Truncating text
Sometimes, you encounter a situation where space is limited and you would prefer to see text truncated rather than wrapped. We’ve been trained to spot truncated text on websites for years with the ellipsis symbol “...”.
Single-line truncation
This is straightforward in CSS. Consider this markup (you can view this example in example_15-01
):
<p class="truncate">
OK, listen up, I've figured out the key to eternal happiness. All you
need to do is eat lots of scones.
</p>
However, we actually want to truncate the text at 530 px wide, so it looks like this:
Figure 15.1: Truncation is handy when keeping dimensions constant is of paramount importance
Here is the CSS to make that happen:
.truncate {
width: 530px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Each one of those properties is needed to make the truncation occur.
You can read the specification...