What are the basic selectors in CSS
This article introduces the knowledge of "what are the basic selectors in CSS". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
CSS (cascading style sheet) is a basic language for rendering HTML,XML within the page, and selector is the top priority of learning CSS, selector can select the corresponding elements, thus start to add the style we want, selector can render single element or multiple elements, with the right selector can get twice the result with half the effort, greatly saving editing time.
Five basic selectors 1. Wildcard selector
The wildcard selector can select all the elements on the page and apply the desired style to them, represented by *. But it is not recommended, and IE6 does not support it, which puts a burden on large websites.
Syntax: * {attribute: value}
* {color: red;}
* {font-size: 30px;}
two。 Tag selector (element selector)
A complete HTML page is made up of many different tags. The tag selector can style HTML elements directly, such as H2, td, p, a, or even html itself.
Syntax: label signature {attribute: value}
H2 {color: blue;}
A {text-decoration: none;}
3.ID selector
The ID selector can specify a specific style for HTML elements marked with a specific ID. Selecting an element according to the element ID is unique, which means that an ID can only appear once in a page. The ID selector is defined by "#" and referenced by id in HTML.
Syntax: # id attribute value {attribute: value}
CSS code: # demo {color: green;}
HTML code: I will turn green
4. Class selector
The class selector uses the class name to select the element, provided that an attribute of class, the class= "class name", is added to the element in the HTML code, and then identified with "." in the CSS code, followed by the class name.
Syntax: .class attribute value {attribute: value}
CSS code: .text {color: gray;}
HTML code: I will turn gray
5. Group selector
When several elements have the same style attributes, you can call a declaration together, with elements separated by commas. Note that the comma is to tell the browser that there are several different selectors in the rule, and that without this comma, it will become a descendant selector.
CSS code: .demo, p {color: pink;}
HTML Code:
I'll turn pink.
I'll turn pink, too.
This is the end of the content of "what are the basic selectors in CSS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!