CSS Selector-CSS Selector

Source: Internet
Author: User
Tags object model

1. Type selector
What is a type selector? The identifier that uses the existing tag type in the webpage as the name. Body is a tag type in a webpage. div, p, and span are all.
As follows:
Body {}
Div {}
P {}
Span {}
2. Group selection operator
For XHMTL objects, you can assign the same style to a group at the same time.
The selector is separated by commas (,). The advantage of this method is that you only need to write the same style once to reduce the amount of code and improve the CSS code structure.
Note that "comma" is in halfwidth mode, not Chinese fullwidth mode.
As follows:
H1, h2, h6, p, span
{
Font-size: 12px;
Color: # FF0000;
Font-family: arial;
}
3. Include selector
Specify the style of the sub-objects in an object, so that the selection method plays a role.
Note that only the sub-object label of this object is valid. This style setting is not applied to other sub-objects that exist independently or are not located in this object.
This helps us avoid too many id and class settings and define the required elements directly.
As follows:
H2 span
{
Color: red;
}
As follows:
Body h1 span strong
{
Font-weight: bold;
}
4. id selector
According to the selection character of the DOM Document Object Model principle, for an XHTML file, each tag can be assigned a name in the form of an id = "", but note that, in an XHTML file, IDs are unique and cannot be repeated.
In a webpage with div css layout, you can name different purposes, such as headers and footer at the bottom.
XHTML:
<Div id = "content"> </div>
CSS:
# Content
{
Font-size: 14px;
Line-height: 120%;
}
5. class selector
In fact, id is an extension of XHTML labels, while class is a combination of multiple labels in SHTML. class literal translation means class or category.
Use class = "" to assign names to XHTML labels. Unlike id, the class can be used repeatedly. For multiple elements with the same style, it can be directly defined as a class.
The advantages of using class are self-evident. It demonstrates the reusability of CSS code. Many labels can be defined using a style without writing a style code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.