Home >Web Front-end >Front-end Q&A >css beyond display
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:
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:
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.
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:
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:
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!