Home >Web Front-end >CSS Tutorial >What are the ways to declare css?
There are three ways to declare css, namely: 1. Use the style tag declaration in the head tag; 2. Use the style attribute declaration on the tag; 3. Use the link tag in the head tag to introduce external declarations css file.
The environment of this article: windows10, css3, this article is applicable to all brands of computers.
(Learning video sharing: css video tutorial)
There are three ways to declare css, namely:
1. Use style in the head tag Tag declaration:
Function: This declaration generally declares the public style of the current web page or a separate style for a certain tag
2. Use the style attribute on the tag to declare:
Function: This statement will directly apply the css style to the current tag.
3. Use the link tag in the head tag to introduce externally declared css files
Function: This declaration is equivalent to a call, which solves the problem of reuse of styles between different web pages
Advantages:
Declare once, use anywhere
Note: Using different declaration methods on the same page follows the principle of proximity.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <!--方式一声明--> <style type="text/css"> hr{ width: 100%; height: 50px; color: #000000; background: #808080; } </style> <!--方式三声明--> <link rel="stylesheet" type="text/css" href="my.css"/> </head> <body> 测试声明方式一 <hr > </hr> <!--方式二声明--> <h1 style="background: #151515;color: aqua;">测试声明方式二</h1> <h2>测试声明方式三</h2> </body> </html>
Related recommendations:CSS tutorial
The above is the detailed content of What are the ways to declare css?. For more information, please follow other related articles on the PHP Chinese website!