In HTML5, the hr tag can be styled with css. The css style can define how to display HTML elements. You only need to use the style attribute to set the hr element with css style. The syntax is "
" or "hr{css style code;}".
The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.
Simply put, hr is a horizontal dividing line (horizontal rule) on the html page, which can visually separate the document into various parts. . Needs to be created in the HTML page via the
Then let’s take a look at the default hr tag style:
is just a black line, which is not beautiful at all, let alone using
css to set hr style
How do we use css to set hr style? In fact, it is very simple. You can set the style of hr through the css border attribute and css background-image attribute:
1.css sets the thickness (bold) and color of hr
<hr style="border: 5px solid red;"/><!--修改的样式--> <br /> <hr /><!--默认的样式-->
2.css sets the dashed line style of hr (color is blue)
<hr style="max-width:90%"/>
3.css sets the double line style of hr
<hr style="max-width:90%"/>
4. css to set the 3D three-dimensional style of hr
<hr style="max-width:90%"/>
5.css to set the gradient style of hr
HTML code:
<hr class="style-one"/> <br/> <hr class="style-two"/>
css code:
hr.style-one {/*透明渐变水平线*/ width:80%; margin:0 auto; border: 0; height: 4px; background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0)); } hr.style-two{/*渐变*/ width:80%; margin:0 auto; border: 0; height: 4px; background: #333; background-image: linear-gradient(to right, red, #333, rgb(9, 206, 91)); }
The above are just a few simple examples. The style of the hr tag can also be realized through CSS. . Everyone can give it a try!
Recommended tutorial: "html video tutorial"
The above is the detailed content of Can css be used for the hr tag in html5?. For more information, please follow other related articles on the PHP Chinese website!