css绝对元素由溢出:自动隐藏

时间:2016-09-13 06:12:54

标签: css google-chrome scroll css-position

当我悬停链接时,会显示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>

2 个答案:

答案 0 :(得分:0)

我正在使用Chrome,它对我来说很好用。看起来就像你的Firefox示例。

[我把它作为答案,因为我不知道如何评论图像]

Chrome Screenshot

答案 1 :(得分:0)

工作小提琴: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