【问题标题】:css absolute element hid by overflow: auto被溢出隐藏的css绝对元素:auto
【发布时间】:2016-09-13 23:42:26
【问题描述】:

当我悬停链接时,会显示一个absolute pseudo element

我制作了 div overflow-y: scroll,那些 pseudo element 外部视图无法显示,他们仍在使用未计算 scroll 的位置。

Chrome 有这个问题,Firefox 运行良好。

这里有两张图片:

    
.blog .widget-panel {
    height: 400px;
    width: 200px;
    margin: 20px;
    position: fixed;
}

.blog .widget-panel > div {
    overflow-x: hidden;
    overflow-y: auto;
    height: 100%;
}

.blog .widget-panel .tag-box .tag-block {
    display: block;
    line-height: 28px;
    border-bottom: 1px dotted rgba(0,0,0,0.1);
    padding: 7px;
    color: #666;
    background-color: #fff;
}

.blog .widget-panel .tag-box .tag-block:hover,
.blog .widget-panel .tag-box .tag-block.selected {
    background-color: #38B7EA;
    color: #fff;
}

.blog .widget-panel .tag-box.block .tag-block[data-title]:hover:after {
    content: attr(data-title);
    position: absolute;
    z-index: 20;
    white-space: nowrap;
    background: rgba(85,85,85, 0.9);
    padding: 4px 8px;
    color: #fff;
    font-size: 14px;
    line-height: 18px;
    margin-top: 2.8em;
}

.blog .widget-panel .tag-box .tag-block .count{
    float: right;
}
<div class="blog">
    <div class="panel panel-default widget-panel">
        <div class="tag-box block">
           
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>
            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
            All
            <span class="count">14</span>
            </a>
                <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                    test
                    <span class="count">7</span>
                </a>            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
                <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                    test
                    <span class="count">7</span>
                </a>            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
                <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                    test
                    <span class="count">7</span>
                </a>            <a class="tag-block" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                All
                <span class="count">14</span>
            </a>
            <a class="tag-block tag-test" href="#" data-title="A few languages with well-developed systems of articles may distinguish additional subtypes. Within each type, languages may have various forms of each article">
                test
                <span class="count">7</span>
            </a>

        </div>
    </div>
</div>

【问题讨论】:

  • 不要在单个网页中一次又一次地使用相同的 ID,例如all-tags。如果您将 position: absolute 设置为任何 div 或标签,并希望相对于父标签显示它,那么您应该将 position: relative 设置为父标签。
  • 谢谢。当我将 position: relative 添加到父级 (.tag-block) 时,它会显示一个水平滚动条,也不会像我想要的那样显示。
  • 当将position: relative; 添加到.tag-block 时,标题会被overflow 隐藏。喜欢这里:https://jsfiddle.net/dp70zv5o/2/

标签: css google-chrome scroll css-position


【解决方案1】:

工作小提琴:https://jsfiddle.net/TheBigDMo1/k2ahruyb/5/

使用 CSS 工具提示:http://www.w3schools.com/css/css_tooltip.asp
- 如果您使用此选项,则需要完全删除 data-title 属性

这是你的 CSS:

    .blog .widget-panel {
    height: 200px;
    width: 200px;
    margin: 20px;
    position: fixed;
}

.blog .widget-panel .tag-box {
    overflow-x: hidden;
    overflow-y: auto;
    height: 100%;
}

.blog .widget-panel .tag-box.remove-over-flow {
    overflow-x: visible;
    overflow-y: visible;
}

.blog .widget-panel .tag-box .tag-block {
    display: block;
    line-height: 28px;
    border-bottom: 1px dotted rgba(0,0,0,0.1);
    padding: 7px;
    color: #777;
    background-color: #fff;

    position: relative;
}

.blog .widget-panel .tag-box .tag-block .tooltip-text {
    visibility: hidden;
    background-color: black;
    color: #fff;
    text-align: center;
    padding: 5px 0;
    margin-left: 10px;
    padding-left: 5px;
    border-radius: 6px;
    z-index: 1;

    white-space: nowrap;

    /* Position the tooltip text - see examples below! */
    position: fixed;
}

.blog .widget-panel .tag-box .tag-block .tooltip-text::after {
    content: " ";
    top: 50%;
    right: 100%;
    margin-top: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent black transparent transparent;

    /* Position the tooltip text - see examples below! */
    position: absolute;
}


.blog .widget-panel .tag-box .tag-block:hover .tooltip-text,
.blog .widget-panel .tag-box .tag-block.selected .tooltip-text {  
    visibility: visible;
    /*background-color: #38B7EA;*/
    /*color: #fff;*/
}

这是你的 jQuery:

$(".tag-block").on('click', function () {
    $(".tag-box").toggleClass("remove-over-flow");
});

$('.tooltip-text').click(function() {
    $(this).hide();
});

已编辑:添加了工作小提琴,添加了 CSS

【讨论】:

  • 谢谢,这是浏览器的默认工具提示。我无法设计它。使用data-title 与您的CSS tooltips 相同:) 我无法在链接中添加position:relative
  • 您的工具提示本身应该是一个span,通过 tag-block:hover 而不是锚标记的 HTML 属性使其可见(使用相对定位)。您的工具提示跨度应如下所示:&lt;span class="tooltiptext"&gt;Tooltip text&lt;/span&gt;
  • 您的 CSS 文件中还应该有一个 tag-block:hover .tooltiptext { visibility: visible; }。这样您就可以在 CSS 中使用 .tagblock .tooltiptext { visibility: hidden; } 设置工具提示的样式。
  • 嗨,我试过了。请看这里https://jsfiddle.net/dp70zv5o/2/。当我这样做时,tooltip 也会被.tag-blockoverflow 隐藏(比如在使用data-title 时将position: relative; 添加到.tag-block)。
  • 在工具提示文本上设置position: fixed
【解决方案2】:

我正在使用 Chrome,它对我来说运行良好。看起来就像您的 Firefox 示例。

[我把这个作为答案,因为我不知道如何评论图片]

【讨论】:

  • 嗨,请滚动滚动条并查看最后几个链接。
猜你喜欢
  • 1970-01-01
  • 2014-08-17
  • 1970-01-01
  • 2012-12-21
  • 1970-01-01
  • 2014-09-02
  • 1970-01-01
  • 2023-03-27
  • 2021-02-07
相关资源
最近更新 更多