Overflow for background color of text

微笑、不失礼 提交于 2020-01-14 07:10:27

问题


I applied background color to the links in my country list. It works well in general:

However, for the countries which have longer name, it doesn't work very well.

I'm trying to make the yellow color overflow everything and show country's full name clearly.

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

回答1:


You can do this by wrapping the content of .flagColumn in an extra element, setting it to display: inline-block; and setting the background on that instead:

.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/



来源:https://stackoverflow.com/questions/26716979/overflow-for-background-color-of-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!