"HTML" CSS Selector

Source: Internet
Author: User

CSS selectors are:

    • Element Selector
    • Selector Group *
    • Class Selector
    • ID Selector
    • Property Selector *
    • Descendant Selector *
    • Child element Selector *
    • Adjacent Sibling selector *

Selector grouping:

h1,h2{/* define style for H1,h2 */   ...}

wildcard character "*":

*{   ...} /* with "*" define styles for all elements */

Class Selector + Tag Selector:

class="cww"class="cww" ...>A.  cww{    ...      }

Multi-Class selectors:

class="p1"class="p2"class= " p1 p2 ">...</p>.p1{...   }.   p2{...   }. p1.p2{...   }

where ". P1.p2" contains its own style and the previous ". P1" and ". P2" styles.

ID selector:

<p id="cww">...</p>#cww {   ...} /* use "#" to locate */
    • Use JS to get ID
    • IDS can only be used once, and classes can be used multiple times
    • ID selectors can not be used in combination

Property selector:

 <a href= http://www.cww.com  Span style= "color: #800000;" > " >...</a><a href="  http:/ /www.mochayo13.com   >...</a> /*   */ [href]{.}  
    • The property selector can be defined by a specific property value.
    • Can be selected based on partial attributes,
      <p tltle="cw"></p><p tltle="cww"></p ><p tltle="cww13"></p>[title~=cww " ]{   ...} /* "~" can be understood to be omitted, that is, the style only acts on some elements of the title property value that contain the "CWW" string */

Descendant selector:

<! DOCTYPE html><p> Mina sang,<b> here is <i> Chen Play </i></b>, Good morning qwq</p></body><style>    P b i{       color:blue;    } </style>

The effect is as follows:

This is much faster than using class,id to achieve.

Child element Selector:

/* still use the above example: */<! DOCTYPE html>    p>b>i{       color:blue;    } </style>

Note that this is the format defined by the child element, denoted by a layer of symbols ">":

p>b>  i{       color:blue;    }
    • Note the difference between the child element selector and the descendant selector, the former to define the <i></i> content needs to be found <b></b> first, a total of three layers of relationship one can not be missed, while the latter can be directly from the <p> go to <i > can omit the middle <b> layer.

Adjacent sibling selector:

    • function from the back of an adjacent element
    • Must belong to the same parent element

"HTML" CSS Selector

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.