溢出文本的背景颜色

Ned*_*Ned 9 html css overflow css3 background-color

我将背景颜色应用于我的国家/地区列表中的链接.它总体上运作良好:

在此输入图像描述

但是,对于名字较长的国家来说,效果不佳.

在此输入图像描述

我试图让黄色溢出一切,并清楚地显示国家的全名.

HTML:

<div class="flagList">
<div class="flagColumn"> ... </div>
<div class="flagColumn"> ... </div>
<div class="flagColumn"> ... </div>
...
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.flagColumn {
    width: 33%;
    float: left;
    border:0px solid;
    height:1.6em;
    overflow:hidden;
    white-space:nowrap; 
    text-overflow:ellipsis;
    z-index: 1; position:relative;
}

.flagColumn:hover {
   overflow:visible;
   z-index: 2; position:relative;
   display: inline;
   background-color:yellow;
}
Run Code Online (Sandbox Code Playgroud)

Hid*_*bes 6

您可以通过将的内容包装.flagColumn在一个额外的元素中,将其设置为display: inline-block;并在其上设置背景来做到这一点:

.flagColumn {
    float: left;
    height: 1.6em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 33%;
    z-index: 1;
}
.flagColumn:hover {
    overflow: visible;
    position: relative;
    z-index: 2;
}
.flagColumn:hover span {
    background-color: yellow;
    display: inline-block;
    height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="flagList">
    <div class="flagColumn"><span>This is test text!</span></div>
    <div class="flagColumn"><span>This is a lot longer test text! This is a lot longer test text!</span></div>
    <div class="flagColumn"><span>This is a lot longer test text! This is a lot longer test text!</span></div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS小提琴: http : //jsfiddle.net/hL9qfuvb/1/