Home  >  Article  >  Web Front-end  >  What are the ways to declare css?

What are the ways to declare css?

王林
王林Original
2020-11-27 11:09:222938browse

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.

What are the ways to declare css?

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!

Statement:
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
Previous article:What is float in cssNext article:What is float in css