Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the ways to nest and use CSS in HTML pages

Shulou Source: shulou.com Published: 2022-05-31 14:02:22 09月20日 Update

Most people do not understand the knowledge points of this article, "what are the methods of using CSS nested in the HTML page?", so the editor summarizes the following, detailed contents, clear steps, and a certain reference value. I hope you can get something after reading this article. Let's take a look at this article, "what are the methods of using CSS nested in the HTML page?"

What is CSS?

CSS (Cascading Style Sheet): cascading stylesheet language.

The purpose of CSS is to:

Decorate the HTML page and style some elements in the HTML page to make the HTML page look better.

Two ways to nest and use CSS in HTML pages

The first way: use the style attribute inside the tag to set the CSS style of the element, which is called inline definition. Syntax format:

The second way: link to an external stylesheet file, which is the most commonly used. (write the style into a separate xxx.css file, introduce the css file directly into the web page you need, and the style is introduced.) Syntax format:

This method is easy to maintain and the maintenance cost is low. Xxx.css file 1.html introduced 2.html, 3.html introduced 4.html, introduced three ways of code presentation

Inline definition mode

The first way to introduce CSS style into HTML: inline definition

Style block mode

The second way to introduce styles in HTML: style block mode / * this is the comment of CSS * / / * id selector # id {style name: style valu Style name: style value; style name: style value. } * / # usernameErrorMsg {font-size: 12px; color: red } / * tag selector signature {style name: style value; style name: style value Style name: style value;} * / div {background-color: black; border: 1px solid red Width: 100px; height: 100px;} / * class selector. Class name {style name: style valu } * / .myclass {border: 2px double blue; width: 400px; height: 30px}

Tags: Style method page file content method selection element commonly used article tag format user user name knowledge article grammar mouse specialty code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno NVidia MariaDB Shulou Tech Info