How To Break Line Without Using
Tag In CSS - W3docs
Có thể bạn quan tâm
There are a few ways to break a line without using a <br> tag. For that, we can use block-level elements.
Block-level elements start on a new line by default (if a CSS rule does not override the default behavior). Here, you can find how to make inline elements start on a new line.
In this snippet, we’ll use the following properties:
- white-space: pre for making elements act like <pre>,
- display: block for representing an element as a block element.
Let’s see how to break a line using the white-space property. This property specifies how the white space within an element must be handled. A white space can be a space sequence or a line break.
Create HTML
- Use <h1> and <div> elements.
Add CSS
- Use the text-align property set to “center” for the <body> element.
- Add color to <h1>.
- Use the white-space property set to “pre” for the <div> element.
Let’s see the result of our code.
Example of breaking a line using the white-space property:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> body { text-align: center; } h1 { color: #000000; } div { white-space: pre; } </style> </head> <body> <h1>W3Docs</h1> <div> Example Example </div> </body> </html> Try it Yourself »Result
W3Docs Example ExampleNext, we’ll show how to break a line with the display property. We need to set display: block to represent an element as a block element. In the following example, we set display: block to the <span> element which is inside a <p> element.
Example of breaking a line using the display property:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> body { text-align: center; } h1 { color: #000000; } p span { display: block; } </style> </head> <body> <h1> W3Docs </h1> <p> <span>Example_1</span> <span>Example_2</span> </p> </body> </html> Try it Yourself »Also, you can use the carriage return character (\A) as content in pseudo-element.
It is possible to add a new line using ::before and ::after pseudo-elements.
Example of breaking a line using the ::after pseudo-element:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .line:after { content: '\A'; white-space: pre; } </style> </head> <body> <h3> <span class="line">This is the first line</span> <span class="secondary-label">second line</span> </h3> </body> </html> Try it Yourself »Từ khóa » Html Br Substitute
-
What Is The Alternative To
If I Want To Control The Height Between ... -
What Is The Best Alternative To Repetitive Typing Of
Tags In HTML ... -
Alternative To BR TAG | Learn HTML CSS - YouTube
-
How To Break Line Without Using
Tag In HTML / CSS -
What To Use Instead Of
- HTML Forum At WebmasterWorld -
How To Replace Line Break Tags (
) With Spaces In CSS | TimOnWeb -
Substitution Tags | Twilio - SendGrid Documentation
-
Alternative To
Inside- - HTML & CSS - SitePoint Forums
-
Mod_substitute - Apache HTTP Server Version 2.5
-
Nucleophilic Substitution - Halogenoalkanes And Hydroxide Ions
-
Nucleophilic Substitution - Halogenoalkanes And Cyanide Ions
-
Effects Of Halogen Substitution On The Optoelectronic Properties Of ...
-
Using The Br Tag - Line Break Tag