W3C home > Mailing lists > Public > www-style@w3.org > March 2009

[css-3 selectors] The :parent pseudo-class

From: Gabriele Romanato <gabriele.romanato@gmail.com>
Date: Tue, 24 Mar 2009 03:31:03 +0100
Message-Id: <15F0C218-419C-4AD6-9299-AD9645016462@gmail.com>
To: www-style@w3.org
CSS is a language that uses a top-down approach when walking the DOM  
Sometimes, however, it's useful to walk the tree from bottom to top.
Consider the following:

<h3><a href="#"></a></h3>

h3 {
padding-bottom: 0.2em;

I want to reset the bottom padding only on h3 elements that have a  
link inside.
Authors usually use classes in such cases. With the :parent pseudo- 
class, instead, we could write:

a:parent {
padding-bottom: 0;

The :parent pseudo-class, whose syntax is E:parent, matches the parent  
element of a given child
element. This is the same as Node.parentNode in a DOM context.


http://www.css-zibaldone.com/test/  (English)
http://www.css-zibaldone.com/articles/  (English)
http://mimicry.css-zibaldone.com/ (Blog)
http://www.flickr.com/photos/gabrieleromanato/ (Flickr)
Received on Tuesday, 24 March 2009 02:31:45 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:25 UTC