How to handle spaces in CSS (example)
The content of this article is about how to process spaces in CSS (examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<p>1. Space rules <p>Spaces in HTML code are usually ignored by browsers. <p>
<p>◡◡hello◡◡world◡◡</p>
◡
is used here to represent spaces. <p>The browser output is as follows. hello world
<pre class="brush:php;toolbar:false"></code> tag. </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'><pre class="brush:php;toolbar:false">◡◡hello◡◡world◡◡</pre></pre><div class="contentsignin">Copy after login</div></div><p>An alternative is to use HTML entities <code>
to represent spaces instead. <p> hello world </p>
\t
) and newline characters (\r
and \n
). <p>The browser will automatically convert these symbols into ordinary space keys. <p>hello world</p>
hello world
<pre class="brush:php;toolbar:false"></code> tag). </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'><p>hello<br>world</p></pre><div class="contentsignin">Copy after login</div></div><p>The above code uses the <code><br>
tag to explicitly indicate line breaks. <p>3. The white-space attribute of CSS<p>The space processing in HTML language is basically direct filtering. Such processing is too crude and completely ignores the fact that the whitespace inside the original text may be meaningful. <p>CSS provides a white-space
attribute, which can provide a more precise way to handle spaces. This attribute has six values in total. In addition to a common inherit
(inheriting the parent element), the remaining five values are introduced below. 3.1 white-space: normal
<p>The default value of the white-space
attribute is normal
, indicating that the browser handles spaces in a normal manner. <p>◡◡hellohellohello◡hello world </p>
<p>
specifies a relatively small width. For easier identification, the background color is set to red. p { width: 100px; background: red; }

3.2 white-space: nowrap
<p>white-space
When the attribute is nowrap
, line breaks will not occur due to exceeding the width of the container. p { white-space: nowrap; }

3.3 white-space: pre
<p>white-space
When the attribute is pre
, follow </code> Label processing. </p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'>p {
white-space: pre;
}
Copy after login

3.4 white-space: pre-wrap
<p>white-space
When the attribute is pre-wrap
, basically follow the < The pre>
tag is processed in the same way. The only difference is that when the width of the container is exceeded, a line break will occur. p { white-space: pre-wrap; }

3.5 white-space: pre-line
<p>white-space
When the attribute is pre-line
, it means to retain the newline character. Except for the newline character, which will be output as it is, everything else is consistent with the white-space:normal
rules. p { white-space: pre-line; }

normal
. This is useful for poetry type texts.
<p> Recommended related articles:
<p>div tag: implementation of horizontal centering and vertical centering (with code)
<p>Code for string conversion using the text-transform attribute in CSSThe above is the detailed content of How to handle spaces in CSS (example). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...
