I have this:
<ul>
<li>
<p>Some long text here</p>
</li>
</ul>
is there a way to get the p text to be restricted to a single line, and have it ellipsize if it's going to be wider than the parent container?
Thanks
element (white-space: nowrap; overflow: scroll;) Text parsed as HTML or XML is tokenized, which means all runs of whitespace are collapsed to a single space character. This means you will have a single line of text unless you specify something in addition to the overflow declaration that could cause your text to wrap.
To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.
You can restrict the text to one line using CSS.
<p style="white-space: nowrap;"></p>
EDIT: According to quirksmode there's apparently a text-overflow: ellipsis
. I've never used this and don't really know anything about it, but you should look into it.
CSS has white-space: nowrap
(gives you single line) and text-overflow: ellipsis
which should do exactly what you want. Unfortunately, text-overflow: ellipsis
isn't supported by all browsers (Firefox being the exception in this case).
Devon Govett wrote a ellipsis plugin for jQuery which solves that.
Original blog: Text-overflow: ellipsis for Firefox via jQuery via Wayback Machine since the original blog was deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With