Home > Web Front-end > Front-end Q&A > css beyond display

css beyond display

WBOY
Release: 2023-05-27 09:29:36
Original
8756 people have browsed it

CSS over-display refers to how to handle overflowing content when the content of an element exceeds its specified width or height. In this case, we can use some properties and values ​​provided by CSS to control the display and hiding of the beyond content and make it look more beautiful and readable in the page.

CSS overflow property

When the content of an element exceeds its specified width or height, we can use the overflow property in CSS to control how the overflowed content is displayed. The overflow attribute has the following values:

  • visible: The excess content will be displayed outside the element and may obscure other elements.
  • hidden: The excess content will be cropped and will not be displayed on the page.
  • scroll: If the content overflows, a scroll bar will be displayed so that the user can scroll.
  • auto: If the content overflows, a scroll bar will be displayed, otherwise the content will be displayed normally.

For example, if we want to display some content in a fixed-height div, when the content exceeds the height of the div, we can set the overflow attribute to scroll or hidden.


Some very long content


In this example, when the content of the p element exceeds the 200px height, a vertical scroll bar will be displayed so that the user can scroll to view the content.

CSS text-overflow property

In addition to using the overflow property to control the display mode of the exceeded content, we can also use the text-overflow property in CSS to control the display mode of the text content when it exceeds the limit. . The text-overflow attribute only takes effect when the white-space attribute is set to nowrap.

text-overflow has the following three values:

  • clip: When the text exceeds, it will be clipped and will not be displayed on the page.
  • ellipsis: Ellipses will be displayed when the text is exceeded.
  • string: The specified string will be displayed beyond the text.

For example, if we want to display a long title in one line, when the title text exceeds the width of the element, we can use the text-overflow attribute and the white-space attribute.

This is a long, long, long title

In this example, when the title text exceeds the width of the element, an ellipsis will be displayed to let the user know that the text has been truncated.

CSS word-wrap attribute

In addition to using the overflow and text-overflow attributes to control the overflow and truncation of element content, we can also use the word-wrap attribute in CSS to control text words of line breaks.

By default, when a word exceeds the width of the element, it is truncated and displayed on the next line. But if we want to ensure that words are not truncated and wrapped at word boundaries, we can use the word-wrap attribute.

The word-wrap attribute has the following two values:

  • normal: Words are broken at boundaries and will not be truncated.
  • break-word: Words will be broken wherever available and will be truncated when they are too long.

For example, if we want to display some long text in a limited width, but also ensure that all words wrap at the boundaries and all excess content is clipped, we can use the following CSS:

This is a long, long, long text. It contains a lot of words, but they wrap at the boundaries and are not truncated.

Conclusion

When designing web pages, we usually need to adapt the content to different screen sizes and resolutions as much as possible. In order to ensure that the overflow content can be displayed correctly on the page, we can use some properties and values ​​​​provided in CSS, such as overflow, text-overflow and word-wrap, which can help with page layout and make the page look Much clearer and neater.

The above is the detailed content of css beyond display. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template