I have a case in a div that will contain some HTML tags, it will have paragraphs and lists. For examples:
<div class="article-block">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<ul>
<li>Some text #1</li>
<li>Some text #2</li>
<li>Some text #3</li>
</ul>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
I want the content in the div will apply text-overflow: ellipsis
if it overflows the div’s size. So what I have tried:
.article-block {
width: 92mm;
height: 85mm;
margin-top: 2mm;
overflow: hidden;
text-overflow: ellipsis;
}
The result will look like this:
I expected that it would look like this, there will be the "…" at the end:
Can I have some hints on how to achieve this? Thanks!
FYI: Only CSS or HTML, no JS.
2
Answers
Firstly,this property should applied to the text element like
p
not the parentdiv
,Secondly this property will not work unless you set overflow and white-space to the text element.
The text-overflow property needs to be attached to the text elements like P, h1-h6 themselves and not a div that’s a container element. also needs to have the white-space:nowrap property set alongside the overflow and text-overflow. Has to be block elements too, so you add display: block in the case of span elements.