Four ways to combine CSS and HTML

Four ways to combine CSS and HTML

(1) Each HTML tag has an attribute style, which combines CSS and HTML together

<div style="background-color:red;color:blue;">I am a little bird</div>

(2) Use an HTML tag, <style> tag: write it in the head

    <style type="text/css">
      css code;
    </style>
<style type="text/css">
div {
background-color:red;
color:gray;
}
</style>

(3) Use statements in the style tag (does not work in some browsers)

@import url(css file path);

- Step 1: Create a css file

   <style type="text/css">
    @import url(div.css);
  </style>

(4) Use the header tag link to introduce external CSS files

- Step 1: Create a css file

 - <link rel="stylesheet" type="text/css" href="div.css"/>

*** Disadvantages of the third combination method: It does not work in some browsers, and the fourth method is generally used

*** Priority (general)

From top to bottom, from outside to inside, priority from low to high

*** The later loaded ones have higher priority

*** Format selector name {attribute name: attribute value; attribute name: attribute value; ......}

Full code:

<html>
    <head>
        <title>World</title>
        <style type="text/css">
            div {
                background-color:gray;
                color:white;
            }
        </style>
    </head>
    <body>
        <div style="background-color:red;color:blue;">I am a little bird</div>
        <div>May we have the years to look back on, and grow old together with deep affection! </div>
    </body>
</html>

<html>
    <head>
        <title>World</title>
        <style type="text/css">
            @import url(div.css);
        </style>
    </head>
    <body>
        <div>May we have the years to look back on, and grow old together with deep affection! </div>
    </body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>world</title>
<link rel="stylesheet" type="text/css" href="div.css"/>
</head>
<body>
    <div>May we have the years to look back on, and grow old together with deep affection! </div>
</body>
</html>

Summarize

The above are the four ways of combining CSS and HTML that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Analysis of the difference between HTML relative path and absolute path

>>:  Specific usage instructions for mysql-joins

Recommend

Implementation of MYSQL (telephone number, ID card) data desensitization

1. Data desensitization explanation In daily deve...

Learn about TypeScript data types in one article

Table of contents Basic Types any type Arrays Tup...

Vue implements login verification code

This article example shares the specific code of ...

How to make your own native JavaScript router

Table of contents Preface Introduction JavaScript...

How to find and delete duplicate rows in MySQL

Table of contents 1. How to find duplicate rows 2...

Vue implementation counter case

This article example shares the specific code of ...

Vue directives v-html and v-text

Table of contents 1. v-text text rendering instru...

How to pull the docker image to view the version

To view the version and tag of the image, you nee...

Vue's guide to pitfalls using throttling functions

Preface In a common business scenario, we need to...

In-depth analysis of Nginx virtual host

Table of contents 1. Virtual Host 1.1 Virtual Hos...

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...