【发布时间】:2013-09-09 15:19:35
【问题描述】:
我在 html 中有一个 <a> 标记,我希望它是省略号。但是当我在<a> 标签内添加<div> 时,'text-overflow' 不起作用。
HTML:
<div class=boxed>
<h1>text-overflow Attribute Sample</h1>
<a href="#" class="caption">
<!----><div style="width:100px;height:20px;border: 1px solid red"></div>
Each box (div element) below contains the following text:
</a>
</div>
CSS:
div.boxed {
width: 200px;
height: 200px;
border: 1px solid blue;
font: 14px Times New Roman, serif;
overflow:hidden;
'position:relative;
}
a.caption {
overflow:hidden;
white-space: nowrap;
text-overflow: ellipsis;
display:block;
text-decoration:none;
float:left;
text-align:left;
}
删除<div> 后,“文本溢出”再次起作用。
【问题讨论】:
-
在你的 CSS 中,
'就在position:之前。也在你的 jsFiddle 中。也许这是一个错误? -
A 是一个内联元素。 Div 是一个块元素。您不应该将块元素放在内联元素中。