CSS adds ellipsis attributes beyond one line: Text-overflow and White-space

Source: Internet
Author: User

Add the following HTML code by using the Text-overflow and White-space properties to make the text appear in one line, beyond the ellipsis:

<p> Front-end development blog focused on front-end development and technology sharing, if the description is more than 100 pixels, it will be hidden, add ellipsis </p>

CSS: Need to add width (width:100px), out of hiding (overflow:hidden;), force to display on the same line (white-space:nowrap;), ellipsis (text-overflow:ellipsis;)

P {width: 100px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}

Test Explorer: IE6/7/8/9, opera12.02, firefox15.0.1, chrome21.0.1180.89 m

1, text-overflow:ellipsis;

The main style here is text-overflow:ellipsis;

However, Text-ellipsis is a special style, the explanation is this: the Text-overflow property is only annotations, and if the text overflows, the ellipsis is displayed. No other style attribute definitions are available.

The effect of an ellipsis on overflow must also be defined: Force the text to appear on one line (white-space:nowrap) and overflow content as hidden (Overflow:hidden), only in order to achieve the effect of overflow text display ellipsis.

This needs to limit the width, the text is displayed on one line (white-space:nowrap;), and the hidden attribute overflow is used.

Online to support the lower version of opera one way is to-o-text-overflow:ellipsis;

2.white-space Property

definition : The White-space property sets how to handle whitespace within an element.

Example : The text in a specified paragraph does not wrap:

P { white-space: nowrap;}

Possible values

value Description
Normal Default. The blank will be ignored by the browser.
Pre The blank will be reserved by the browser. It behaves like a <pre> tag in HTML.
NoWrap The text does not wrap, and the text continues on the same line until the <br> tag is encountered.
Pre-wrap Preserves the sequence of whitespace characters, but wraps them normally.
Pre-line Merges a sequence of whitespace characters, but preserves newline characters.
Inherit Specifies that the value of the White-space property should be inherited from the parent element.

Object.style.whitespace=normal|nowrap|pre

3.word-wrap

definition : The Word-wrap property allows long words or URL addresses to wrap to the next line. originally from: Http://caibaojian.com/css-white-space.html

example : Allow long words to wrap to the next line:

{word-wrap:break-word;}

Possible values:

value Description
Normal Line breaks only on allowed hyphenation points (the browser keeps the default processing).
Break-word Wraps a line inside a long word or URL address.

1. (IE) consecutive English characters and Arabic numerals, using Word-wrap:break-word; or word-break:break-all; implement force break

2. (Firefox browser) consecutive lines of English characters and Arabic numerals, all versions of Firefox do not solve this problem, we only let the characters beyond the boundary hide or add a scrollbar to the container
. a{word-break:break-all; width:200px; overflow:auto;}

. (Firefox browser) use table-layout:fixed, force table width, inner layer td,th adopt word-break:break-all; or Word-wrap:break-word; newline, use overflow : Hidden; Hide beyond content, here Overflow:auto; not working

Go: CSS adds ellipsis attributes beyond one line: Text-overflow and White-space front-end Development blog (http://caibaojian.com/css-white-space.html)

CSS adds ellipsis attributes beyond one line: Text-overflow and White-space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.