Where is the css style written?

下次还敢
Release: 2024-04-25 12:36:17
Original
1007 people have browsed it

CSS styles can be written in the following three locations: Inline style: written directly into the style attribute of the HTML element. Internal style sheets: written in the <style> element within the <head> tag. External style sheet: written in a separate .css file and linked to the HTML page through the <link> tag. Generally, the most appropriate location for writing the style is chosen on a case-by-case basis.

Where is the css style written?

CSS style writing location

CSS (Cascading Style Sheets) style is used to control the visual presentation of web pages , it can be written in three positions:

1. Inline style

  • Write the style directly into the HTML element, use styleAttributes.
  • For example:<p style="color: red;">This text is red.</p>

2 . Internal style sheet

  • Create a <style> element inside the <head> tag and write the style in it.
  • For example:

    <code class="html"><head>
    <style>
    p {
    color: blue;
    }
    </style>
    </head></code>
    Copy after login

3. External style sheet

  • Write the style in a separate .css file, the file is linked to the HTML page through the <link> tag.
  • For example:

    <code class="html"><head>
    <link rel="stylesheet" href="style.css">
    </head></code>
    Copy after login

Recommended position:

Usually, choose the most appropriate style to write according to the specific situation Insertion position:

  • Inline style: is only suitable for a very small amount of element modifications, because it will increase the amount of code.
  • Internal style sheet: For small pages or documents, it is very convenient to write the style in the <head> tag.
  • External style sheet: For large projects that span multiple pages, using external style sheets can achieve centralized management and maintenance of styles.

The above is the detailed content of Where is the css style written?. 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!