Several ways to combine CSS and HTML

1. Internal style

Internal style is also called inline style. Use style tag to write css code in head tag.
Insert picture description here

to sum up:

  1. In the grammar, the style tag is usually located after the title tag in the head tag, and it can also be placed anywhere in the HTML document.
  2. type="text/CSS" can be omitted in html5, and it is more in line with the specification, so this place can be written or omitted.

2. In-line style

Set the style directly on the label by using style="attribute:value".
Insert picture description here
3. External style

In this way, you need to create a separate css file, write all the css code into the file, and then use the link tag to import it in the html file.

Insert picture description here

  • href: Defines the URL of the linked external style sheet file, which can be a relative path or an absolute path.
  • rel: Define the relationship between the current document and the linked document, where it needs to be specified as "stylesheet", which means that the linked document is a style sheet file.

Comparison between the three methods
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41504815/article/details/114093733