How to reference css in html

藏色散人
Release: 2023-01-05 16:12:16
Original
16747 people have browsed it

How to reference css in html: 1. Reference css through inline style, code such as ""; 2. Reference css through internal style sheet, code such as " "; 3. Reference css through an external style sheet.

How to reference css in html

The operating environment of this article: windows7 system, HTML5&&CSS3 version, DELL G3 computer.

Three ways to reference css in html

CSS was first used in HTML 4 and was introduced to better render HTML elements.

CSS is introduced into HTML in the following three ways: 1-inline, 2-internal style sheet, 3-external style sheet.

  • Inline style:

    <body style="background-color: gray">
Copy after login

Within the tag style=" "

  • Internal style Table:

    <style type="text/css"> 
    p {color:red;} <!--内部样式表-->
    </style>
Copy after login

Use the style tag and place the attributes to be controlled by CSS inside the tag

  • External style sheet:

<link rel="stylesheet" type="text/css" href="mystyle.css">
Copy after login

In the head tag, and use the link tag to introduce the css file you want to load

I accidentally discovered that when I use these three expression methods to control the background-color attribute at the same time When , only the properties within the tag of the inline style take effect.

Inline tags set the background color to gray, internal style sheets are set to red, and external style sheets are not set. The background color on html is gray.​​

The background color of the inline tag is set to gray, the external style sheet is set to yellow, and the internal style sheet is not set. The background color on html is gray.​ ​

Internal style sheets are set to red, and external style sheets are set to yellow. The background color on html is yellow.​​​​

Conclusion: Inline>External Style Sheet>Internal Style Sheet

It can be seen that the attributes closest to the label are reflected first.

For more detailed HTML/css knowledge, please visit the HTML video tutorial column!

The above is the detailed content of How to reference css in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!