html - 文本背景颜色溢出

标签 html css overflow background-color

我为我的国家/地区列表中的链接应用了背景色。一般情况下效果很好:

enter image description here

但是,对于名字较长的国家来说,效果不是很好。

enter image description here

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

HTML:

<div class="flagList">
<div class="flagColumn"> ... </div>
<div class="flagColumn"> ... </div>
<div class="flagColumn"> ... </div>
...
</div>

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;
}

最佳答案

您可以通过将 .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%;
}
<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>

JS fiddle : http://jsfiddle.net/hL9qfuvb/1/

关于html - 文本背景颜色溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26716979/

相关文章:

javascript - 获取按钮上的 div 的 id 单击 div 包含该按钮的位置

javascript - CSS 中的 url() 函数如何工作?

css - 彩色背景上的 Div 闪烁边框

javascript - 如何在溢出 : hidden? 的 div 中正确放置文本

css - 与父 div 重叠的 HTML/CSS div

javascript - 将元素动态添加到 SVG 后,该项目不可见

javascript - 输入数据后我的表格无法正确显示

css - CSS 和 jquery UI 可拖动有问题

html - 电子邮件 html - 如何更改我的 html/css 以使其在 Outlook 上看起来不错

css - 谷歌浏览器 : how to display full text when the mouse hovers over a table cell