[英]Extend span width base on content with position absolute
I'm using a tooltip to show the users some info but if the text is longer the span would not expand to full width of the text as usual. 我正在使用工具提示向用户显示一些信息,但是如果文本较长,则跨度将不会像往常一样扩展为文本的全宽。 i have a fiddle link http://jsfiddle.net/VJ7su/ if you hover the first check box you can see the text is forced down.
我有一个小提琴链接http://jsfiddle.net/VJ7su/如果您将鼠标悬停在第一个复选框上,您会看到文本被压低。
<ul class="booth26_34">
<li class="tooltips"><input type="radio" value="26" name="booth_nr" disabled=""><span>AIT Austrian Institute of Technology</span></li>
<pre>
li.tooltips {
position: relative;
display: inline;
}
li.tooltips span {
position: absolute;
width:auto;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
font-weight:bold;
}
li.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 50%;
margin-left: -2px;
width: 0; height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
li:hover.tooltips span {
visibility: visible;
opacity: 0.8;
bottom: 30px;
left: 50%;
margin-left: -76px;
z-index: 999;
}
</pre>
You must to remove width and height from your tooltip + if you want the text to be displayed in one line just set white-space:nowrap 您必须从工具提示中删除宽度和高度+如果您希望文本显示在一行中,只需设置空白:nowrap
CSS 的CSS
li.tooltips span {
position: absolute;
color: #FFFFFF;
background: #000000;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
font-weight:bold;
white-space:nowrap;
padding: 5px 10px;
}
Add whitespace: nowrap;
添加
whitespace: nowrap;
to the span
CSS style. span
CSS样式。
li.tooltips:first-child span {
left: -133px;
}
li.tooltips:nth-child(2) span {
left: -135px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.