Where to put css

藏色散人
Release: 2023-01-04 09:34:59
Original
7919 people have browsed it

There are three places where css can be placed, namely: 1. Put it in the style attribute of the element tag, which is only valid for the current element; 2. Put it in the style tag of the head tag at the head of the current page. It is only valid for all elements of the current page; 3. Put it in an independent CSS file and is valid for all pages that introduce the file.

Where to put css

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

Where can I put the css code?

1, written in the style attribute of the element tag, is only valid for the current element;

2, written in the style tag of the head tag at the head of the current page, is only valid for Valid for all elements of the current page;

3, written in a separate CSS file, referenced using the tag in the head tag; valid for all pages that introduce the file.

Let’s use examples to explain one by one:

Written in the style attribute of the element tag:

<p style="color:red;">abc</p>
Copy after login

Written in the tag at the head of the current page:

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        p{
            text-align: center;
        }
    </style>
</head>
Copy after login

Written in a separate CSS file, referenced using the tag:

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="Untitled-1.css">
</head>
Copy after login

The following is the content of the CSS separate file:

p{
    color: red;
}
Copy after login

[Recommended learning: css video tutorial

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

Related labels:
css
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