DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Languages
  4. What’s new in CSS 4 selectors

What’s new in CSS 4 selectors

Axel Rauschmayer user avatar by
Axel Rauschmayer
·
Dec. 13, 11 · Interview
Like (0)
Save
Tweet
Share
5.30K Views

Join the DZone community and get the full member experience.

Join For Free
The following are the highlights of what is new in CSS 4 selectors:

  • Determining the subject of a selector. Currently, if a selector consists of several compound selectors, the last one is considered its subject. The subject determines what elements the rule applies to. CSS 4 allows one to make any compound selector the subject, by prepending a dollar sign. For example:
    $ul li:hover {
        color: green;
    }
    Here, if one hovers over a list element, the whole list will turn green. This is a great and dearly needed feature.

  • Pseudo-class :nth-match(). Lets you apply a rule to every n-th match for a given selector list.
    :nth-match(an+b of selector-list)
    Previously, you could only access every n-th child. This selector gives you more flexibility.

  • UI states pseudo-classes allow you to style elements depending on their user interface state. Examples: :disabled, :checked (radio elements, checkbox elements, menu items, etc.), :in-range (for input elements with range limitations).

  • The matches-any pseudo-class :matches(). Example:
    :matches(section, article, aside) h1 {
        font-size: 3em;
    }
    
    The above selector is an abbreviation for
    section h1, article h1, aside h1
    

  • The contextual reference element pseudo-class ‘:scope’. When you use selectors to query for elements, you can start your search in a list of elements that is iterated over, one element at a time. :scope is a placeholder for the current element. Example:
    document.querySelector(":scope > ul > li", elems)
    
    The above returns all list items that are direct children of unordered lists that are direct children of the elements in elems.

More details (partial source of this post): “Discover What’s New in CSS 4 [selectors]” by Scott Gilbertson for Webmonkey.

 

Source: http://www.2ality.com/2011/12/css4-selectors.html

CSS Element

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Microservices Testing
  • Assessment of Scalability Constraints (and Solutions)
  • Introduction To OpenSSH
  • What Is Advertised Kafka Address?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: