HTML+CSS Easy G...LOGIN

HTML+CSS Easy Getting Started: What is a Selector?

The definition of css is composed of two parts

body{

Style

}

The part before {} is " Selector", "selector" specifies the object of the "style" in {}, that is, which elements in the web page the "style" acts on

body is an html element, so we also call it an element Selector

div table span etc.

Let’s look at the example below

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>元素选择器</title>
	<style type="text/css">
		p{
			color:red;
		}

		div{
			color:red;
		}


		span{
			color:red;
		}
	</style>
</head>
<body>
			<p>中国</p>

			<div>美国</div>

			<span>日本</span>
</body>
</html>

Note: If there are many tags in the text and need to have the same style, then we will use css A lot of repeated code must be written in the style, so that the page will be untidy. Let's use a method to write it. The code is as follows:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>元素选择器</title>
	<style type="text/css">
		p,div,span{
			color:red;
		}
	</style>
</head>
<body>
			<p>中国</p>

			<div>美国</div>

			<span>日本</span>
</body>
</html>

The effect of writing this way is the same as the above, but the code will be very neat.

Next Section
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>元素选择器</title> <style type="text/css"> p,div,span{ color:red; } </style> </head> <body> <p>中国</p> <div>美国</div> <span>日本</span> </body> </html>
submitReset Code
ChapterCourseware