Home >Web Front-end >Front-end Q&A >css that disables line breaks
CSS that prohibits line breaks
In web design, we often encounter situations where line breaks need to be prohibited. For example, you need to insert a long link or image URL into a piece of text. If these links span two or even more lines, it will destroy the aesthetics of the page and affect the user's reading experience. At this point, we need to use CSS to disable line breaks.
There are two properties in CSS that can be used to prohibit line breaks, namely "white-space" and "word-break".
The white-space attribute is used to control spaces and line breaks in style elements. It has the following values:
We can use the nowrap attribute to prohibit line breaks within an element. For example, the text in the following example will be forced to be displayed on one line:
<p style="white-space:nowrap;">This is a sample text that will not be wrapped.</p>
The word-break attribute is used to control word wrapping processing method, it has the following values:
We can use the break-all attribute to prohibit a Line wrapping of words within the element. For example, the long URL link in the following example will be forced to wrap:
<p style="word-break:break-all;">https://www.example.com/es?hl=zhcn&tab=rw</p>
It should be noted that if both the white-space and word-break attributes are used in an element, their priority is different. Specifically, the word-break attribute takes precedence over the white-space attribute. That is, if you want to force line breaks and preserve all spaces, you should use word-break: break-all; white-space: pre-wrap;, but not white-space: pre-wrap; word-break: break -all;.
In addition, in actual use, we can add these CSS styles to the CSS file and call them to achieve the purpose of beautifying the web page.
The above is an introduction to CSS techniques for disabling line breaks. I hope it will be helpful to you.
The above is the detailed content of css that disables line breaks. For more information, please follow other related articles on the PHP Chinese website!