{"id":3016,"date":"2011-11-13T06:51:52","date_gmt":"2011-11-13T11:51:52","guid":{"rendered":"http:\/\/www.ericfeminella.com\/blog\/?p=3016"},"modified":"2016-03-30T14:59:56","modified_gmt":"2016-03-30T18:59:56","slug":"css3-combinators","status":"publish","type":"post","link":"https:\/\/www.ericfeminella.com\/blog\/2011\/11\/13\/css3-combinators\/","title":{"rendered":"CSS3 Combinators"},"content":{"rendered":"<p>In my previous article on CSS3 Selectors, I discussed the two <em>Attribute Selector<\/em> classifications; <a href=\"https:\/\/www.ericfeminella.com\/blog\/2011\/11\/10\/css3-attribute-selectors\/#attribute-presence-value-selectors\" target=\"_blank\">Attribute Presence and Value Selectors<\/a>, and, <a href=\"https:\/\/www.ericfeminella.com\/blog\/2011\/11\/10\/css3-attribute-selectors\/#attribute-substring-matching-selectors\" target=\"_blank\">Attribute Substring Matching Selectors<\/a>.<\/p>\n<p>In addition to the new Attribute Selectors, the <a href=\"http:\/\/www.w3.org\/TR\/css3-selectors\/\" target=\"_blank\">CSS3 Selectors Module<\/a> defines a new <em>Combinator<\/em> called the <strong>General sibling combinator<\/strong>, which is described below, succeeding a review of each CSS3 <em>Combinator<\/em>.<\/p>\n<section>\n<h2>Combinators<\/h2>\n<p>Combinators provide a means for describing relationships between elements in order to &#8220;combine&#8221; them to form specific rules based on a simple syntax. There are four Combinators in CSS3, below is description and example of each:<\/p>\n<div class=\"post-datalist\">\n<dl>\n<dt>Descendant combinator<\/dt>\n<dd>The most familiar of all Combinators, the <em>Descendant combinator<\/em> allows for selecting any element <em>f<\/em> which is a descendant (child, grandchild, great-grandchild and so on) of an element <em>e<\/em>. The combinator syntax for a Descendant combinator is a single &#8220;white-space&#8221; character.<\/p>\n<pre lang=\"javascript\">\r\n\/* \r\n Matches all <h1> elements which are descendants of \r\n an <article> element \r\n *\/\r\narticle h1{\r\n  \/* declarations *\/\r\n} \r\n<\/pre>\n<p><a href=\"http:\/\/www.w3.org\/TR\/selectors\/#descendant-combinators\" target=\"_blank\">8.1. Descendant combinator<\/a><br \/>\n\n<\/dd>\n<dt>Child combinators<\/dt>\n<dd><em>Child combinators<\/em> allow for selecting any element <em>f<\/em> which is a direct child of an element <em>e<\/em>. The combinator syntax for a <em>Child combinator<\/em> is a single &#8220;greater-than&#8221; (&gt;) sign.<\/p>\n<pre lang=\"javascript\">\r\n\/* \r\n Matches each <section> element that is a child \r\n of an <article> element \r\n *\/\r\narticle > section {\r\n  \/* declarations *\/\r\n} \r\n<\/pre>\n<p><a href=\"http:\/\/www.w3.org\/TR\/selectors\/#child-combinators\" target=\"_blank\">8.2. Child combinator<\/a><br \/>\n\n<\/dd>\n<dt>Adjacent sibling combinator<\/dt>\n<dd>The <em>Adjacent sibling combinator<\/em> is a <em>Sibling combinator<\/em> which allows for selecting an element <em>f<\/em> which is adjacent to an element <em>e<\/em>; that is, element <em>f<\/em> immediately follows element <em>e<\/em> in the document tree. The combinator syntax for an <em>Adjacent sibling combinator<\/em> is a single &#8220;plus&#8221; (+) sign.<\/p>\n<pre lang=\"javascript\">\r\n\/* \r\n Matches all <em> elements which are the next sibling \r\n of a <strong> element \r\n *\/\r\nstrong + em {\r\n  \/* declarations *\/\r\n} \r\n<\/pre>\n<p><a href=\"http:\/\/www.w3.org\/TR\/selectors\/#adjacent-sibling-combinators\" target=\"_blank\">8.3.1. Adjacent sibling combinator<\/a><br \/>\n\n<\/dd>\n<dt>General sibling combinator<\/dt>\n<dd>New in CSS3, the <em>General sibling combinator<\/em> is similar to the <em>Adjacent sibling combinator<\/em> in that it matches an element <em>f<\/em> which follows an element <em>e<\/em> in the document tree; however, whereas in the <em>Adjacent sibling combinator<\/em> element <em>f<\/em> must immediately follow element <em>e<\/em>, the <em>General sibling combinator<\/em> allows for selecting an element <em>f<\/em> which is preceded by an element <em>e<\/em>, but not necessarily immediately preceded by an element <em>e<\/em>. The combinator syntax for a <em>General sibling combinator<\/em> is a single &#8220;tilde&#8221; (~) sign.<\/p>\n<pre lang=\"javascript\">\r\n\/* \r\n Matches all <time> elements which are preceded by \r\n a <del> element \r\n *\/\r\ndel ~ time {\r\n  \/* declarations *\/\r\n} \r\n<\/pre>\n<p><a href=\"http:\/\/www.w3.org\/TR\/selectors\/#general-sibling-combinators\" target=\"_blank\">8.3.2. General sibling combinator<\/a><br \/>\n\n<\/dd>\n<\/dl>\n<p>The following demonstrates a very basic example of each of the above Combinators:<br \/>\n<a href=\"http:\/\/code.ericfeminella.com\/articles\/examples\/css3\/selectors\/combinators.html\" target=\"_blank\" title=\"CSS3 Combinators Example\">View Example<\/a>\n<\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>In my previous article on CSS3 Selectors, I discussed the two Attribute Selector classifications; Attribute Presence and Value Selectors, and, Attribute Substring Matching Selectors. In addition to the new Attribute Selectors, the CSS3 Selectors Module defines a new Combinator called the General sibling combinator, which is described below, succeeding a review of each CSS3 Combinator. Combinators Combinators provide a means&#8230; <a class=\"read-more\" href=\"https:\/\/www.ericfeminella.com\/blog\/2011\/11\/13\/css3-combinators\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[133,62,59,78],"tags":[166,66,165,161,65,167],"class_list":["post-3016","post","type-post","status-publish","format-standard","hentry","category-browsers","category-css3","category-html5","category-javascript-2","tag-browsers-2","tag-css3-2","tag-css3-combinators","tag-css3-selectors","tag-html5-2","tag-selectors"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/3016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/comments?post=3016"}],"version-history":[{"count":0,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/3016\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media?parent=3016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/categories?post=3016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/tags?post=3016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}