 
    
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>howto Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/howto/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Fri, 17 May 2019 11:57:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Attribute Selectors &#8211; Advanced CSS Selectors &#8211; Part 4</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/attribute-selectors-advanced-css-selectors-part-4/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 07 May 2019 18:16:02 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5 selectors]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3844</guid>

					<description><![CDATA[<p>Learn the 7 different ways to write [attribute] selectors.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/attribute-selectors-advanced-css-selectors-part-4/">Attribute Selectors &#8211; Advanced CSS Selectors &#8211; Part 4</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>Attribute selectors offer more options than selectors for HTML tags, <span class="css-id">ID</span>s, and <span class="css-class">classes</span>.</p>
<p>As with all selectors, you can combine them to create powerful and specific selectors.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#review-of-attributes-seen-so-far">Review of Attributes Seen So Far</a></li>
<li><a href="#attribute">Attribute</a></li>
<li><a href="#exact-value">Exact Value</a></li>
<li><a href="#exact-match-a-single-value">Exact Match a Single Value</a></li>
<li><a href="#partial-match-at-start-of-value-1">Partial Match at Start of Value #1</a></li>
<li><a href="#partial-match-at-start-of-value-2">Partial Match at Start of Value #2</a></li>
<li><a href="#partial-match-at-end-of-value">Partial Match at End of Value</a></li>
<li><a href="#partial-match-anywhere-in-value">Partial Match Anywhere in Value</a></li>
<li><a href="#case-sensitivity">Case Sensitivity</a></li>
<li><a href="#closing-thoughts">Closing Thoughts</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="review-of-attributes-seen-so-far">Review of Attributes Seen So Far</h2>
<p>Attributes are additional information included inside HTML tags. So far, we have seen 9 of them (each item links to their first use in this tutorial series):</p>
<ol class="incremental" type="1">
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#id-selector"><span class="css-id">id</span></a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#class-selector"><span class="css-class">class</span></a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#class-selector">href</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/hyperlinks-in-html/#target">target</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/hyperlinks-in-html/#download">download</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/images-in-html/#src">src</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/images-in-html/#alt">alt</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/lists-in-html/#reversed">reversed</a></li>
<li><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/lists-in-html/#start">start</a></li>
</ol>
<p>Example use is shown below:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb1-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"main"</span><span class="kw">&gt;</span>
<a id="cb1-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"important todo scale"</span><span class="kw">&gt;</span>
<a id="cb1-3" class="sourceLine" title="3"></a>    Some paragraph text.
<a id="cb1-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb1-5" class="sourceLine" title="5"></a><span class="kw">&lt;/div&gt;</span>  
<a id="cb1-6" class="sourceLine" title="6"></a>
<a id="cb1-7" class="sourceLine" title="7"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span>
<a id="cb1-8" class="sourceLine" title="8"></a><span class="ot">   target=</span><span class="st">"_blank"</span>
<a id="cb1-9" class="sourceLine" title="9"></a><span class="ot">   download=</span><span class="st">"file.txt"</span><span class="kw">&gt;</span>
<a id="cb1-10" class="sourceLine" title="10"></a>   This is a link.
<a id="cb1-11" class="sourceLine" title="11"></a><span class="kw">&lt;/a&gt;</span>
<a id="cb1-12" class="sourceLine" title="12"></a>
<a id="cb1-13" class="sourceLine" title="13"></a><span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"/img/picture.jpg"</span>
<a id="cb1-14" class="sourceLine" title="14"></a><span class="ot">     alt=</span><span class="st">"Description of the image"</span><span class="kw">&gt;</span>
<a id="cb1-15" class="sourceLine" title="15"></a>
<a id="cb1-16" class="sourceLine" title="16"></a><span class="kw">&lt;ol</span><span class="ot"> reversed</span>
<a id="cb1-17" class="sourceLine" title="17"></a><span class="ot">    start=</span><span class="st">"101"</span><span class="kw">&gt;</span>
<a id="cb1-18" class="sourceLine" title="18"></a>  <span class="kw">&lt;li&gt;</span>Item 1<span class="kw">&lt;/li&gt;</span>
<a id="cb1-19" class="sourceLine" title="19"></a>  <span class="kw">&lt;li&gt;</span>Item 2<span class="kw">&lt;/li&gt;</span>
<a id="cb1-20" class="sourceLine" title="20"></a><span class="kw">&lt;/ol&gt;</span></code></pre>
</div>
<h2 id="attribute">Attribute</h2>
<p>You can select elements by the attributes they contain by writing the attribute between square braces:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb2-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb2-2" class="sourceLine" title="2"></a><span class="co">  select all HTML elements containing the</span>
<a id="cb2-3" class="sourceLine" title="3"></a><span class="co">  'reversed' attribute</span>
<a id="cb2-4" class="sourceLine" title="4"></a><span class="co">*/</span>
<a id="cb2-5" class="sourceLine" title="5"></a><span class="ex">[reversed]</span> {
<a id="cb2-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb2-7" class="sourceLine" title="7"></a>}
<a id="cb2-8" class="sourceLine" title="8"></a>
<a id="cb2-9" class="sourceLine" title="9"></a><span class="co">/*</span>
<a id="cb2-10" class="sourceLine" title="10"></a><span class="co">  select all HTML elements containing the</span>
<a id="cb2-11" class="sourceLine" title="11"></a><span class="co">  'id' attribute</span>
<a id="cb2-12" class="sourceLine" title="12"></a><span class="co">*/</span>
<a id="cb2-13" class="sourceLine" title="13"></a><span class="ex">[id]</span> {
<a id="cb2-14" class="sourceLine" title="14"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb2-15" class="sourceLine" title="15"></a>}</code></pre>
</div>
<h2 id="exact-value">Exact Value</h2>
<p>You can select by specifying the exact attribute and its value. The value must be in quotes:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" title="1"></a><span class="ex">[id</span><span class="op">=</span><span class="st">"footer"</span><span class="ex">]</span> {
<a id="cb3-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb3-3" class="sourceLine" title="3"></a>}
<a id="cb3-4" class="sourceLine" title="4"></a>
<a id="cb3-5" class="sourceLine" title="5"></a><span class="ex">[class</span><span class="op">=</span><span class="st">"red box"</span><span class="ex">]</span>{
<a id="cb3-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb3-7" class="sourceLine" title="7"></a>}
<a id="cb3-8" class="sourceLine" title="8"></a>
<a id="cb3-9" class="sourceLine" title="9"></a><span class="ex">[start</span><span class="op">=</span><span class="st">"101"</span><span class="ex">]</span> {
<a id="cb3-10" class="sourceLine" title="10"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb3-11" class="sourceLine" title="11"></a>}</code></pre>
</div>
<h2 id="exact-match-a-single-value">Exact Match a Single Value</h2>
<p>If you have attributes with multiple values (<span class="css-class">classes</span> are a good example), you can select based on one of the values by placing a tilde (<strong>~</strong>) before the equals sign:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb4-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">~=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb4-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb4-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will select the following HTML elements because they all contain <strong>box</strong>:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" title="1"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"red box"</span><span class="kw">&gt;</span>This is a selected paragraph.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-2" class="sourceLine" title="2"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"box blue"</span><span class="kw">&gt;</span>This one too.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-3" class="sourceLine" title="3"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"red green box blue"</span><span class="kw">&gt;</span>This too!<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>The attribute values must be separated by spaces:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb6-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb6-2" class="sourceLine" title="2"></a><span class="co">  Validly separated attribute values</span>
<a id="cb6-3" class="sourceLine" title="3"></a><span class="co">--&gt;</span>
<a id="cb6-4" class="sourceLine" title="4"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"red box a b c"</span><span class="kw">&gt;&lt;/p&gt;</span>
<a id="cb6-5" class="sourceLine" title="5"></a>
<a id="cb6-6" class="sourceLine" title="6"></a><span class="co">&lt;!--</span>
<a id="cb6-7" class="sourceLine" title="7"></a><span class="co">  incorrectly separated attribute values</span>
<a id="cb6-8" class="sourceLine" title="8"></a><span class="co">--&gt;</span>
<a id="cb6-9" class="sourceLine" title="9"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"red,box,a,b,c"</span><span class="kw">&gt;&lt;/p&gt;</span>
<a id="cb6-10" class="sourceLine" title="10"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"a, b, c"</span><span class="kw">&gt;&lt;/p&gt;</span></code></pre>
</div>
<p>You can only match one attribute value:</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb7-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb7-2" class="sourceLine" title="2"></a><span class="co">  THIS NEVER MATCHES ANYTHING</span>
<a id="cb7-3" class="sourceLine" title="3"></a>
<a id="cb7-4" class="sourceLine" title="4"></a><span class="co">  Even if you have an element like this:</span>
<a id="cb7-5" class="sourceLine" title="5"></a>
<a id="cb7-6" class="sourceLine" title="6"></a><span class="co">  &lt;p class="a red box blue"&gt;</span>
<a id="cb7-7" class="sourceLine" title="7"></a>
<a id="cb7-8" class="sourceLine" title="8"></a><span class="co">*/</span>
<a id="cb7-9" class="sourceLine" title="9"></a><span class="ex">[class</span><span class="op">~=</span><span class="st">"red box"</span><span class="ex">]</span> {
<a id="cb7-10" class="sourceLine" title="10"></a>
<a id="cb7-11" class="sourceLine" title="11"></a>}</code></pre>
</div>
<h2 id="partial-match-at-start-of-value-1">Partial Match at Start of Value #1</h2>
<p>You can match the beginning of a value string by using the <strong>vertical-bar</strong> before the equals sign (<strong>|=</strong>). The match <strong>must</strong> be followed by a hyphen:</p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">|=</span><span class="st">"cf"</span><span class="ex">]</span> {
<a id="cb8-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb8-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will match the following:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb9-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-abc"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb9-2" class="sourceLine" title="2"></a>
<a id="cb9-3" class="sourceLine" title="3"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb9-4" class="sourceLine" title="4"></a>
<a id="cb9-5" class="sourceLine" title="5"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-d blue box"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>The selector above will <strong>not</strong> match any of the following:</p>
<div id="cb10" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb10-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb10-2" class="sourceLine" title="2"></a><span class="co">  cf is not followed by a hyphen</span>
<a id="cb10-3" class="sourceLine" title="3"></a><span class="co">--&gt;</span>
<a id="cb10-4" class="sourceLine" title="4"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb10-5" class="sourceLine" title="5"></a>
<a id="cb10-6" class="sourceLine" title="6"></a><span class="co">&lt;!--</span>
<a id="cb10-7" class="sourceLine" title="7"></a><span class="co">  cf is not at the start of the value string</span>
<a id="cb10-8" class="sourceLine" title="8"></a><span class="co">--&gt;</span>
<a id="cb10-9" class="sourceLine" title="9"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"red cf- box"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>This is an extremely specific behaviour that was originally introduced for dealing with language codes.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></p>
<h2 id="partial-match-at-start-of-value-2">Partial Match at Start of Value #2</h2>
<p>This is the more common way to match the start of an attribute value string.</p>
<p>You can match the beginning of a value string by using the <strong>caret</strong> before the equals sign (<strong>^=</strong>):</p>
<div id="cb11" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb11-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">^=</span><span class="st">"cf"</span><span class="ex">]</span> {
<a id="cb11-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb11-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will match the following:</p>
<div id="cb12" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb12-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cfabc"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb12-2" class="sourceLine" title="2"></a>
<a id="cb12-3" class="sourceLine" title="3"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb12-4" class="sourceLine" title="4"></a>
<a id="cb12-5" class="sourceLine" title="5"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb12-6" class="sourceLine" title="6"></a>
<a id="cb12-7" class="sourceLine" title="7"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-d blue box"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>The selector above will <strong>not</strong> match any of the following:</p>
<div id="cb13" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb13-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb13-2" class="sourceLine" title="2"></a><span class="co">  cf is not at the start of the value string</span>
<a id="cb13-3" class="sourceLine" title="3"></a><span class="co">--&gt;</span>
<a id="cb13-4" class="sourceLine" title="4"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"red cf box"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>It should be obvious that you can make the <strong>^=</strong> equivalent to the <strong>|=</strong> by simply appending a hyphen to your string:</p>
<div id="cb14" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb14-1" class="sourceLine" title="1"></a>
<a id="cb14-2" class="sourceLine" title="2"></a><span class="co">/*</span>
<a id="cb14-3" class="sourceLine" title="3"></a><span class="co">  These two selectors are identical.</span>
<a id="cb14-4" class="sourceLine" title="4"></a><span class="co">*/</span>
<a id="cb14-5" class="sourceLine" title="5"></a><span class="ex">[class</span><span class="op">^=</span><span class="st">"cf-"</span><span class="ex">]</span> {
<a id="cb14-6" class="sourceLine" title="6"></a>
<a id="cb14-7" class="sourceLine" title="7"></a>}
<a id="cb14-8" class="sourceLine" title="8"></a>
<a id="cb14-9" class="sourceLine" title="9"></a><span class="ex">[class</span><span class="op">|=</span><span class="st">"cf"</span><span class="ex">]</span> {
<a id="cb14-10" class="sourceLine" title="10"></a>
<a id="cb14-11" class="sourceLine" title="11"></a>}</code></pre>
</div>
<h2 id="partial-match-at-end-of-value">Partial Match at End of Value</h2>
<p>You can match the end of a value string by using the <strong>dollar</strong> symbol before the equals sign (<strong>$=</strong>):</p>
<div id="cb15" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb15-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">$=</span><span class="st">"nt"</span><span class="ex">]</span> {
<a id="cb15-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb15-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will match the following:</p>
<div id="cb16" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb16-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"nt"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb16-2" class="sourceLine" title="2"></a>
<a id="cb16-3" class="sourceLine" title="3"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"plant"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb16-4" class="sourceLine" title="4"></a>
<a id="cb16-5" class="sourceLine" title="5"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-d blue box plant"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>The selector above will <strong>not</strong> match any of the following:</p>
<div id="cb17" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb17-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb17-2" class="sourceLine" title="2"></a><span class="co">  nt is not at the end of the value string</span>
<a id="cb17-3" class="sourceLine" title="3"></a><span class="co">--&gt;</span>
<a id="cb17-4" class="sourceLine" title="4"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"red nt box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb17-5" class="sourceLine" title="5"></a>
<a id="cb17-6" class="sourceLine" title="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"plants"</span><span class="er">&lt;/div</span><span class="kw">&gt;</span></code></pre>
</div>
<h2 id="partial-match-anywhere-in-value">Partial Match Anywhere in Value</h2>
<p>You can match the value anywhere in a string by using the <strong>asterisk</strong> symbol before the equals sign (<strong>*=</strong>):</p>
<div id="cb18" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb18-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">*=</span><span class="st">"nt"</span><span class="ex">]</span> {
<a id="cb18-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb18-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will match the following:</p>
<div id="cb19" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb19-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"nt"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb19-2" class="sourceLine" title="2"></a>
<a id="cb19-3" class="sourceLine" title="3"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"planter"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb19-4" class="sourceLine" title="4"></a>
<a id="cb19-5" class="sourceLine" title="5"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"cf-d blue plant box"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>The selector above will <strong>not</strong> match any of the following:</p>
<div id="cb20" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb20-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb20-2" class="sourceLine" title="2"></a><span class="co">  nt is not is not found in any value string</span>
<a id="cb20-3" class="sourceLine" title="3"></a><span class="co">--&gt;</span>
<a id="cb20-4" class="sourceLine" title="4"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"red flat box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb20-5" class="sourceLine" title="5"></a>
<a id="cb20-6" class="sourceLine" title="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"explains"</span><span class="er">&lt;/div</span><span class="kw">&gt;</span></code></pre>
</div>
<h2 id="case-sensitivity">Case Sensitivity</h2>
<p>If you want to match values without regard to upper and lower case, you append <strong>i</strong> to the end of the attribute selector:</p>
<div id="cb21" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb21-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">=</span><span class="st">"red" i</span><span class="ex">]</span> {
<a id="cb21-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 0:1:0 */</span>
<a id="cb21-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The selector above will match any of the following:<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></p>
<div id="cb22" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb22-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"red"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-2" class="sourceLine" title="2"></a>
<a id="cb22-3" class="sourceLine" title="3"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"RED"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-4" class="sourceLine" title="4"></a>
<a id="cb22-5" class="sourceLine" title="5"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"Red"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-6" class="sourceLine" title="6"></a>
<a id="cb22-7" class="sourceLine" title="7"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"rED"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-8" class="sourceLine" title="8"></a>
<a id="cb22-9" class="sourceLine" title="9"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"rEd"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-10" class="sourceLine" title="10"></a>
<a id="cb22-11" class="sourceLine" title="11"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"ReD"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-12" class="sourceLine" title="12"></a>
<a id="cb22-13" class="sourceLine" title="13"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"REd"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb22-14" class="sourceLine" title="14"></a>
<a id="cb22-15" class="sourceLine" title="15"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"reD"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>It is a good idea to be consistent in your use of case to avoid situations where you might need to use case insensitive matching.</p>
<h2 id="closing-thoughts">Closing Thoughts</h2>
<ol class="incremental" type="1">
<li>Attribute selectors provide 7 different ways to match attributes and their values.
<ol class="incremental" type="1">
<li>[attribute] &#8211; select only by attribute name</li>
<li>[attribute=“value”] &#8211; select by attribute name and exact value</li>
<li>[attribute~=“value”] &#8211; select by attribute name and exact match one value in the value string</li>
<li>[attribute|=“val”] &#8211; select by attribute name and exact match at the beginning of the value string which must then be followed by a hyphen</li>
<li>[attribute^=“val”] &#8211; select by attribute name and exact match match at the beginning of the value string</li>
<li>[attribute$=“lue”] &#8211; select by attribute name and exact match at the end of the value string</li>
<li>[attribute*=“value”] &#8211; select by attribute name and exact match anywhere in the value string</li>
</ol>
</li>
<li>You can combine attribute selectors with other selectors and combinators:
<div id="cb23" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb23-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb23-2" class="sourceLine" title="2"></a><span class="co">  only selects ordered lists that contain the</span>
<a id="cb23-3" class="sourceLine" title="3"></a><span class="co">  attribute reversed and the attribute list</span>
<a id="cb23-4" class="sourceLine" title="4"></a><span class="co">*/</span>
<a id="cb23-5" class="sourceLine" title="5"></a>ol<span class="ex">[reversed][start]</span> {
<a id="cb23-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity 0:2:1 */</span>
<a id="cb23-7" class="sourceLine" title="7"></a>
<a id="cb23-8" class="sourceLine" title="8"></a>}
<a id="cb23-9" class="sourceLine" title="9"></a>
<a id="cb23-10" class="sourceLine" title="10"></a><span class="co">/*</span>
<a id="cb23-11" class="sourceLine" title="11"></a><span class="co">  selects elements contained within objects</span>
<a id="cb23-12" class="sourceLine" title="12"></a><span class="co">  having an ID of #main if those elements</span>
<a id="cb23-13" class="sourceLine" title="13"></a><span class="co">  contain an attribute of target</span>
<a id="cb23-14" class="sourceLine" title="14"></a><span class="co">*/</span>
<a id="cb23-15" class="sourceLine" title="15"></a><span class="pp">#main</span> <span class="ex">[target</span><span class="op">=</span><span class="st">"_blank"</span><span class="ex">]</span> {
<a id="cb23-16" class="sourceLine" title="16"></a>  <span class="co">/* specificity = 1:1:0 */</span>
<a id="cb23-17" class="sourceLine" title="17"></a>}</code></pre>
</div>
</li>
<li>You could colour code links to visually show if they refer this site or an external site:
<div id="cb24" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb24-1" class="sourceLine" title="1"></a>  <span class="co">/*</span>
<a id="cb24-2" class="sourceLine" title="2"></a><span class="co">    as long as the link contains</span>
<a id="cb24-3" class="sourceLine" title="3"></a><span class="co">    complet-concrete-concise.com</span>
<a id="cb24-4" class="sourceLine" title="4"></a><span class="co">    we assume is points to this website</span>
<a id="cb24-5" class="sourceLine" title="5"></a><span class="co">  */</span>
<a id="cb24-6" class="sourceLine" title="6"></a>  a<span class="ex">[href</span><span class="op">*=</span><span class="st">"complete-concrete-concise.com"</span><span class="ex">]</span> {
<a id="cb24-7" class="sourceLine" title="7"></a>    <span class="kw">color</span>: <span class="cn">green</span><span class="op">;</span>
<a id="cb24-8" class="sourceLine" title="8"></a>  }</code></pre>
</div>
</li>
<li>You could colour code links to visually show if a link uses a secure or unsecured connection:
<div id="cb25" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb25-1" class="sourceLine" title="1"></a>  <span class="co">/*</span>
<a id="cb25-2" class="sourceLine" title="2"></a><span class="co">    secure links begin with https</span>
<a id="cb25-3" class="sourceLine" title="3"></a><span class="co">  */</span>
<a id="cb25-4" class="sourceLine" title="4"></a>  a<span class="ex">[href</span><span class="op">^=</span><span class="st">"https:"</span><span class="ex">]</span> {
<a id="cb25-5" class="sourceLine" title="5"></a>    <span class="kw">color</span>: <span class="cn">green</span><span class="op">;</span>
<a id="cb25-6" class="sourceLine" title="6"></a>  }
<a id="cb25-7" class="sourceLine" title="7"></a>
<a id="cb25-8" class="sourceLine" title="8"></a>  <span class="co">/*</span>
<a id="cb25-9" class="sourceLine" title="9"></a><span class="co">    unsecured links begin with http</span>
<a id="cb25-10" class="sourceLine" title="10"></a><span class="co">  */</span>
<a id="cb25-11" class="sourceLine" title="11"></a>  a<span class="ex">[href</span><span class="op">^=</span><span class="st">"http:"</span><span class="ex">]</span> {
<a id="cb25-12" class="sourceLine" title="12"></a>    <span class="kw">color</span>: <span class="cn">red</span><span class="op">;</span>
<a id="cb25-13" class="sourceLine" title="13"></a>  }</code></pre>
</div>
</li>
<li>Given the following HTML code:
<div id="cb26" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb26-1" class="sourceLine" title="1"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"box"</span><span class="kw">&gt;</span>Some paragraph.<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>There is no functional difference between these pairs of selectors:</p>
<div id="cb27" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb27-1" class="sourceLine" title="1"></a>
<a id="cb27-2" class="sourceLine" title="2"></a><span class="ex">[class</span><span class="op">=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb27-3" class="sourceLine" title="3"></a>
<a id="cb27-4" class="sourceLine" title="4"></a>}
<a id="cb27-5" class="sourceLine" title="5"></a>
<a id="cb27-6" class="sourceLine" title="6"></a><span class="fu">.box</span> {
<a id="cb27-7" class="sourceLine" title="7"></a>
<a id="cb27-8" class="sourceLine" title="8"></a>}
<a id="cb27-9" class="sourceLine" title="9"></a>
<a id="cb27-10" class="sourceLine" title="10"></a>
<a id="cb27-11" class="sourceLine" title="11"></a>p<span class="ex">[class</span><span class="op">=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb27-12" class="sourceLine" title="12"></a>
<a id="cb27-13" class="sourceLine" title="13"></a>}
<a id="cb27-14" class="sourceLine" title="14"></a>
<a id="cb27-15" class="sourceLine" title="15"></a>p<span class="fu">.box</span> {
<a id="cb27-16" class="sourceLine" title="16"></a>
<a id="cb27-17" class="sourceLine" title="17"></a>}</code></pre>
</div>
</li>
<li>Given the following HTML code:
<div id="cb28" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb28-1" class="sourceLine" title="1"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"box blue"</span><span class="kw">&gt;</span>Some paragraph.<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>These pairs of selectors behave differently:</p>
<div id="cb29" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb29-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb29-2" class="sourceLine" title="2"></a><span class="co">  selects only if the class is exactly "box"</span>
<a id="cb29-3" class="sourceLine" title="3"></a><span class="co">*/</span>
<a id="cb29-4" class="sourceLine" title="4"></a><span class="ex">[class</span><span class="op">=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb29-5" class="sourceLine" title="5"></a>
<a id="cb29-6" class="sourceLine" title="6"></a>}
<a id="cb29-7" class="sourceLine" title="7"></a>
<a id="cb29-8" class="sourceLine" title="8"></a><span class="co">/*</span>
<a id="cb29-9" class="sourceLine" title="9"></a><span class="co">  selects if the class contains "box"</span>
<a id="cb29-10" class="sourceLine" title="10"></a><span class="co">*/</span>
<a id="cb29-11" class="sourceLine" title="11"></a><span class="fu">.box</span> {
<a id="cb29-12" class="sourceLine" title="12"></a>
<a id="cb29-13" class="sourceLine" title="13"></a>}
<a id="cb29-14" class="sourceLine" title="14"></a>
<a id="cb29-15" class="sourceLine" title="15"></a>
<a id="cb29-16" class="sourceLine" title="16"></a>p<span class="ex">[class</span><span class="op">=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb29-17" class="sourceLine" title="17"></a>
<a id="cb29-18" class="sourceLine" title="18"></a>}
<a id="cb29-19" class="sourceLine" title="19"></a>
<a id="cb29-20" class="sourceLine" title="20"></a>p<span class="fu">.box</span> {
<a id="cb29-21" class="sourceLine" title="21"></a>
<a id="cb29-22" class="sourceLine" title="22"></a>}</code></pre>
</div>
<p>You might be tempted to rewrite the attribute selector as:</p>
<div id="cb30" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb30-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">*=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb30-2" class="sourceLine" title="2"></a>
<a id="cb30-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>But that selector will match not only <strong>box</strong>, but also: <strong>matchbox</strong>, <strong>bitbox</strong>, and any other class with <strong>box</strong> in it.</p>
<p>The correct substitution would be:</p>
<div id="cb31" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb31-1" class="sourceLine" title="1"></a><span class="ex">[class</span><span class="op">~=</span><span class="st">"box"</span><span class="ex">]</span> {
<a id="cb31-2" class="sourceLine" title="2"></a>
<a id="cb31-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
</li>
<li>Analyzing 4632 CSS rules<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a> from the home pages of 5 different websites<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a> revealed the following attribute selector distribution:<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a>
<ul class="incremental">
<li>2.5% of the rules use attribute selectors</li>
<li>85.2% of the attribute selectors use an exact match ([attribute=“value”])</li>
<li>11.3% of the attribute selectors match the attribute ([attribute])</li>
<li>3.5% of the attribute selectors do a partial on the start of the value ([attribute^=“val”])</li>
<li>No other attribute selector types were used</li>
</ul>
</li>
<li>To see some real world selector examples using attribute selectors, consider the following from the <a href="https://github.com/WordPress/twentysixteen/blob/master/style.css">WordPress 2016 Theme</a>:<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a>
<div id="cb32" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb32-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb32-2" class="sourceLine" title="2"></a><span class="co">  Style a link (&lt;a&gt;) only if:</span>
<a id="cb32-3" class="sourceLine" title="3"></a><span class="co">  (1) the value of href begins with "mailto:"</span>
<a id="cb32-4" class="sourceLine" title="4"></a><span class="co">  (2) it is somewhere inside a block with a</span>
<a id="cb32-5" class="sourceLine" title="5"></a><span class="co">      class of .social-navigation</span>
<a id="cb32-6" class="sourceLine" title="6"></a>
<a id="cb32-7" class="sourceLine" title="7"></a><span class="co">  :before is a pseudo-element which will be</span>
<a id="cb32-8" class="sourceLine" title="8"></a><span class="co">  covered in a later tutorial. Pseudo-elements</span>
<a id="cb32-9" class="sourceLine" title="9"></a><span class="co">  add 0:1:0 to specificity</span>
<a id="cb32-10" class="sourceLine" title="10"></a>
<a id="cb32-11" class="sourceLine" title="11"></a><span class="co">  specificity = 0:3:1</span>
<a id="cb32-12" class="sourceLine" title="12"></a><span class="co">*/</span>
<a id="cb32-13" class="sourceLine" title="13"></a><span class="fu">.social-navigation</span> a<span class="ex">[href</span><span class="op">^=</span><span class="st">"mailto:"</span><span class="ex">]</span><span class="in">:before</span> {
<a id="cb32-14" class="sourceLine" title="14"></a>    <span class="kw">content</span>: <span class="st">"</span><span class="sc">\f410</span><span class="st">"</span><span class="op">;</span>
<a id="cb32-15" class="sourceLine" title="15"></a>}
<a id="cb32-16" class="sourceLine" title="16"></a>
<a id="cb32-17" class="sourceLine" title="17"></a><span class="co">/*</span>
<a id="cb32-18" class="sourceLine" title="18"></a><span class="co">Style a link (&lt;a&gt;) only if:</span>
<a id="cb32-19" class="sourceLine" title="19"></a><span class="co">(1) the value of href ends with "/feed/:"</span>
<a id="cb32-20" class="sourceLine" title="20"></a><span class="co">(2) it is somewhere inside a block with a</span>
<a id="cb32-21" class="sourceLine" title="21"></a><span class="co">    class of .social-navigation</span>
<a id="cb32-22" class="sourceLine" title="22"></a>
<a id="cb32-23" class="sourceLine" title="23"></a><span class="co">:before is a pseudo-element which will be</span>
<a id="cb32-24" class="sourceLine" title="24"></a><span class="co">covered in a later tutorial. Pseudo-elements</span>
<a id="cb32-25" class="sourceLine" title="25"></a><span class="co">add 0:1:0 to specificity</span>
<a id="cb32-26" class="sourceLine" title="26"></a>
<a id="cb32-27" class="sourceLine" title="27"></a><span class="co">specificity = 0:3:1</span>
<a id="cb32-28" class="sourceLine" title="28"></a><span class="co">*/</span>
<a id="cb32-29" class="sourceLine" title="29"></a><span class="fu">.social-navigation</span> a<span class="ex">[href</span><span class="op">$=</span><span class="st">"/feed/"</span><span class="ex">]</span><span class="in">:before</span> {
<a id="cb32-30" class="sourceLine" title="30"></a>    <span class="kw">content</span>: <span class="st">"</span><span class="sc">\f413</span><span class="st">"</span><span class="op">;</span>
<a id="cb32-31" class="sourceLine" title="31"></a>}
<a id="cb32-32" class="sourceLine" title="32"></a>
<a id="cb32-33" class="sourceLine" title="33"></a><span class="co">/*</span>
<a id="cb32-34" class="sourceLine" title="34"></a><span class="co">  Style &lt;img&gt; tags only if:</span>
<a id="cb32-35" class="sourceLine" title="35"></a><span class="co">  (1) they have a class name containing</span>
<a id="cb32-36" class="sourceLine" title="36"></a><span class="co">      "wp-image-"</span>
<a id="cb32-37" class="sourceLine" title="37"></a><span class="co">  (2) they are somewhere inside a block with</span>
<a id="cb32-38" class="sourceLine" title="38"></a><span class="co">      a class of .wp-caption</span>
<a id="cb32-39" class="sourceLine" title="39"></a>
<a id="cb32-40" class="sourceLine" title="40"></a><span class="co">  specificity = 0:2:1</span>
<a id="cb32-41" class="sourceLine" title="41"></a><span class="co">*/</span>
<a id="cb32-42" class="sourceLine" title="42"></a><span class="fu">.wp-caption</span> img<span class="ex">[class</span><span class="op">*=</span><span class="st">"wp-image-"</span><span class="ex">]</span> {
<a id="cb32-43" class="sourceLine" title="43"></a>    <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb32-44" class="sourceLine" title="44"></a>    <span class="kw">margin</span>: <span class="dv">0</span><span class="op">;</span>
<a id="cb32-45" class="sourceLine" title="45"></a>}</code></pre>
</div>
</li>
</ol>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://drafts.csswg.org/selectors-4/#attribute-selectors">CSS Attribute Selectors</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-combinators-advanced-css-selectors-part-3/">Prev</a></p>
</div>
<div class="next">
<p><a href="#">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">This will be covered in a future tutorial. Essentially, language tags allow on to specify the primary language and a subset of that language. For example: <strong>en</strong> specifies the English language, <strong>en-ca</strong> specifies Canadian English, <strong>en-nz</strong> specifies New Zealand English, etc.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">This does not work with all browsers. It does not work with Internet Explorer, Microsoft Edge version 18 or lower, Android Browser (Android version 4.4 or earlier). A good site to check if a particular HTML or CSS feature is supported is <a href="https://caniuse.com/">Can I Use</a>.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">Yes, it is a lot of rules.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">I pulled the CSS from the main landing pages of the following:
<ul class="incremental">
<li>BBC,</li>
<li>Engadget,</li>
<li>The Verge,</li>
<li>Wikipedia,</li>
<li>WordPress</li>
</ul>
<p><a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">Take these numbers as a rough guide to their relative use.<a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">There is plenty in the CSS Styling that you haven’t seen &#8211; but they will be covered in future tutorials.<a class="footnote-back" href="#fnref6">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/attribute-selectors-advanced-css-selectors-part-4/">Attribute Selectors &#8211; Advanced CSS Selectors &#8211; Part 4</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS Combinators &#8211; Advanced CSS Selectors &#8211; Part 3</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-combinators-advanced-css-selectors-part-3/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Thu, 02 May 2019 14:58:31 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[combinators]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3830</guid>

					<description><![CDATA[<p>Learn how to use CSS combinators to combine CSS selectors for more flexible and precise selection of HTML elements for styling.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-combinators-advanced-css-selectors-part-3/">CSS Combinators &#8211; Advanced CSS Selectors &#8211; Part 3</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>In the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">previous tutorial</a>, you have seen how to combine CSS selectors to precisely specify an HTML element for styling and the rules by which the <em>specificity</em> of a CSS selector is calculated.</p>
<p>You will learn about <strong>combinators</strong> for combining CSS selectors to more precisely select HTML elements for styling.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#child-combinator">Child Combinator</a></li>
<li><a href="#descendant-combinator">Descendant Combinator</a></li>
<li><a href="#next-sibling-combinator">Next Sibling Combinator</a></li>
<li><a href="#subsequent-sibling-combinator">Subsequent Sibling Combinator</a></li>
<li><a href="#closing-thoughts">Closing Thoughts</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="child-combinator">Child Combinator</h2>
<p>You were introduced to the <strong>Child Combinator</strong> in the first part of this series on <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/">Advanced CSS Selectors</a>:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb1-1" class="sourceLine" title="1"></a><span class="fu">.column-left</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb1-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">lightgreen</span><span class="op">;</span>
<a id="cb1-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The combinator <strong>&gt;</strong> (greater-than symbol<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a>) specifies a direct parent-child relationship.</p>
<p>In the example above, it selects an element with the class of <span class="css-class">.headline</span> only if it is an immediate child of an element with the class of <span class="css-class">.card</span> AND the element with the class of <span class="css-class">.card</span> is an immediate child of an element with the class of <span class="css-class">.column-left</span>.</p>
<p>It has a <em>specificity</em> of 0:3:0.</p>
<p>Consider the following HTML code and the selector declared above:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb2-1" class="sourceLine" title="1"></a><span class="co">&lt;!--</span>
<a id="cb2-2" class="sourceLine" title="2"></a><span class="co">  The &lt;p&gt; tag will be selected because the</span>
<a id="cb2-3" class="sourceLine" title="3"></a><span class="co">  parent-child relationships match the selector.</span>
<a id="cb2-4" class="sourceLine" title="4"></a>
<a id="cb2-5" class="sourceLine" title="5"></a><span class="co">  You could also use the selector:</span>
<a id="cb2-6" class="sourceLine" title="6"></a>
<a id="cb2-7" class="sourceLine" title="7"></a><span class="co">  div &gt; div &gt; p</span>
<a id="cb2-8" class="sourceLine" title="8"></a>
<a id="cb2-9" class="sourceLine" title="9"></a><span class="co">  That selector has a specificity of 0:0:3</span>
<a id="cb2-10" class="sourceLine" title="10"></a><span class="co">--&gt;</span>
<a id="cb2-11" class="sourceLine" title="11"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb2-12" class="sourceLine" title="12"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb2-13" class="sourceLine" title="13"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>A Headline<span class="kw">&lt;/p&gt;</span>
<a id="cb2-14" class="sourceLine" title="14"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-15" class="sourceLine" title="15"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb2-16" class="sourceLine" title="16"></a>
<a id="cb2-17" class="sourceLine" title="17"></a><span class="co">&lt;!--</span>
<a id="cb2-18" class="sourceLine" title="18"></a><span class="co">  The &lt;p&gt; tag will NOT be selected because the</span>
<a id="cb2-19" class="sourceLine" title="19"></a><span class="co">  parent-child relationships do not match the</span>
<a id="cb2-20" class="sourceLine" title="20"></a><span class="co">  selector</span>
<a id="cb2-21" class="sourceLine" title="21"></a>
<a id="cb2-22" class="sourceLine" title="22"></a><span class="co">  To select the &lt;p&gt; tag, the selector could be:</span>
<a id="cb2-23" class="sourceLine" title="23"></a>
<a id="cb2-24" class="sourceLine" title="24"></a><span class="co">  .column-left  &gt; div &gt; .headline</span>
<a id="cb2-25" class="sourceLine" title="25"></a>
<a id="cb2-26" class="sourceLine" title="26"></a><span class="co">  That selector has a specificity of 0:2:1</span>
<a id="cb2-27" class="sourceLine" title="27"></a><span class="co">--&gt;</span>
<a id="cb2-28" class="sourceLine" title="28"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb2-29" class="sourceLine" title="29"></a>  <span class="kw">&lt;div&gt;</span>
<a id="cb2-30" class="sourceLine" title="30"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>A Headline<span class="kw">&lt;/p&gt;</span>
<a id="cb2-31" class="sourceLine" title="31"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-32" class="sourceLine" title="32"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb2-33" class="sourceLine" title="33"></a>
<a id="cb2-34" class="sourceLine" title="34"></a><span class="co">&lt;!--</span>
<a id="cb2-35" class="sourceLine" title="35"></a><span class="co">  The &lt;p&gt; tag will NOT be selected because the</span>
<a id="cb2-36" class="sourceLine" title="36"></a><span class="co">  parent-child relationships do not match the</span>
<a id="cb2-37" class="sourceLine" title="37"></a><span class="co">  selector.</span>
<a id="cb2-38" class="sourceLine" title="38"></a>
<a id="cb2-39" class="sourceLine" title="39"></a><span class="co">  To select the &lt;p&gt; tag, the selector could be:</span>
<a id="cb2-40" class="sourceLine" title="40"></a>
<a id="cb2-41" class="sourceLine" title="41"></a><span class="co">  .card &gt; .column-left  &gt; .headline</span>
<a id="cb2-42" class="sourceLine" title="42"></a>
<a id="cb2-43" class="sourceLine" title="43"></a><span class="co">  That selector has a specificity of 0:3:0</span>
<a id="cb2-44" class="sourceLine" title="44"></a><span class="co">--&gt;</span>
<a id="cb2-45" class="sourceLine" title="45"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb2-46" class="sourceLine" title="46"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb2-47" class="sourceLine" title="47"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>A Headline<span class="kw">&lt;/p&gt;</span>
<a id="cb2-48" class="sourceLine" title="48"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-49" class="sourceLine" title="49"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb2-50" class="sourceLine" title="50"></a>
<a id="cb2-51" class="sourceLine" title="51"></a><span class="co">&lt;!--</span>
<a id="cb2-52" class="sourceLine" title="52"></a><span class="co">  The &lt;p&gt; tag WILL be selected because the</span>
<a id="cb2-53" class="sourceLine" title="53"></a><span class="co">  parent-child relationships match the selector.</span>
<a id="cb2-54" class="sourceLine" title="54"></a>
<a id="cb2-55" class="sourceLine" title="55"></a><span class="co">  Both &lt;p&gt; tags are children of the parent with</span>
<a id="cb2-56" class="sourceLine" title="56"></a><span class="co">  the class .card. The position of the child</span>
<a id="cb2-57" class="sourceLine" title="57"></a><span class="co">  within the parent doesn't affect its selection.</span>
<a id="cb2-58" class="sourceLine" title="58"></a><span class="co">  All that matters is that it is a direct child.</span>
<a id="cb2-59" class="sourceLine" title="59"></a><span class="co">--&gt;</span>
<a id="cb2-60" class="sourceLine" title="60"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb2-61" class="sourceLine" title="61"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb2-62" class="sourceLine" title="62"></a>    <span class="kw">&lt;p&gt;</span>Some random text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-63" class="sourceLine" title="63"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>A Headline<span class="kw">&lt;/p&gt;</span>
<a id="cb2-64" class="sourceLine" title="64"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-65" class="sourceLine" title="65"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb2-66" class="sourceLine" title="66"></a>
<a id="cb2-67" class="sourceLine" title="67"></a><span class="co">&lt;!--</span>
<a id="cb2-68" class="sourceLine" title="68"></a><span class="co">  The &lt;p&gt; tag will NOT be selected because the</span>
<a id="cb2-69" class="sourceLine" title="69"></a><span class="co">  parent-child relationships do not match the</span>
<a id="cb2-70" class="sourceLine" title="70"></a><span class="co">  selector.</span>
<a id="cb2-71" class="sourceLine" title="71"></a>
<a id="cb2-72" class="sourceLine" title="72"></a><span class="co">  To select the &lt;p&gt; tag, the selector could be:</span>
<a id="cb2-73" class="sourceLine" title="73"></a>
<a id="cb2-74" class="sourceLine" title="74"></a><span class="co">  .column-left &gt; .card &gt; div &gt; .headline</span>
<a id="cb2-75" class="sourceLine" title="75"></a>
<a id="cb2-76" class="sourceLine" title="76"></a><span class="co">  That selector has a specificity of 0:3:1</span>
<a id="cb2-77" class="sourceLine" title="77"></a>
<a id="cb2-78" class="sourceLine" title="78"></a><span class="co">  It could also be:</span>
<a id="cb2-79" class="sourceLine" title="79"></a>
<a id="cb2-80" class="sourceLine" title="80"></a><span class="co">  div &gt; div &gt; div &gt; p</span>
<a id="cb2-81" class="sourceLine" title="81"></a>
<a id="cb2-82" class="sourceLine" title="82"></a><span class="co">  That selector has a specificity of 0:0:4</span>
<a id="cb2-83" class="sourceLine" title="83"></a><span class="co">--&gt;</span>
<a id="cb2-84" class="sourceLine" title="84"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb2-85" class="sourceLine" title="85"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb2-86" class="sourceLine" title="86"></a>    <span class="kw">&lt;div&gt;</span>
<a id="cb2-87" class="sourceLine" title="87"></a>      <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>A Headline<span class="kw">&lt;/p&gt;</span>
<a id="cb2-88" class="sourceLine" title="88"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb2-89" class="sourceLine" title="89"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-90" class="sourceLine" title="90"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>While I wrote the selector with a space around the combinator, there is no need for that. The following child selectors are also valid:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" title="1"></a><span class="fu">.column-left</span><span class="op">&gt;</span><span class="fu">.card.</span><span class="op">&gt;</span><span class="fu">.headline</span> {
<a id="cb3-2" class="sourceLine" title="2"></a>
<a id="cb3-3" class="sourceLine" title="3"></a>}
<a id="cb3-4" class="sourceLine" title="4"></a>
<a id="cb3-5" class="sourceLine" title="5"></a>div<span class="op">&gt;</span>div<span class="op">&gt;</span>p {
<a id="cb3-6" class="sourceLine" title="6"></a>
<a id="cb3-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<p>While the direct selection method discussed in the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">previous tutorial</a> can never have an <span class="css-id">#ID</span> specificity greater than 1 (because an HTML element can never have more than 1 ID associated with it), with combinators, it is possible to have an <span class="css-id">#ID</span> specificity greater than 1. Consider the following (based on the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">More Advanced float Example</a>):</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb4-1" class="sourceLine" title="1"></a><span class="pp">#wrapper</span> <span class="op">&gt;</span> <span class="pp">#title</span> {
<a id="cb4-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity = 2:0:0 */</span>
<a id="cb4-3" class="sourceLine" title="3"></a>}
<a id="cb4-4" class="sourceLine" title="4"></a>
<a id="cb4-5" class="sourceLine" title="5"></a><span class="pp">#wrapper</span> <span class="op">&gt;</span> <span class="pp">#navbar</span> {
<a id="cb4-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity = 2:0:0 */</span>
<a id="cb4-7" class="sourceLine" title="7"></a>}
<a id="cb4-8" class="sourceLine" title="8"></a>
<a id="cb4-9" class="sourceLine" title="9"></a><span class="pp">#wrapper</span> <span class="op">&gt;</span> <span class="pp">#content</span> <span class="op">&gt;</span> <span class="fu">.column-left</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb4-10" class="sourceLine" title="10"></a>  <span class="co">/* specificity = 2:3:0 */</span>
<a id="cb4-11" class="sourceLine" title="11"></a>}</code></pre>
</div>
<h2 id="descendant-combinator">Descendant Combinator</h2>
<p>This is the most commonly used combinator.</p>
<p>The <strong>descendant combinator</strong> is more general than the <strong>child combinator</strong> and is useful for styling different sections of your document without having to specify the <strong>exact</strong> parent-child relationships.</p>
<p>As you recall, when you create your HTML page, <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided/">you <span class="html-tag">div</span>ide the page into various sections</a>. Common sections include:</p>
<ul class="incremental">
<li>Header</li>
<li>Navigation Bar</li>
<li>Main Body</li>
<li>Side Bar</li>
<li>Footer</li>
</ul>
<p>You might like to have common styles within a section, but not have to specify the exact relationship for every element in a section, but give a more general <em>“all <span class="html-tag">p</span> tags in the Main Body, regardless of how the main body is subdivided, have the following styling”</em>.</p>
<p>Consider the clone page <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">created in an earlier lesson</a>, it had a <span class="css-id">#content</span> section that contained three columns:</p>
<p>You can style ALL <span class="html-tag">p</span> elements in the document using:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb5-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb5-2" class="sourceLine" title="2"></a><span class="co">  applies to all &lt;p&gt; tags, unless</span>
<a id="cb5-3" class="sourceLine" title="3"></a><span class="co">  overridden by a more specific selector</span>
<a id="cb5-4" class="sourceLine" title="4"></a><span class="co">*/</span>
<a id="cb5-5" class="sourceLine" title="5"></a>p {
<a id="cb5-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity = 0:0:1 */</span>
<a id="cb5-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<p>You can also style all <span class="html-tag">p</span> elements that are immediate children of the <span class="css-id">#content</span> section using the <strong>child combinator</strong>:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb6-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb6-2" class="sourceLine" title="2"></a><span class="co">  Only applies to &lt;p&gt; elements that are</span>
<a id="cb6-3" class="sourceLine" title="3"></a><span class="co">  immediate children of a #content element,</span>
<a id="cb6-4" class="sourceLine" title="4"></a><span class="co">*/</span>
<a id="cb6-5" class="sourceLine" title="5"></a><span class="pp">#content</span> <span class="op">&gt;</span> p {
<a id="cb6-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity = 1:0:1 */</span>  
<a id="cb6-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<p>But the <strong>child combinator</strong> will not select <span class="html-tag">p</span> elements if they are nested deeper:</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb7-1" class="sourceLine" title="1"></a>
<a id="cb7-2" class="sourceLine" title="2"></a><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"content"</span><span class="kw">&gt;</span>
<a id="cb7-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;p&gt;</span>This will be selected.<span class="kw">&lt;/p&gt;</span>
<a id="cb7-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"aside"</span><span class="kw">&gt;</span>
<a id="cb7-5" class="sourceLine" title="5"></a>    <span class="kw">&lt;p&gt;</span>This will NOT be selected<span class="kw">&lt;/p&gt;</span>
<a id="cb7-6" class="sourceLine" title="6"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb7-7" class="sourceLine" title="7"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <strong>descendant combinator</strong> allows you to create a selector for ALL <span class="html-tag">p</span> elements located inside a <span class="css-id">#content</span> container &#8211; you can select immediate children, grandchildren and more deeply nested elements. The <strong>descendant combinator</strong> is a space character:<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb8-2" class="sourceLine" title="2"></a><span class="co">  The descendant combinator is the space character.</span>
<a id="cb8-3" class="sourceLine" title="3"></a><span class="co">*/</span>
<a id="cb8-4" class="sourceLine" title="4"></a><span class="pp">#content</span> p {
<a id="cb8-5" class="sourceLine" title="5"></a>  <span class="co">/* specificity = 1:0:1 */</span>  
<a id="cb8-6" class="sourceLine" title="6"></a>}
<a id="cb8-7" class="sourceLine" title="7"></a>
<a id="cb8-8" class="sourceLine" title="8"></a><span class="co">/*</span>
<a id="cb8-9" class="sourceLine" title="9"></a><span class="co">  The space character acts as a descendant combinator</span>
<a id="cb8-10" class="sourceLine" title="10"></a><span class="co">  when it is alone. If you write a child combinator</span>
<a id="cb8-11" class="sourceLine" title="11"></a><span class="co">  with spaces it is a child combinator, not a</span>
<a id="cb8-12" class="sourceLine" title="12"></a><span class="co">  child + descendant combinator.</span>
<a id="cb8-13" class="sourceLine" title="13"></a><span class="co">*/</span>
<a id="cb8-14" class="sourceLine" title="14"></a><span class="pp">#content</span> <span class="op">&gt;</span> p {
<a id="cb8-15" class="sourceLine" title="15"></a>  <span class="co">/* specificity = 1:0:1 */</span>
<a id="cb8-16" class="sourceLine" title="16"></a>}</code></pre>
</div>
<p>This top selector will select <strong>all</strong> the <span class="html-tag">p</span> elements in the HTML example above, but if they are located anywhere inside a block with an ID of <span class="css-id">#content</span>.</p>
<p>The bottom selector will <strong>only</strong> select those the <span class="html-tag">p</span> elements which are immediate children of a block with an ID of <span class="css-id">#content</span>.</p>
<p>This is useful for defining styles that are localized to particular sections of your webpage without having to rigidly follow the structure of your page:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb9-1" class="sourceLine" title="1"></a><span class="pp">#header</span> p {
<a id="cb9-2" class="sourceLine" title="2"></a>  <span class="co">/*</span>
<a id="cb9-3" class="sourceLine" title="3"></a><span class="co">    applies to all &lt;p&gt; tags inside #header</span>
<a id="cb9-4" class="sourceLine" title="4"></a><span class="co">    specificity = 1:0:1</span>
<a id="cb9-5" class="sourceLine" title="5"></a><span class="co">  */</span>
<a id="cb9-6" class="sourceLine" title="6"></a>}
<a id="cb9-7" class="sourceLine" title="7"></a>
<a id="cb9-8" class="sourceLine" title="8"></a><span class="pp">#navbar</span> a{
<a id="cb9-9" class="sourceLine" title="9"></a>  <span class="co">/*</span>
<a id="cb9-10" class="sourceLine" title="10"></a><span class="co">    applies to all links inside #navbar</span>
<a id="cb9-11" class="sourceLine" title="11"></a><span class="co">    specificity = 1:0:1</span>
<a id="cb9-12" class="sourceLine" title="12"></a><span class="co">  */</span>
<a id="cb9-13" class="sourceLine" title="13"></a>}
<a id="cb9-14" class="sourceLine" title="14"></a>
<a id="cb9-15" class="sourceLine" title="15"></a><span class="pp">#content</span> <span class="fu">.sidebar</span> img {
<a id="cb9-16" class="sourceLine" title="16"></a>  <span class="co">/*</span>
<a id="cb9-17" class="sourceLine" title="17"></a><span class="co">    applies to all images located anywhere</span>
<a id="cb9-18" class="sourceLine" title="18"></a><span class="co">    inside .sidebar, when .sidebar is</span>
<a id="cb9-19" class="sourceLine" title="19"></a><span class="co">    located anywhere inside #content</span>
<a id="cb9-20" class="sourceLine" title="20"></a><span class="co">    specificity = 1:1:1</span>
<a id="cb9-21" class="sourceLine" title="21"></a><span class="co">  */</span>
<a id="cb9-22" class="sourceLine" title="22"></a>}
<a id="cb9-23" class="sourceLine" title="23"></a>
<a id="cb9-24" class="sourceLine" title="24"></a><span class="pp">#content</span> <span class="fu">.aside</span> <span class="op">&gt;</span> img {
<a id="cb9-25" class="sourceLine" title="25"></a>  <span class="co">/*</span>
<a id="cb9-26" class="sourceLine" title="26"></a><span class="co">    applies to images inside #content that</span>
<a id="cb9-27" class="sourceLine" title="27"></a><span class="co">    are direct children of .aside</span>
<a id="cb9-28" class="sourceLine" title="28"></a><span class="co">    specificity = 1:1:1</span>
<a id="cb9-29" class="sourceLine" title="29"></a><span class="co">  */</span>
<a id="cb9-30" class="sourceLine" title="30"></a>}
<a id="cb9-31" class="sourceLine" title="31"></a>
<a id="cb9-32" class="sourceLine" title="32"></a><span class="pp">#footer</span> img {
<a id="cb9-33" class="sourceLine" title="33"></a>  <span class="co">/*</span>
<a id="cb9-34" class="sourceLine" title="34"></a><span class="co">    applies to all images inside #footer</span>
<a id="cb9-35" class="sourceLine" title="35"></a><span class="co">    specificity = 1:0:1</span>
<a id="cb9-36" class="sourceLine" title="36"></a><span class="co">  */</span>
<a id="cb9-37" class="sourceLine" title="37"></a>}</code></pre>
</div>
<p>Remember to pay attention to the <em>specificity</em> of your selector:</p>
<div id="cb10" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb10-1" class="sourceLine" title="1"></a><span class="pp">#content</span> p {
<a id="cb10-2" class="sourceLine" title="2"></a>  <span class="co">/* specificity 1:0:1 */</span>
<a id="cb10-3" class="sourceLine" title="3"></a>}
<a id="cb10-4" class="sourceLine" title="4"></a>
<a id="cb10-5" class="sourceLine" title="5"></a><span class="fu">.aside</span> <span class="op">&gt;</span> p {
<a id="cb10-6" class="sourceLine" title="6"></a>  <span class="co">/* specificity 0:1:1 */</span>
<a id="cb10-7" class="sourceLine" title="7"></a>}
<a id="cb10-8" class="sourceLine" title="8"></a>
<a id="cb10-9" class="sourceLine" title="9"></a><span class="co">/*</span>
<a id="cb10-10" class="sourceLine" title="10"></a><span class="co">  Even though the bottom selector looks more "specific"</span>
<a id="cb10-11" class="sourceLine" title="11"></a><span class="co">  than the top selector, because the top selector says</span>
<a id="cb10-12" class="sourceLine" title="12"></a><span class="co">  "select any &lt;p&gt; found anywhere inside #content" and</span>
<a id="cb10-13" class="sourceLine" title="13"></a><span class="co">  the bottom selector says "only select &lt;p&gt; if it is</span>
<a id="cb10-14" class="sourceLine" title="14"></a><span class="co">  an immediate child of .aside".</span>
<a id="cb10-15" class="sourceLine" title="15"></a>
<a id="cb10-16" class="sourceLine" title="16"></a><span class="co">  However, the calculated specificity of the top selector</span>
<a id="cb10-17" class="sourceLine" title="17"></a><span class="co">  is greater than the specificity of the bottom selector.</span>
<a id="cb10-18" class="sourceLine" title="18"></a><span class="co">*/</span></code></pre>
</div>
<h2 id="next-sibling-combinator">Next Sibling Combinator</h2>
<p>This is also known as the <strong>first sibling combinator</strong> and <strong>adjacent sibling combinator</strong>.</p>
<p>The first two combinators allow you to select HTML elements based on how they are contained within other HTML elements &#8211; either as children, grandchildren, great-grandchildren, etc.</p>
<p>The <strong>next sibling combinator</strong> allows you to select HTML elements in relation to other elements at the same nesting level. Consider the following:</p>
<div id="cb11" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb11-1" class="sourceLine" title="1"></a><span class="co">&lt;!-- This is a parent element --&gt;</span>
<a id="cb11-2" class="sourceLine" title="2"></a><span class="kw">&lt;div&gt;</span>
<a id="cb11-3" class="sourceLine" title="3"></a>  <span class="co">&lt;!--</span>
<a id="cb11-4" class="sourceLine" title="4"></a><span class="co">    The &lt;h1&gt;, &lt;p&gt;, &lt;p&gt;, &lt;ol&gt;, &lt;img&gt;, and &lt;p&gt;</span>
<a id="cb11-5" class="sourceLine" title="5"></a><span class="co">    are siblings and children of &lt;div&gt;</span>
<a id="cb11-6" class="sourceLine" title="6"></a><span class="co">  --&gt;</span>
<a id="cb11-7" class="sourceLine" title="7"></a>  <span class="kw">&lt;h1&gt;</span>A Header<span class="kw">&lt;/h1&gt;</span>
<a id="cb11-8" class="sourceLine" title="8"></a>  <span class="kw">&lt;p&gt;</span>A paragraph.<span class="kw">&lt;/p&gt;</span>
<a id="cb11-9" class="sourceLine" title="9"></a>  <span class="kw">&lt;p&gt;</span>Another paragraph<span class="kw">&lt;/p&gt;</span>
<a id="cb11-10" class="sourceLine" title="10"></a>  <span class="co">&lt;!--</span>
<a id="cb11-11" class="sourceLine" title="11"></a><span class="co">    While &lt;ol&gt; is a child of &lt;div&gt; and a sibling</span>
<a id="cb11-12" class="sourceLine" title="12"></a><span class="co">    to &lt;h1&gt;, &lt;p&gt;, &lt;p&gt;, &lt;img&gt;, and &lt;p&gt;, it is also</span>
<a id="cb11-13" class="sourceLine" title="13"></a><span class="co">    the parent of the &lt;li&gt; elements.</span>
<a id="cb11-14" class="sourceLine" title="14"></a><span class="co">  --&gt;</span>
<a id="cb11-15" class="sourceLine" title="15"></a>  <span class="kw">&lt;ol&gt;</span>
<a id="cb11-16" class="sourceLine" title="16"></a>    <span class="co">&lt;!-- All the &lt;li&gt; elements are siblings --&gt;</span>
<a id="cb11-17" class="sourceLine" title="17"></a>    <span class="kw">&lt;li&gt;</span>Item 1<span class="kw">&lt;/li&gt;</span>
<a id="cb11-18" class="sourceLine" title="18"></a>    <span class="kw">&lt;li&gt;</span>Item 2<span class="kw">&lt;/li&gt;</span>
<a id="cb11-19" class="sourceLine" title="19"></a>    <span class="kw">&lt;li&gt;</span>Item 3<span class="kw">&lt;/li&gt;</span>
<a id="cb11-20" class="sourceLine" title="20"></a>  <span class="kw">&lt;/ol&gt;</span>
<a id="cb11-21" class="sourceLine" title="21"></a>  <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"/valid/image.jpg"</span><span class="kw">&gt;</span>
<a id="cb11-22" class="sourceLine" title="22"></a>  <span class="kw">&lt;p&gt;</span>Maybe a caption?<span class="kw">&lt;/p&gt;</span>
<a id="cb11-23" class="sourceLine" title="23"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Consider the following rules using the <strong>next sibling combinator</strong> (which is the plus ‘+’ symbol):</p>
<div id="cb12" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb12-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb12-2" class="sourceLine" title="2"></a><span class="co">  Select a &lt;p&gt; element if it immediately follows</span>
<a id="cb12-3" class="sourceLine" title="3"></a><span class="co">  an &lt;h1&gt; element.</span>
<a id="cb12-4" class="sourceLine" title="4"></a>
<a id="cb12-5" class="sourceLine" title="5"></a><span class="co">  You might want the first paragraph following</span>
<a id="cb12-6" class="sourceLine" title="6"></a><span class="co">  &lt;h1&gt; to be special in some way - perhaps a</span>
<a id="cb12-7" class="sourceLine" title="7"></a><span class="co">  slightly larger font or italicized. This could</span>
<a id="cb12-8" class="sourceLine" title="8"></a><span class="co">  also be done by applying a class to the first</span>
<a id="cb12-9" class="sourceLine" title="9"></a><span class="co">  &lt;p&gt; element.</span>
<a id="cb12-10" class="sourceLine" title="10"></a><span class="co">*/</span>
<a id="cb12-11" class="sourceLine" title="11"></a>h1 <span class="op">+</span> p {
<a id="cb12-12" class="sourceLine" title="12"></a>  <span class="co">/* specificity = 0:0:2 */</span>
<a id="cb12-13" class="sourceLine" title="13"></a>}
<a id="cb12-14" class="sourceLine" title="14"></a>
<a id="cb12-15" class="sourceLine" title="15"></a><span class="co">/*</span>
<a id="cb12-16" class="sourceLine" title="16"></a><span class="co">  Select a &lt;p&gt; element if it immediately follows</span>
<a id="cb12-17" class="sourceLine" title="17"></a><span class="co">  an &lt;img&gt; element.</span>
<a id="cb12-18" class="sourceLine" title="18"></a>
<a id="cb12-19" class="sourceLine" title="19"></a><span class="co">  You might use the convention that each image</span>
<a id="cb12-20" class="sourceLine" title="20"></a><span class="co">  in your documents must be followed by a caption.</span>
<a id="cb12-21" class="sourceLine" title="21"></a><span class="co">  You could also apply a class (like .caption) to</span>
<a id="cb12-22" class="sourceLine" title="22"></a><span class="co">  the &lt;p&gt; element instead.</span>
<a id="cb12-23" class="sourceLine" title="23"></a><span class="co">*/</span>
<a id="cb12-24" class="sourceLine" title="24"></a>img p {
<a id="cb12-25" class="sourceLine" title="25"></a>  <span class="co">/* specificity = 0:0:2 */</span>
<a id="cb12-26" class="sourceLine" title="26"></a>}
<a id="cb12-27" class="sourceLine" title="27"></a>
<a id="cb12-28" class="sourceLine" title="28"></a><span class="co">/*</span>
<a id="cb12-29" class="sourceLine" title="29"></a><span class="co">  Select an &lt;li&gt; element if it immediately follows</span>
<a id="cb12-30" class="sourceLine" title="30"></a><span class="co">  an &lt;li&gt; element.</span>
<a id="cb12-31" class="sourceLine" title="31"></a>
<a id="cb12-32" class="sourceLine" title="32"></a><span class="co">  Applied to the HTML code above, it will</span>
<a id="cb12-33" class="sourceLine" title="33"></a><span class="co">  select the &lt;li&gt;s containing 'Item 2' and</span>
<a id="cb12-34" class="sourceLine" title="34"></a><span class="co">  'Item 3' - this is because:</span>
<a id="cb12-35" class="sourceLine" title="35"></a><span class="co">  - &lt;li&gt;Item 1&lt;/li&gt; is the first li in the</span>
<a id="cb12-36" class="sourceLine" title="36"></a><span class="co">    rule and &lt;li&gt;Item 2&lt;/li&gt; is the second</span>
<a id="cb12-37" class="sourceLine" title="37"></a><span class="co">    li in the rule - the one that is</span>
<a id="cb12-38" class="sourceLine" title="38"></a><span class="co">    selected.</span>
<a id="cb12-39" class="sourceLine" title="39"></a><span class="co">  - then &lt;li&gt;Item 2&lt;/li&gt; is the first li in</span>
<a id="cb12-40" class="sourceLine" title="40"></a><span class="co">    the rule and &lt;li&gt;Item 3&lt;/li&gt; is the second</span>
<a id="cb12-41" class="sourceLine" title="41"></a><span class="co">    li in the rule - the one that is</span>
<a id="cb12-42" class="sourceLine" title="42"></a><span class="co">    selected.</span>
<a id="cb12-43" class="sourceLine" title="43"></a><span class="co">  - when &lt;li&gt;Item 3&lt;/li&gt; is evaluated as the</span>
<a id="cb12-44" class="sourceLine" title="44"></a><span class="co">    first li in the rule, because there is</span>
<a id="cb12-45" class="sourceLine" title="45"></a><span class="co">    no subsequent li, this selector isn't</span>
<a id="cb12-46" class="sourceLine" title="46"></a><span class="co">    applied to anything.</span>
<a id="cb12-47" class="sourceLine" title="47"></a><span class="co">*/</span>
<a id="cb12-48" class="sourceLine" title="48"></a>
<a id="cb12-49" class="sourceLine" title="49"></a>li <span class="op">+</span> li {
<a id="cb12-50" class="sourceLine" title="50"></a>  <span class="co">/* specificity = 0:0:2 */</span>
<a id="cb12-51" class="sourceLine" title="51"></a>}</code></pre>
</div>
<p>Let’s apply these selectors to the HTML code above:</p>
<div id="cb13" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb13-1" class="sourceLine" title="1"></a>h1 <span class="op">+</span> p {
<a id="cb13-2" class="sourceLine" title="2"></a>  <span class="kw">font-size</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span>
<a id="cb13-3" class="sourceLine" title="3"></a>  <span class="kw">font-style</span>: <span class="dv">italic</span><span class="op">;</span>
<a id="cb13-4" class="sourceLine" title="4"></a>}
<a id="cb13-5" class="sourceLine" title="5"></a>
<a id="cb13-6" class="sourceLine" title="6"></a>img <span class="op">+</span> p {
<a id="cb13-7" class="sourceLine" title="7"></a>  <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb13-8" class="sourceLine" title="8"></a>  <span class="kw">text-align</span>: <span class="dv">center</span><span class="op">;</span>
<a id="cb13-9" class="sourceLine" title="9"></a>}
<a id="cb13-10" class="sourceLine" title="10"></a>
<a id="cb13-11" class="sourceLine" title="11"></a><span class="co">/*</span>
<a id="cb13-12" class="sourceLine" title="12"></a><span class="co">  Remove the yellow background from all list</span>
<a id="cb13-13" class="sourceLine" title="13"></a><span class="co">  items, except the first one.</span>
<a id="cb13-14" class="sourceLine" title="14"></a><span class="co">*/</span>
<a id="cb13-15" class="sourceLine" title="15"></a>li <span class="op">+</span> li {
<a id="cb13-16" class="sourceLine" title="16"></a><span class="kw">background-color</span>: <span class="dv">transparent</span><span class="op">;</span>
<a id="cb13-17" class="sourceLine" title="17"></a>}
<a id="cb13-18" class="sourceLine" title="18"></a>
<a id="cb13-19" class="sourceLine" title="19"></a><span class="co">/*</span>
<a id="cb13-20" class="sourceLine" title="20"></a><span class="co">  Select all list items and set the</span>
<a id="cb13-21" class="sourceLine" title="21"></a><span class="co">  background to yellow.</span>
<a id="cb13-22" class="sourceLine" title="22"></a>
<a id="cb13-23" class="sourceLine" title="23"></a><span class="co">  I'm putting this rule here to demonstrate</span>
<a id="cb13-24" class="sourceLine" title="24"></a><span class="co">  selector specificity.</span>
<a id="cb13-25" class="sourceLine" title="25"></a><span class="co">*/</span>
<a id="cb13-26" class="sourceLine" title="26"></a>li {
<a id="cb13-27" class="sourceLine" title="27"></a>  <span class="kw">background-color</span>: <span class="cn">yellow</span><span class="op">;</span>
<a id="cb13-28" class="sourceLine" title="28"></a>}</code></pre>
</div>
<p>Results in the following output:</p>
<div class="html-output">
<style>
h1.x39 + p.x39 {font-size: 20px;  font-style: italic;}p.x39f + p.x39 { font-weight: bold;  text-align: center;}li.x39 + li.x39 {background-color: transparent;}li.x39 {  background-color: yellow;}</style>
<div class="x39">
<h1 class="x39">A Header</h1>
<p class="x39">A paragraph.</p>
<p class="x39">Another paragraph</p>
<ol class="x39">
<li class="x39">Item 1</li>
<li class="x39">Item 2</li>
<li class="x39">Item 3</li>
</ol>
<p class="x39f"><img decoding="async" class="x39" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg" /></p>
<p class="x39">Maybe a caption?</p>
</div>
</div>
<h2 id="subsequent-sibling-combinator">Subsequent Sibling Combinator</h2>
<p>This is also known as the <strong>general sibling combinator</strong> and <strong>following sibling combinator</strong><a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a>.</p>
<p>It is similar to the <strong>next sibling combinator</strong> in specifying the relationship between child elements, except that:</p>
<ol class="incremental" type="1">
<li>the selected element does not need to be adjacent to the first element</li>
<li>it selects ALL subsequent elements that match</li>
</ol>
<p>The combinator is the tilde (<strong>~</strong>) symbol.</p>
<p>Consider:</p>
<div id="cb14" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb14-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb14-2" class="sourceLine" title="2"></a><span class="co">  Select all &lt;p&gt; elements following an &lt;h1&gt;</span>
<a id="cb14-3" class="sourceLine" title="3"></a><span class="co">  element as long as the &lt;p&gt; elements are</span>
<a id="cb14-4" class="sourceLine" title="4"></a><span class="co">  all siblings with the &lt;h1&gt; element.</span>
<a id="cb14-5" class="sourceLine" title="5"></a><span class="co">*/</span>
<a id="cb14-6" class="sourceLine" title="6"></a>h1<span class="fu">.important</span> <span class="op">~</span> p {
<a id="cb14-7" class="sourceLine" title="7"></a>  <span class="co">/* specificity = 0:1:2 */</span>
<a id="cb14-8" class="sourceLine" title="8"></a>  <span class="kw">background-color</span>: <span class="cn">yellow</span><span class="op">;</span>
<a id="cb14-9" class="sourceLine" title="9"></a>}</code></pre>
</div>
<p>When applied to the following code:</p>
<div id="cb15" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb15-1" class="sourceLine" title="1"></a><span class="kw">&lt;p&gt;</span>This is a paragraph.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-2" class="sourceLine" title="2"></a><span class="kw">&lt;p&gt;</span>So is this.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-3" class="sourceLine" title="3"></a><span class="kw">&lt;h1</span><span class="ot"> class=</span><span class="st">"important"</span><span class="kw">&gt;</span>This is important!<span class="kw">&lt;/h1&gt;</span>
<a id="cb15-4" class="sourceLine" title="4"></a><span class="kw">&lt;p&gt;</span>This paragraph is selected.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-5" class="sourceLine" title="5"></a><span class="kw">&lt;p&gt;</span>So is this one.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-6" class="sourceLine" title="6"></a><span class="kw">&lt;div&gt;</span>
<a id="cb15-7" class="sourceLine" title="7"></a>  <span class="kw">&lt;p&gt;</span>These paragraphs are not selected.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-8" class="sourceLine" title="8"></a>  <span class="kw">&lt;p&gt;</span>Because they are not siblings.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-9" class="sourceLine" title="9"></a>  <span class="kw">&lt;p&gt;</span>They are nested inside a div.<span class="kw">&lt;/p&gt;</span>
<a id="cb15-10" class="sourceLine" title="10"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb15-11" class="sourceLine" title="11"></a><span class="kw">&lt;p&gt;</span>But this paragraph is selected.<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Results in the following:</p>
<div class="html-output">
<style>
h1.important.x39a ~ p.x39a {  background-color: yellow;}</style>
<p class="x39a">This is a paragraph.</p>
<p class="x39a">So is this.</p>
<h1 class="important x39a">This is important!</h1>
<p class="x39a">This paragraph is selected.</p>
<p class="x39a">So is this one.</p>
<div class="x39a">
<p class="x39a">These paragraphs are not selected.</p>
<p class="x39a">Because they are not siblings.</p>
<p class="x39a">They are nested inside a div.</p>
</div>
<p class="x39a">But this paragraph is selected.</p>
</div>
<h2 id="closing-thoughts">Closing Thoughts</h2>
<ol class="incremental" type="1">
<li>The four types of combinators allow you to combine various selectors to create selectors based on their relationships. This allows for more powerful selection.</li>
<li>The <strong>child combinator</strong> allows you to precisely specify the parent-child relationship of the elements:</li>
</ol>
<div id="cb16" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb16-1" class="sourceLine" title="1"></a>parent <span class="op">&gt;</span> child <span class="op">&gt;</span> grandchild {
<a id="cb16-2" class="sourceLine" title="2"></a>
<a id="cb16-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<ol class="incremental" start="3" type="1">
<li>The <strong>descendant combinator</strong> allows you to target elements based on whether they are nested inside other elements without caring about the specific details of the nesting:</li>
</ol>
<div id="cb17" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb17-1" class="sourceLine" title="1"></a>outer-element inner-element {
<a id="cb17-2" class="sourceLine" title="2"></a>
<a id="cb17-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<ol class="incremental" start="4" type="1">
<li>The <strong>next sibling combinator</strong> allows you to select an element if it immediately follows another element:</li>
</ol>
<div id="cb18" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb18-1" class="sourceLine" title="1"></a>first-element <span class="op">+</span> adjacent-element {
<a id="cb18-2" class="sourceLine" title="2"></a>
<a id="cb18-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<ol class="incremental" start="5" type="1">
<li>The <strong>subsequent sibling combinator</strong> allows you to select all elements that follow the first element &#8211; as long as they are siblings:</li>
</ol>
<div id="cb19" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb19-1" class="sourceLine" title="1"></a>key-element <span class="op">~</span> following-elements {
<a id="cb19-2" class="sourceLine" title="2"></a>
<a id="cb19-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<ol class="incremental" start="6" type="1">
<li>The combinators can be combined and you can more use more specific combinations of html elements, IDs, classes, and attributes:</li>
</ol>
<div id="cb20" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb20-1" class="sourceLine" title="1"></a>div<span class="pp">#main</span> <span class="op">&gt;</span> p<span class="fu">.important</span> <span class="op">+</span> <span class="ex">[reversed]</span> {
<a id="cb20-2" class="sourceLine" title="2"></a>
<a id="cb20-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<ol class="incremental" start="7" type="1">
<li>There is no combinator that allows you to select <strong>preceding</strong> elements:</li>
</ol>
<div id="cb21" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb21-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb21-2" class="sourceLine" title="2"></a><span class="co">  There is no select parent combinator.</span>
<a id="cb21-3" class="sourceLine" title="3"></a>
<a id="cb21-4" class="sourceLine" title="4"></a><span class="co">  For example, you cannot style the parent</span>
<a id="cb21-5" class="sourceLine" title="5"></a><span class="co">  based on the child tag.</span>
<a id="cb21-6" class="sourceLine" title="6"></a><span class="co">*/</span>
<a id="cb21-7" class="sourceLine" title="7"></a>div &lt; p {
<a id="cb21-8" class="sourceLine" title="8"></a>  <span class="co">/* This does NOT exist */</span>
<a id="cb21-9" class="sourceLine" title="9"></a>}
<a id="cb21-10" class="sourceLine" title="10"></a>
<a id="cb21-11" class="sourceLine" title="11"></a><span class="co">/*</span>
<a id="cb21-12" class="sourceLine" title="12"></a><span class="co">  There is NO preceding adjacent sibling</span>
<a id="cb21-13" class="sourceLine" title="13"></a><span class="co">  combinator.</span>
<a id="cb21-14" class="sourceLine" title="14"></a>
<a id="cb21-15" class="sourceLine" title="15"></a><span class="co">  For example, you could not select an &lt;h1&gt;</span>
<a id="cb21-16" class="sourceLine" title="16"></a><span class="co">  element that is followed by a &lt;p&gt; element</span>
<a id="cb21-17" class="sourceLine" title="17"></a><span class="co">*/</span>
<a id="cb21-18" class="sourceLine" title="18"></a>h1 &lt;<span class="op">+</span> p {
<a id="cb21-19" class="sourceLine" title="19"></a>  <span class="co">/* This does NOT exist */</span>
<a id="cb21-20" class="sourceLine" title="20"></a>}
<a id="cb21-21" class="sourceLine" title="21"></a>
<a id="cb21-22" class="sourceLine" title="22"></a><span class="co">/*</span>
<a id="cb21-23" class="sourceLine" title="23"></a><span class="co">  There is no preceding sibling combinator.</span>
<a id="cb21-24" class="sourceLine" title="24"></a>
<a id="cb21-25" class="sourceLine" title="25"></a><span class="co">  For example, you cannot select the &lt;p&gt;</span>
<a id="cb21-26" class="sourceLine" title="26"></a><span class="co">  elements that occur before an &lt;h1&gt; element.</span>
<a id="cb21-27" class="sourceLine" title="27"></a><span class="co">*/</span>
<a id="cb21-28" class="sourceLine" title="28"></a>h1 &lt;<span class="op">~</span> p {
<a id="cb21-29" class="sourceLine" title="29"></a>  <span class="co">/* This does NOT exist */</span>
<a id="cb21-30" class="sourceLine" title="30"></a>}
<a id="cb21-31" class="sourceLine" title="31"></a>
<a id="cb21-32" class="sourceLine" title="32"></a><span class="co">/*</span>
<a id="cb21-33" class="sourceLine" title="33"></a><span class="co">  There is no select antedent combinator.</span>
<a id="cb21-34" class="sourceLine" title="34"></a>
<a id="cb21-35" class="sourceLine" title="35"></a><span class="co">  For example, you cannot style an enclosing</span>
<a id="cb21-36" class="sourceLine" title="36"></a><span class="co">  element based on an enclosed element.</span>
<a id="cb21-37" class="sourceLine" title="37"></a><span class="co">*/</span>
<a id="cb21-38" class="sourceLine" title="38"></a><span class="pp">#main</span> &lt;&lt; <span class="fu">.some-deeply-embedded-element</span> {
<a id="cb21-39" class="sourceLine" title="39"></a>  <span class="co">/* This does NOT exist */</span>
<a id="cb21-40" class="sourceLine" title="40"></a>}</code></pre>
</div>
<ol class="incremental" start="8" type="1">
<li>While it may seem unfair to not allow selecting preceding elements or parents by their children or enclosing elements from interior elements, recall that the page is rendered from top to bottom. Rendering preceding elements would require rendering the page from bottom to top or from innermost elements to outermost elements and would make application of CSS rules far more complex regarding whether top-down, bottom-up, or inner-outer rules take precedence. As well, processing from the inner elements to the outer elements is computationally more expensive &#8211; making page renders slower.</li>
<li>You don’t need to use all combinators all the time. In fact, the <strong>descendant combinator</strong> is the most commonly used one. An analysis of 4632 CSS rules<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a> from 5 different websites<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a> revealed the following combinator distribution:<a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a>
<ul class="incremental">
<li>78.5% use the <strong>descendant combinator</strong></li>
<li>2.9% use the <strong>child combinator</strong></li>
<li>0.2% use the <strong>next sibling combinator</strong></li>
<li>0% use the <strong>subsequent sibling combinator</strong></li>
<li>18.4% are single item selector rules<a id="fnref8" class="footnote-ref" href="#fn8"><sup>8</sup></a></li>
</ul>
</li>
<li>To see some real world selector examples using combinators, consider the following from the <a href="https://github.com/WordPress/twentynineteen/blob/master/style.css">WordPress 2019 Theme</a>:<a id="fnref9" class="footnote-ref" href="#fn9"><sup>9</sup></a></li>
</ol>
<div id="cb22" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb22-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb22-2" class="sourceLine" title="2"></a><span class="co">  Styles an element with the class .comments-title</span>
<a id="cb22-3" class="sourceLine" title="3"></a><span class="co">  that immediately follows a sibling element with</span>
<a id="cb22-4" class="sourceLine" title="4"></a><span class="co">  an ID of #respond that is located at any level</span>
<a id="cb22-5" class="sourceLine" title="5"></a><span class="co">  inside a block with a class of .comment-form-flex.</span>
<a id="cb22-6" class="sourceLine" title="6"></a>
<a id="cb22-7" class="sourceLine" title="7"></a><span class="co">  specificity = 1:2:0</span>
<a id="cb22-8" class="sourceLine" title="8"></a><span class="co">*/</span>
<a id="cb22-9" class="sourceLine" title="9"></a><span class="fu">.comment-form-flex</span> <span class="pp">#respond</span> <span class="op">+</span> <span class="fu">.comments-title</span> {
<a id="cb22-10" class="sourceLine" title="10"></a>  <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb22-11" class="sourceLine" title="11"></a>}
<a id="cb22-12" class="sourceLine" title="12"></a>
<a id="cb22-13" class="sourceLine" title="13"></a><span class="co">/*</span>
<a id="cb22-14" class="sourceLine" title="14"></a><span class="co">  Styles all elements that are direct children of</span>
<a id="cb22-15" class="sourceLine" title="15"></a><span class="co">  a block with the class .comments-area.</span>
<a id="cb22-16" class="sourceLine" title="16"></a>
<a id="cb22-17" class="sourceLine" title="17"></a><span class="co">  You've seen calc() in the lesson</span>
<a id="cb22-18" class="sourceLine" title="18"></a><span class="co">  "CSS – How and When to Use Float".</span>
<a id="cb22-19" class="sourceLine" title="19"></a>
<a id="cb22-20" class="sourceLine" title="20"></a><span class="co">  'rem' will be covered in a future tutorial,</span>
<a id="cb22-21" class="sourceLine" title="21"></a><span class="co">  but it is a measurement unit like px or %.</span>
<a id="cb22-22" class="sourceLine" title="22"></a>
<a id="cb22-23" class="sourceLine" title="23"></a><span class="co">  specificity = 0:1:0</span>
<a id="cb22-24" class="sourceLine" title="24"></a><span class="co">*/</span>
<a id="cb22-25" class="sourceLine" title="25"></a><span class="fu">.comments-area</span> <span class="op">&gt;</span> <span class="op">*</span> {
<a id="cb22-26" class="sourceLine" title="26"></a>  <span class="kw">margin-top</span>: <span class="fu">calc(</span><span class="dv">2</span> <span class="op">*</span> <span class="dv">1</span><span class="dt">rem</span><span class="fu">)</span><span class="op">;</span>
<a id="cb22-27" class="sourceLine" title="27"></a>  <span class="kw">margin-bottom</span>: <span class="fu">calc(</span><span class="dv">2</span> <span class="op">*</span> <span class="dv">1</span><span class="dt">rem</span><span class="fu">)</span><span class="op">;</span>
<a id="cb22-28" class="sourceLine" title="28"></a>}
<a id="cb22-29" class="sourceLine" title="29"></a>
<a id="cb22-30" class="sourceLine" title="30"></a><span class="co">/*</span>
<a id="cb22-31" class="sourceLine" title="31"></a><span class="co">  Styles any &lt;img&gt; nested within the three classes</span>
<a id="cb22-32" class="sourceLine" title="32"></a><span class="co">  laid out below.</span>
<a id="cb22-33" class="sourceLine" title="33"></a>
<a id="cb22-34" class="sourceLine" title="34"></a><span class="co">  specificity = 0:3:1</span>
<a id="cb22-35" class="sourceLine" title="35"></a><span class="co">*/</span>
<a id="cb22-36" class="sourceLine" title="36"></a><span class="fu">.entry</span> <span class="fu">.post-thumbnail</span> <span class="fu">.post-thumbnail-inner</span> img {
<a id="cb22-37" class="sourceLine" title="37"></a>  <span class="kw">position</span>: <span class="dv">relative</span><span class="op">;</span>
<a id="cb22-38" class="sourceLine" title="38"></a>  <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb22-39" class="sourceLine" title="39"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb22-40" class="sourceLine" title="40"></a>}</code></pre>
</div>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://drafts.csswg.org/selectors-4/#descendant-combinators">Descendant Combinator</a></li>
<li><a href="https://drafts.csswg.org/selectors-4/#child-combinators">Child Combinator</a></li>
<li><a href="https://drafts.csswg.org/selectors-4/#adjacent-sibling-combinators">Next Sibling Combinator</a></li>
<li><a href="https://drafts.csswg.org/selectors-4/#general-sibling-combinators">Subsequent Sibling Combinator</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/attribute-selectors-advanced-css-selectors-part-4/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">It is sometimes called <strong>closing angle bracket</strong> or <strong>right pointing angle bracket</strong> &#8211; although these are distinct symbols contrast <strong>‘&gt;’</strong> with <strong>‘〉’</strong><a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">The space character only acts as a <strong>descendant combinator</strong> when it is alone. If you write a <strong>child combinator</strong> with spaces (<span class="css-class">.parent &gt; .child</span>), it is a <strong>child combinator</strong>, not a <strong>child + descendant combinator</strong>.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn4">In earlier versions of the CSS specification, it was called <strong>following sibling combinator</strong>, but the internal anchor was (and still is) <strong>general-sibling combinators</strong> (<a href="https://web.archive.org/web/20170103060540/https://drafts.csswg.org/selectors-3/#general-sibling-combinators">look at the end of the URL</a>).<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">Yes, it is a lot of rules.<a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">I pulled the CSS from the main landing pages of the following:
<ul class="incremental">
<li>BBC,</li>
<li>Engadget,</li>
<li>The Verge,</li>
<li>Wikipedia,</li>
<li>WordPress</li>
</ul>
<p><a class="footnote-back" href="#fnref6">↩</a></li>
<li id="fn7">Take these numbers as a rough guide to their relative use &#8211; if you find yourself using a lot of <strong>subsequent sibling combinators</strong>, then you are, probably, doing something wrong.<a class="footnote-back" href="#fnref7">↩</a></li>
<li id="fn8">This is not entirely accurate. There are other selector types you can use (which will be covered over the next few tutorials) but, for now, it is accurate enough. One such selector is the <span class="css-pseudo-element">::after</span> pseudo-element you saw in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-1/#clearfix---the-better-way-to-clear-a-float">one of the float tutorials</a>.<a class="footnote-back" href="#fnref8">↩</a></li>
<li id="fn9">There is plenty in the CSS Styling that you haven’t seen &#8211; but they will be covered in future tutorials.<a class="footnote-back" href="#fnref9">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-combinators-advanced-css-selectors-part-3/">CSS Combinators &#8211; Advanced CSS Selectors &#8211; Part 3</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS Specificity &#8211; Advanced CSS Selectors &#8211; Part 2</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 19 Apr 2019 14:57:44 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css selectors]]></category>
		<category><![CDATA[css specificity]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3822</guid>

					<description><![CDATA[<p>Learn to be more specific in selecting elements for styling and how to calculate the specificity of CSS selectors.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">CSS Specificity &#8211; Advanced CSS Selectors &#8211; Part 2</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>Understanding CSS <em>specificity</em> will help you understand how rules are applied to the elements on your page and allow you greater control over how your page is styled.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#getting-specific">Getting Specific</a></li>
<li><a href="#calculating-specificity">Calculating Specificity</a></li>
<li><a href="#rules-for-creating-specific-selectors">Rules for Creating Specific Selectors</a></li>
<li><a href="#final-words">Final Words</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="getting-specific">Getting Specific</h2>
<p>You’ve seen that you can apply multiple styles to an HTML element like this:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">&quot;first&quot;</span><span class="ot"> class=</span><span class="st">&quot;important box&quot;</span><span class="kw">&gt;</span></a></code></pre>
</div>
<p>And you can create individual styles for various elements on the page:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb2-1" title="1">p {</a>
<a class="sourceLine" id="cb2-2" title="2">  <span class="kw">background-color</span>: <span class="cn">aliceblue</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-3" title="3">}</a>
<a class="sourceLine" id="cb2-4" title="4"></a>
<a class="sourceLine" id="cb2-5" title="5"><span class="pp">#first</span> {</a>
<a class="sourceLine" id="cb2-6" title="6">  <span class="kw">background-color</span>: <span class="cn">darkgray</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-7" title="7">  <span class="kw">color</span>: <span class="cn">yellow</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-8" title="8">}</a>
<a class="sourceLine" id="cb2-9" title="9"></a>
<a class="sourceLine" id="cb2-10" title="10"><span class="fu">.important</span> {</a>
<a class="sourceLine" id="cb2-11" title="11">  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-12" title="12">  <span class="kw">background-color</span>: <span class="cn">red</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-13" title="13">  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-14" title="14">  <span class="kw">border</span>: <span class="dv">2</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-15" title="15">}</a>
<a class="sourceLine" id="cb2-16" title="16"></a>
<a class="sourceLine" id="cb2-17" title="17"><span class="fu">.box</span> {</a>
<a class="sourceLine" id="cb2-18" title="18">  <span class="kw">border</span>: <span class="dv">1</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb2-19" title="19">}</a></code></pre>
</div>
<p>A number of rules style the same CSS properties &#8211; <span class="css-property">background-color</span> and <span class="css-property">color</span> &#8211; and final result depends on:</p>
<ol class="incremental" type="1">
<li>the priority (or significance) of the selectors</li>
<li>for selectors with the same priority, the last defined property takes priority.</li>
</ol>
<p>Which means that the final style rule looks like this</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb3-1" title="1">{</a>
<a class="sourceLine" id="cb3-2" title="2">  <span class="co">/* ID styles have highest priority */</span></a>
<a class="sourceLine" id="cb3-3" title="3">  <span class="kw">background-color</span>: <span class="cn">darkgray</span><span class="op">;</span></a>
<a class="sourceLine" id="cb3-4" title="4">  <span class="kw">color</span>: <span class="cn">yellow</span><span class="op">;</span></a>
<a class="sourceLine" id="cb3-5" title="5">  <span class="co">/* font-size is only specified in .important,</span></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="co">     so it is applied */</span></a>
<a class="sourceLine" id="cb3-7" title="7">  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span></a>
<a class="sourceLine" id="cb3-8" title="8">  <span class="co">/* border in .box is defined after border was</span></a>
<a class="sourceLine" id="cb3-9" title="9"><span class="co">     defined in .important, so it gets applied */</span></a>
<a class="sourceLine" id="cb3-10" title="10">  <span class="kw">border</span>: <span class="dv">1</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb3-11" title="11">}</a></code></pre>
</div>
<p>This can seem haphazard and you might like to have better control over your CSS style rules &#8211; especially if later declarations can override earlier declarations.</p>
<p>We can overcome this by being more specific with our styling rules:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb4-1" title="1"><span class="co">/*</span></a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co">  Apply this style to any element which has</span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="co">  id=&quot;first&quot; AND class=&quot;important&quot;</span></a>
<a class="sourceLine" id="cb4-4" title="4"><span class="co">*/</span></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="pp">#first</span><span class="fu">.important</span> {</a>
<a class="sourceLine" id="cb4-6" title="6">  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span></a>
<a class="sourceLine" id="cb4-7" title="7">  <span class="kw">background-color</span>: <span class="cn">red</span><span class="op">;</span></a>
<a class="sourceLine" id="cb4-8" title="8">  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb4-9" title="9">}</a></code></pre>
</div>
<p>We can get even more specific with the following:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb5-1" title="1"><span class="co">/*</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="co">  Apply this style to any &lt;p&gt; element which has</span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="co">  id=&quot;first&quot; AND class=&quot;important&quot;</span></a>
<a class="sourceLine" id="cb5-4" title="4"><span class="co">*/</span></a>
<a class="sourceLine" id="cb5-5" title="5">p<span class="pp">#first</span><span class="fu">.important</span> {</a>
<a class="sourceLine" id="cb5-6" title="6">  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span></a>
<a class="sourceLine" id="cb5-7" title="7">  <span class="kw">background-color</span>: <span class="cn">red</span><span class="op">;</span></a>
<a class="sourceLine" id="cb5-8" title="8">  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb5-9" title="9">}</a></code></pre>
</div>
<p>However, if you created the following rule:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb6-1" title="1"><span class="co">/*</span></a>
<a class="sourceLine" id="cb6-2" title="2"><span class="co">  Apply this style to any &lt;p&gt; element which has</span></a>
<a class="sourceLine" id="cb6-3" title="3"><span class="co">  a class=&quot;important&quot;</span></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="co">*/</span></a>
<a class="sourceLine" id="cb6-5" title="5">p<span class="fu">.important</span> {</a>
<a class="sourceLine" id="cb6-6" title="6">  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span></a>
<a class="sourceLine" id="cb6-7" title="7">  <span class="kw">background-color</span>: <span class="cn">red</span><span class="op">;</span></a>
<a class="sourceLine" id="cb6-8" title="8">  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span></a>
<a class="sourceLine" id="cb6-9" title="9">}</a></code></pre>
</div>
<p>And you applied it to the following code:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb7-1" title="1"><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">&quot;first&quot;</span><span class="ot"> class=</span><span class="st">&quot;important box&quot;</span><span class="kw">&gt;</span></a></code></pre>
</div>
<p>You would find that the styles of <span class="css-id">#first</span> would take priority over the styles in <span class="css-class">p.important</span> despite <span class="css-class">p.important</span> appearing to be more specific &#8211; after all, it specifies <strong>two</strong> selectors (&lt;element&gt; and .class) over the <strong>single</strong> ID selector.</p>
<p>This is because the <strong>significance</strong> of a rule depends on the <em>specificity</em> of the selector. CSS specificity is calculated using a few straightforward rules.</p>
<h2 id="calculating-specificity">Calculating Specificity</h2>
<p>Specificity is calculated as a string of three values<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a>. Many resources and tutorials show it as a single number like 000 or 130. Some tutorials show it in the form 0-0-0 or 1-3-0 &#8211; which is a better representation. I will use the following representation: 0:0:0 or 1:3:0.</p>
<p>The <em>specificity</em> number indicates the total counts of various basic selectors. The universal selector always has a <em>specificity</em> of 0:0:0 &#8211; so any selector with a higher <em>specificity</em> will trump it. As with normal numbers, the leftmost digits are more significant than the rightmost digits. Consider the ranking of the following specificities:</p>
<ul class="incremental">
<li>0:0:1 &gt; 0:0:0</li>
<li>0:2:0 &gt; 0:1:0</li>
<li>0:2:1 &gt; 0:1:6</li>
<li>0:2:5 &gt; 0:2:4</li>
<li>1:2:3 &gt; 0:12:7</li>
</ul>
<p>The <em>specificity</em> number is calculated as the total number of CSS specifiers used for that style rule. The totals are arranged in the following manner:</p>
<table style="border:1px solid black;margin: auto;">
<tr>
<td style="border:1px solid black;padding:1.5em;">
IDs
</td>
<td style="border:1px solid black;padding:1.5em;">
.classes and [attributes]
</td>
<td style="border:1px solid black;padding:1.5em;">
&lt;elements&gt;
</td>
</tr>
</table>
<p>Consider the specificity of the following selectors:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb8-1" title="1"><span class="op">*</span> {</a>
<a class="sourceLine" id="cb8-2" title="2">  <span class="co">/* specificity = 0:0:0 */</span>  </a>
<a class="sourceLine" id="cb8-3" title="3">}</a>
<a class="sourceLine" id="cb8-4" title="4"></a>
<a class="sourceLine" id="cb8-5" title="5">p {</a>
<a class="sourceLine" id="cb8-6" title="6">  <span class="co">/* specificity = 0:0:1 */</span>  </a>
<a class="sourceLine" id="cb8-7" title="7">}</a>
<a class="sourceLine" id="cb8-8" title="8"></a>
<a class="sourceLine" id="cb8-9" title="9"><span class="fu">.class</span> {</a>
<a class="sourceLine" id="cb8-10" title="10">  <span class="co">/* specificity = 0:1:0 */</span>  </a>
<a class="sourceLine" id="cb8-11" title="11">}</a>
<a class="sourceLine" id="cb8-12" title="12"></a>
<a class="sourceLine" id="cb8-13" title="13"><span class="ex">[attribute]</span> {</a>
<a class="sourceLine" id="cb8-14" title="14">  <span class="co">/* specificity = 0:1:0 */</span>    </a>
<a class="sourceLine" id="cb8-15" title="15">}</a>
<a class="sourceLine" id="cb8-16" title="16"></a>
<a class="sourceLine" id="cb8-17" title="17"><span class="pp">#id</span> {</a>
<a class="sourceLine" id="cb8-18" title="18">  <span class="co">/* specificity = 1:0:0 */</span>  </a>
<a class="sourceLine" id="cb8-19" title="19">}</a>
<a class="sourceLine" id="cb8-20" title="20"></a>
<a class="sourceLine" id="cb8-21" title="21">p<span class="fu">.class</span> {</a>
<a class="sourceLine" id="cb8-22" title="22">  <span class="co">/* specificity = 0:1:1 */</span></a>
<a class="sourceLine" id="cb8-23" title="23">}</a>
<a class="sourceLine" id="cb8-24" title="24"></a>
<a class="sourceLine" id="cb8-25" title="25">ol<span class="ex">[reversed]</span> {</a>
<a class="sourceLine" id="cb8-26" title="26">  <span class="co">/* specificity = 0:1:1 */</span></a>
<a class="sourceLine" id="cb8-27" title="27">}</a>
<a class="sourceLine" id="cb8-28" title="28"></a>
<a class="sourceLine" id="cb8-29" title="29">p<span class="pp">#id</span><span class="fu">.class</span> {</a>
<a class="sourceLine" id="cb8-30" title="30">  <span class="co">/* specificity = 1:1:1 */</span></a>
<a class="sourceLine" id="cb8-31" title="31">}</a>
<a class="sourceLine" id="cb8-32" title="32"></a>
<a class="sourceLine" id="cb8-33" title="33">p<span class="pp">#id</span><span class="fu">.class</span><span class="ex">[attribute]</span> {</a>
<a class="sourceLine" id="cb8-34" title="34">  <span class="co">/* specificity = 1:2:1 */</span></a>
<a class="sourceLine" id="cb8-35" title="35">}</a>
<a class="sourceLine" id="cb8-36" title="36"></a>
<a class="sourceLine" id="cb8-37" title="37"><span class="pp">#id</span><span class="ex">[attribute]</span> {</a>
<a class="sourceLine" id="cb8-38" title="38">  <span class="co">/* specificity = 1:1:0 */</span></a>
<a class="sourceLine" id="cb8-39" title="39">}</a>
<a class="sourceLine" id="cb8-40" title="40"></a>
<a class="sourceLine" id="cb8-41" title="41"><span class="fu">.class</span><span class="ex">[attribute]</span> {</a>
<a class="sourceLine" id="cb8-42" title="42">  <span class="co">/* specificity = 0:2:0 */</span></a>
<a class="sourceLine" id="cb8-43" title="43">}</a>
<a class="sourceLine" id="cb8-44" title="44"></a>
<a class="sourceLine" id="cb8-45" title="45"><span class="co">/*</span></a>
<a class="sourceLine" id="cb8-46" title="46"><span class="co">  it looks strange, but this is valid CSS</span></a>
<a class="sourceLine" id="cb8-47" title="47"><span class="co">  you can repeat the same selector over and</span></a>
<a class="sourceLine" id="cb8-48" title="48"><span class="co">  over to increase its specificity.</span></a>
<a class="sourceLine" id="cb8-49" title="49"></a>
<a class="sourceLine" id="cb8-50" title="50"><span class="co">  It does not work for &lt;elements&gt;, i.e. you</span></a>
<a class="sourceLine" id="cb8-51" title="51"><span class="co">  can not do ppp to increase the specificity</span></a>
<a class="sourceLine" id="cb8-52" title="52"><span class="co">  for &lt;p&gt; tags.</span></a>
<a class="sourceLine" id="cb8-53" title="53"><span class="co">*/</span></a>
<a class="sourceLine" id="cb8-54" title="54"><span class="fu">.class.class.class.class</span> {</a>
<a class="sourceLine" id="cb8-55" title="55">  <span class="co">/* specificity = 0:4:0 */</span></a>
<a class="sourceLine" id="cb8-56" title="56">}</a></code></pre>
</div>
<p>In each case, you simply add up the total number of basic selectors, put them in the correct location and compare.</p>
<h2 id="rules-for-creating-specific-selectors">Rules for Creating Specific Selectors</h2>
<ol class="incremental" type="1">
<li>If you specify an HTML element, then it must be at the beginning of the selector. i.e.: <span class="css-class">p[attribute]</span> not <span class="css-class">[attribute]p</span>.</li>
<li>There can be a maximum of 1 HTML element in a specific selector. i.e.: <span class="css-class">p.class</span> or <span class="css-class">ul[reversed]</span>, but not <span class="css-class">pspan.class</span>.</li>
<li>There can be a maximum of 1 <span class="css-id">#ID</span> in a selector. This is because <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#fn2">an element can have at most 1 <span class="css-id">#ID</span></a>.</li>
<li>The order of <span class="css-class">.class</span>, <span class="css-attribute">[attribute]</span>, or <span class="css-id">#ID</span> doesn’t matter. i.e.: <span class="css-class">#ID.class</span> is equivalent to <span class="css-class">.class#ID</span>.</li>
<li><span class="css-class">.class</span>, <span class="css-attribute">[attribute]</span>, and <span class="css-id">#ID</span> selectors may be repeated to increase their specificity. i.e.: <span class="css-class">.class</span> has a specificity of 0:1:0, but <span class="css-class">.class.class</span> has a specificity of 0:2:0.</li>
<li>You cannot repeat HTML elements. i.e.: <span class="css-class">pppp</span> or <span class="css-class">ulul</span> have no meaning and will be ignored by the browser.</li>
<li>All selectors are written together without spaces between them. i.e.: <span class="css-class">p.class</span> is not the same as <span class="css-class">p .class</span> and <span class="css-class">#id[attribute]</span> is not the same as <span class="css-class">#id [attribute]</span>.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></li>
</ol>
<h2 id="final-words">Final Words</h2>
<ol class="incremental" type="1">
<li>
<p>You can be very specific about which HTML element to style on a page by stringing together various selectors associated with that element:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb9-1" title="1"><span class="co">/*</span></a>
<a class="sourceLine" id="cb9-2" title="2"><span class="co">  select &lt;ul&gt; elements which contain the</span></a>
<a class="sourceLine" id="cb9-3" title="3"><span class="co">  reversed attribute</span></a>
<a class="sourceLine" id="cb9-4" title="4"></a>
<a class="sourceLine" id="cb9-5" title="5"><span class="co">  specificity = 0:1:1</span></a>
<a class="sourceLine" id="cb9-6" title="6"><span class="co">*/</span></a>
<a class="sourceLine" id="cb9-7" title="7">ul<span class="ex">[reversed]</span> {</a>
<a class="sourceLine" id="cb9-8" title="8"></a>
<a class="sourceLine" id="cb9-9" title="9">}</a>
<a class="sourceLine" id="cb9-10" title="10"></a>
<a class="sourceLine" id="cb9-11" title="11"><span class="co">/*</span></a>
<a class="sourceLine" id="cb9-12" title="12"><span class="co">  select &lt;ul&gt; elements which contain the</span></a>
<a class="sourceLine" id="cb9-13" title="13"><span class="co">  reversed attribute AND have a class of</span></a>
<a class="sourceLine" id="cb9-14" title="14"><span class="co">  .class1</span></a>
<a class="sourceLine" id="cb9-15" title="15"></a>
<a class="sourceLine" id="cb9-16" title="16"><span class="co">  specificity = 0:2:1</span></a>
<a class="sourceLine" id="cb9-17" title="17"><span class="co">*/</span></a>
<a class="sourceLine" id="cb9-18" title="18">ul<span class="ex">[reversed]</span><span class="fu">.class1</span> {</a>
<a class="sourceLine" id="cb9-19" title="19"></a>
<a class="sourceLine" id="cb9-20" title="20">}</a></code></pre>
</div>
</li>
<li><em>Specificity</em> is calculated by summing and arranging the total number of basic specifiers in each of the following groups:<br />
<table style="border:1px solid black;margin: auto;">
<tr>
<td style="border:1px solid black;padding:1.5em;">
IDs
</td>
<td style="border:1px solid black;padding:1.5em;">
.classes and [attributes]
</td>
<td style="border:1px solid black;padding:1.5em;">
&lt;elements&gt;
</td>
</tr>
</table>
</li>
<li>In deciding which styling rule to apply, the rule with the higher <em>specificity</em> is applied.</li>
<li>If two rules have the same <em>specificity</em> then the last rule defined is applied.</li>
<li>The universal selector always has a specificity of 0:0:0.</li>
<li>
<p>There are no spaces between the selectors &#8211; it is written as one long expression.</p>
</li>
</ol>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://drafts.csswg.org/selectors-3/">CSS Selectors</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-combinators-advanced-css-selectors-part-3/">Next</a></p>
</div>
<div class="clear">
</div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">
<p>For now it is three values, in reality there two more values that have higher specificity and can be considered as the fourth and fifth specificity values &#8211; they will be covered in a future tutorial.<a href="#fnref1" class="footnote-back">↩</a></p>
</li>
<li id="fn2">
<p>The next tutorial will show how spaces between selectors changes the meaning of the selection expression.<a href="#fnref2" class="footnote-back">↩</a></p>
</li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">CSS Specificity &#8211; Advanced CSS Selectors &#8211; Part 2</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Advanced CSS Selectors &#8211; Part 1</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 17 Apr 2019 12:42:14 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[combinator]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3813</guid>

					<description><![CDATA[<p>Expand your skill set from 5 basic CSS selectors to over 50 advanced CSS selectors.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/">Advanced CSS Selectors &#8211; Part 1</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>We’ve seen <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/">5 different ways to select page elements</a> for styling. Over the next few tutorials we will add more than 50 advanced CSS selectors for targeting HTML elements for styling.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#a-quick-recap-and-introduction">A Quick Recap and Introduction</a></li>
<li><a href="#updated-clone-page-code">Updated Clone Page Code</a></li>
<li><a href="#final-words">Final Words</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="a-quick-recap-and-introduction">A Quick Recap and Introduction</h2>
<p>You have seen how to style HTML elements using the following selectors:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb1-1" class="sourceLine" title="1"></a>
<a id="cb1-2" class="sourceLine" title="2"></a><span class="co">/*</span>
<a id="cb1-3" class="sourceLine" title="3"></a><span class="co">  This styling will be applied to all elements on</span>
<a id="cb1-4" class="sourceLine" title="4"></a><span class="co">  the page unless another style overrides it.</span>
<a id="cb1-5" class="sourceLine" title="5"></a><span class="co">*/</span>
<a id="cb1-6" class="sourceLine" title="6"></a><span class="op">*</span> {
<a id="cb1-7" class="sourceLine" title="7"></a>  <span class="kw">box-sizing</span>: <span class="dv">border-box</span><span class="op">;</span>
<a id="cb1-8" class="sourceLine" title="8"></a>}
<a id="cb1-9" class="sourceLine" title="9"></a>
<a id="cb1-10" class="sourceLine" title="10"></a><span class="co">/*</span>
<a id="cb1-11" class="sourceLine" title="11"></a><span class="co">  This styling will be applied to all &lt;p&gt; elements</span>
<a id="cb1-12" class="sourceLine" title="12"></a><span class="co">  on the page unless overridden by a style applied</span>
<a id="cb1-13" class="sourceLine" title="13"></a><span class="co">  via a .class, [attribute], or #ID</span>
<a id="cb1-14" class="sourceLine" title="14"></a><span class="co">*/</span>
<a id="cb1-15" class="sourceLine" title="15"></a>p {
<a id="cb1-16" class="sourceLine" title="16"></a>  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb1-17" class="sourceLine" title="17"></a>  <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-18" class="sourceLine" title="18"></a>}
<a id="cb1-19" class="sourceLine" title="19"></a>
<a id="cb1-20" class="sourceLine" title="20"></a><span class="co">/*</span>
<a id="cb1-21" class="sourceLine" title="21"></a><span class="co">  This styling will be applied to all elements</span>
<a id="cb1-22" class="sourceLine" title="22"></a><span class="co">  with this class.</span>
<a id="cb1-23" class="sourceLine" title="23"></a>
<a id="cb1-24" class="sourceLine" title="24"></a><span class="co">  It can be overridden by other classes or [attributes]</span>
<a id="cb1-25" class="sourceLine" title="25"></a><span class="co">  that are applied to the element, but only if they are</span>
<a id="cb1-26" class="sourceLine" title="26"></a><span class="co">  defined after this one.</span>
<a id="cb1-27" class="sourceLine" title="27"></a>
<a id="cb1-28" class="sourceLine" title="28"></a><span class="co">  An #ID style will always override this style.</span>
<a id="cb1-29" class="sourceLine" title="29"></a><span class="co">*/</span>
<a id="cb1-30" class="sourceLine" title="30"></a><span class="fu">.myStyle</span> {
<a id="cb1-31" class="sourceLine" title="31"></a>  <span class="kw">color</span>: <span class="cn">blue</span><span class="op">;</span>
<a id="cb1-32" class="sourceLine" title="32"></a>  <span class="kw">background</span>: <span class="cn">yellow</span><span class="op">;</span>
<a id="cb1-33" class="sourceLine" title="33"></a>}
<a id="cb1-34" class="sourceLine" title="34"></a>
<a id="cb1-35" class="sourceLine" title="35"></a><span class="co">/*</span>
<a id="cb1-36" class="sourceLine" title="36"></a><span class="co">This styling will be applied to all elements</span>
<a id="cb1-37" class="sourceLine" title="37"></a><span class="co">matching this attribute.</span>
<a id="cb1-38" class="sourceLine" title="38"></a>
<a id="cb1-39" class="sourceLine" title="39"></a><span class="co">It can be overridden by other classes or [attributes]</span>
<a id="cb1-40" class="sourceLine" title="40"></a><span class="co">that are applied to the element, but only if they are</span>
<a id="cb1-41" class="sourceLine" title="41"></a><span class="co">defined after this one.</span>
<a id="cb1-42" class="sourceLine" title="42"></a>
<a id="cb1-43" class="sourceLine" title="43"></a><span class="co">An #ID style will always override this style.</span>
<a id="cb1-44" class="sourceLine" title="44"></a><span class="co">*/</span>
<a id="cb1-45" class="sourceLine" title="45"></a><span class="ex">[reversed]</span> {
<a id="cb1-46" class="sourceLine" title="46"></a>  <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-47" class="sourceLine" title="47"></a>  <span class="kw">background-color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb1-48" class="sourceLine" title="48"></a>}
<a id="cb1-49" class="sourceLine" title="49"></a>
<a id="cb1-50" class="sourceLine" title="50"></a><span class="co">/*</span>
<a id="cb1-51" class="sourceLine" title="51"></a><span class="co">  This styling will be applied to the element</span>
<a id="cb1-52" class="sourceLine" title="52"></a><span class="co">  with this ID. Remember: each ID must be</span>
<a id="cb1-53" class="sourceLine" title="53"></a><span class="co">  unique on the page and an element can have a</span>
<a id="cb1-54" class="sourceLine" title="54"></a><span class="co">  maximum of 1 ID.</span>
<a id="cb1-55" class="sourceLine" title="55"></a>
<a id="cb1-56" class="sourceLine" title="56"></a><span class="co">  This styling overrides any other styling</span>
<a id="cb1-57" class="sourceLine" title="57"></a><span class="co">  applied to the element.</span>
<a id="cb1-58" class="sourceLine" title="58"></a><span class="co">*/</span>
<a id="cb1-59" class="sourceLine" title="59"></a>
<a id="cb1-60" class="sourceLine" title="60"></a><span class="pp">#myID</span> {
<a id="cb1-61" class="sourceLine" title="61"></a>  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-62" class="sourceLine" title="62"></a>  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb1-63" class="sourceLine" title="63"></a>  <span class="kw">background-color</span>: <span class="cn">orange</span><span class="op">;</span>
<a id="cb1-64" class="sourceLine" title="64"></a>}</code></pre>
</div>
<p>This sort of styling is very direct: you explicitly specify the element you want styled and rely on inheritance to pass styles from parent to child elements.</p>
<p>This direct form of styling does have shortcomings &#8211; if we want to style part of the page differently, we have to explicitly create new styles for that (likely using classes) and apply them to the elements we want styled. This creates a multiplicity of style rules than can quickly become unwieldy.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a> As well, if you apply multiple styles (via classes) then the order in which the styles were defined matters.</p>
<p>Let’s consider the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">clone page created earlier</a>: one of the things used was a <strong>card</strong> pattern for the articles on the page:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb2-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb2-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb2-3" class="sourceLine" title="3"></a>    <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">""</span><span class="kw">&gt;</span>
<a id="cb2-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-5" class="sourceLine" title="5"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb2-6" class="sourceLine" title="6"></a>
<a id="cb2-7" class="sourceLine" title="7"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb2-8" class="sourceLine" title="8"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb2-9" class="sourceLine" title="9"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>This worked fine, except that instead of using a generic class of <span class="css-class">.headline</span>, specific headline classes were used depending on which column the card was located: <span class="css-class">.headline-small</span>, <span class="css-class">.headline-large</span>, and <span class="css-class">.headline-medium</span>.</p>
<p>This makes moving cards from one column to another complicated because styling information (rather than content information) is embedded in the class. Moving a card requires the class be updated because its location changed.</p>
<p>CSS allows you to apply styles based on the context your content appears in. Consider:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" title="1"></a><span class="co">/*</span>
<a id="cb3-2" class="sourceLine" title="2"></a><span class="co">apply the following style to elements</span>
<a id="cb3-3" class="sourceLine" title="3"></a><span class="co">with the class .headline that are</span>
<a id="cb3-4" class="sourceLine" title="4"></a><span class="co">immediate children of elements with the</span>
<a id="cb3-5" class="sourceLine" title="5"></a><span class="co">class .card that are immediate children</span>
<a id="cb3-6" class="sourceLine" title="6"></a><span class="co">of elements with the class .left-column</span>
<a id="cb3-7" class="sourceLine" title="7"></a><span class="co">*/</span>
<a id="cb3-8" class="sourceLine" title="8"></a><span class="fu">.column-left</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb3-9" class="sourceLine" title="9"></a>
<a id="cb3-10" class="sourceLine" title="10"></a>}
<a id="cb3-11" class="sourceLine" title="11"></a>
<a id="cb3-12" class="sourceLine" title="12"></a><span class="co">/*</span>
<a id="cb3-13" class="sourceLine" title="13"></a><span class="co">apply the following style to elements</span>
<a id="cb3-14" class="sourceLine" title="14"></a><span class="co">with the class .headline if their parent</span>
<a id="cb3-15" class="sourceLine" title="15"></a><span class="co">element has class .card and their</span>
<a id="cb3-16" class="sourceLine" title="16"></a><span class="co">grandparent has class .middle-column</span>
<a id="cb3-17" class="sourceLine" title="17"></a><span class="co">*/</span>
<a id="cb3-18" class="sourceLine" title="18"></a><span class="fu">.column-middle</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb3-19" class="sourceLine" title="19"></a>  <span class="kw">font-size</span>: <span class="dv">32</span><span class="dt">px</span><span class="op">;</span>
<a id="cb3-20" class="sourceLine" title="20"></a>}
<a id="cb3-21" class="sourceLine" title="21"></a>
<a id="cb3-22" class="sourceLine" title="22"></a><span class="co">/*</span>
<a id="cb3-23" class="sourceLine" title="23"></a><span class="co">apply the following style to elements</span>
<a id="cb3-24" class="sourceLine" title="24"></a><span class="co">with the class .headline only if it is</span>
<a id="cb3-25" class="sourceLine" title="25"></a><span class="co">nested exactly as follows:</span>
<a id="cb3-26" class="sourceLine" title="26"></a><span class="co">  class=“right-column”</span>
<a id="cb3-27" class="sourceLine" title="27"></a><span class="co">      class=“card”</span>
<a id="cb3-28" class="sourceLine" title="28"></a><span class="co">          class=“headline”</span>
<a id="cb3-29" class="sourceLine" title="29"></a><span class="co">*/</span>
<a id="cb3-30" class="sourceLine" title="30"></a><span class="fu">.column-right</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb3-31" class="sourceLine" title="31"></a>  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb3-32" class="sourceLine" title="32"></a>}</code></pre>
</div>
<p>If you replace the <span class="css-class">.headline-small</span>, <span class="css-class">.headline-large</span>, and <span class="css-class">.headline-medium</span>. style definitions in the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">clone page</a> with the above code and replace their use in the HTML with <span class="css-class">.headline</span>, you will notice everything still works correctly.</p>
<h2 id="updated-clone-page-code">Updated Clone Page Code</h2>
<p>You can see how the updated clone page <a href="https://complete-concrete-concise.com/sample/37-update-clone-page.html">looks here</a> and you can see how the original clone page <a href="https://complete-concrete-concise.com/sample/32-float.html">looks here</a>. You can also inspect the page source code using the <strong>view source</strong> tool you <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/#view-page-source">learned about here</a> or inspect the updated source code below:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" title="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb4-2" class="sourceLine" title="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb4-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb4-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;title&gt;</span>Clone Page<span class="kw">&lt;/title&gt;</span>
<a id="cb4-5" class="sourceLine" title="5"></a>    <span class="kw">&lt;meta</span><span class="ot"> charset=</span><span class="st">"utf-8"</span>  <span class="kw">/&gt;</span>
<a id="cb4-6" class="sourceLine" title="6"></a>
<a id="cb4-7" class="sourceLine" title="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb4-8" class="sourceLine" title="8"></a>
<a id="cb4-9" class="sourceLine" title="9"></a>      <span class="op">*</span> {
<a id="cb4-10" class="sourceLine" title="10"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span><span class="op">;</span>
<a id="cb4-11" class="sourceLine" title="11"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span><span class="op">;</span>
<a id="cb4-12" class="sourceLine" title="12"></a>        <span class="kw">font-size</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-13" class="sourceLine" title="13"></a>      }
<a id="cb4-14" class="sourceLine" title="14"></a>
<a id="cb4-15" class="sourceLine" title="15"></a>      img {
<a id="cb4-16" class="sourceLine" title="16"></a>        <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb4-17" class="sourceLine" title="17"></a>      }
<a id="cb4-18" class="sourceLine" title="18"></a>
<a id="cb4-19" class="sourceLine" title="19"></a>      <span class="pp">#wrapper</span> {
<a id="cb4-20" class="sourceLine" title="20"></a>        <span class="kw">width</span>: <span class="dv">960</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-21" class="sourceLine" title="21"></a>        <span class="kw">margin</span>: <span class="bu">auto</span><span class="op">;</span>
<a id="cb4-22" class="sourceLine" title="22"></a>      }
<a id="cb4-23" class="sourceLine" title="23"></a>
<a id="cb4-24" class="sourceLine" title="24"></a>      <span class="pp">#title</span> {
<a id="cb4-25" class="sourceLine" title="25"></a>        <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb4-26" class="sourceLine" title="26"></a>        <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb4-27" class="sourceLine" title="27"></a>        <span class="kw">padding</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-28" class="sourceLine" title="28"></a>      }
<a id="cb4-29" class="sourceLine" title="29"></a>
<a id="cb4-30" class="sourceLine" title="30"></a>      <span class="pp">#site-name</span> {
<a id="cb4-31" class="sourceLine" title="31"></a>        <span class="kw">font-size</span>: <span class="dv">32</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-32" class="sourceLine" title="32"></a>        <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb4-33" class="sourceLine" title="33"></a>      }
<a id="cb4-34" class="sourceLine" title="34"></a>
<a id="cb4-35" class="sourceLine" title="35"></a>      <span class="pp">#login</span> {
<a id="cb4-36" class="sourceLine" title="36"></a>        <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb4-37" class="sourceLine" title="37"></a>        <span class="kw">padding-top</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-38" class="sourceLine" title="38"></a>        <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb4-39" class="sourceLine" title="39"></a>      }
<a id="cb4-40" class="sourceLine" title="40"></a>
<a id="cb4-41" class="sourceLine" title="41"></a>      <span class="pp">#search</span> {
<a id="cb4-42" class="sourceLine" title="42"></a>        <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb4-43" class="sourceLine" title="43"></a>        <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb4-44" class="sourceLine" title="44"></a>        <span class="kw">padding-top</span>: <span class="dv">18</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-45" class="sourceLine" title="45"></a>        <span class="kw">padding-right</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-46" class="sourceLine" title="46"></a>        <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-47" class="sourceLine" title="47"></a>      }
<a id="cb4-48" class="sourceLine" title="48"></a>
<a id="cb4-49" class="sourceLine" title="49"></a>      <span class="pp">#navbar</span> {
<a id="cb4-50" class="sourceLine" title="50"></a>        <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb4-51" class="sourceLine" title="51"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb4-52" class="sourceLine" title="52"></a>        <span class="kw">border-bottom</span>: <span class="dv">2</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">grey</span><span class="op">;</span>
<a id="cb4-53" class="sourceLine" title="53"></a>      }
<a id="cb4-54" class="sourceLine" title="54"></a>
<a id="cb4-55" class="sourceLine" title="55"></a>      <span class="pp">#darkbox</span> {
<a id="cb4-56" class="sourceLine" title="56"></a>        <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb4-57" class="sourceLine" title="57"></a>        <span class="kw">height</span>: <span class="dv">100</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-58" class="sourceLine" title="58"></a>      }
<a id="cb4-59" class="sourceLine" title="59"></a>
<a id="cb4-60" class="sourceLine" title="60"></a>      <span class="pp">#content</span> {
<a id="cb4-61" class="sourceLine" title="61"></a>        <span class="kw">margin-top</span>: <span class="dv">-90</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-62" class="sourceLine" title="62"></a>      }
<a id="cb4-63" class="sourceLine" title="63"></a>
<a id="cb4-64" class="sourceLine" title="64"></a>      <span class="pp">#popular</span> {
<a id="cb4-65" class="sourceLine" title="65"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb4-66" class="sourceLine" title="66"></a>        <span class="kw">padding-left</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-67" class="sourceLine" title="67"></a>        <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb4-68" class="sourceLine" title="68"></a>      }
<a id="cb4-69" class="sourceLine" title="69"></a>
<a id="cb4-70" class="sourceLine" title="70"></a>      <span class="pp">#footer</span> {
<a id="cb4-71" class="sourceLine" title="71"></a>        <span class="kw">text-align</span>: <span class="dv">center</span><span class="op">;</span>
<a id="cb4-72" class="sourceLine" title="72"></a>        <span class="kw">padding</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-73" class="sourceLine" title="73"></a>        <span class="kw">background</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb4-74" class="sourceLine" title="74"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb4-75" class="sourceLine" title="75"></a>        <span class="kw">font-size</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-76" class="sourceLine" title="76"></a>      }
<a id="cb4-77" class="sourceLine" title="77"></a>
<a id="cb4-78" class="sourceLine" title="78"></a>      <span class="fu">.nav-item</span> {
<a id="cb4-79" class="sourceLine" title="79"></a>        <span class="kw">display</span>: <span class="dv">inline-block</span><span class="op">;</span>
<a id="cb4-80" class="sourceLine" title="80"></a>        <span class="kw">padding</span>: <span class="dv">24</span><span class="dt">px</span> <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-81" class="sourceLine" title="81"></a>      }
<a id="cb4-82" class="sourceLine" title="82"></a>
<a id="cb4-83" class="sourceLine" title="83"></a>      <span class="fu">.column-left</span> {
<a id="cb4-84" class="sourceLine" title="84"></a>        <span class="kw">width</span>: <span class="dv">20</span><span class="dt">%</span><span class="op">;</span>
<a id="cb4-85" class="sourceLine" title="85"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb4-86" class="sourceLine" title="86"></a>      }
<a id="cb4-87" class="sourceLine" title="87"></a>
<a id="cb4-88" class="sourceLine" title="88"></a>      <span class="fu">.column-middle</span> {
<a id="cb4-89" class="sourceLine" title="89"></a>        <span class="kw">width</span>: <span class="dv">55</span><span class="dt">%</span><span class="op">;</span>
<a id="cb4-90" class="sourceLine" title="90"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb4-91" class="sourceLine" title="91"></a>        <span class="kw">border-left</span>: <span class="dv">2</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">grey</span><span class="op">;</span>
<a id="cb4-92" class="sourceLine" title="92"></a>        <span class="kw">border-right</span>: <span class="dv">2</span><span class="dt">px</span> <span class="dv">solid</span> <span class="cn">grey</span><span class="op">;</span>
<a id="cb4-93" class="sourceLine" title="93"></a>      }
<a id="cb4-94" class="sourceLine" title="94"></a>
<a id="cb4-95" class="sourceLine" title="95"></a>      <span class="fu">.column-right</span> {
<a id="cb4-96" class="sourceLine" title="96"></a>        <span class="kw">width</span>: <span class="dv">25</span><span class="dt">%</span><span class="op">;</span>
<a id="cb4-97" class="sourceLine" title="97"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb4-98" class="sourceLine" title="98"></a>      }
<a id="cb4-99" class="sourceLine" title="99"></a>
<a id="cb4-100" class="sourceLine" title="100"></a>      <span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb4-101" class="sourceLine" title="101"></a>        <span class="kw">clear</span>: <span class="dv">both</span><span class="op">;</span>
<a id="cb4-102" class="sourceLine" title="102"></a>        <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb4-103" class="sourceLine" title="103"></a>        <span class="kw">content</span>: <span class="st">""</span><span class="op">;</span>
<a id="cb4-104" class="sourceLine" title="104"></a>      }
<a id="cb4-105" class="sourceLine" title="105"></a>
<a id="cb4-106" class="sourceLine" title="106"></a>      <span class="fu">.card</span> {
<a id="cb4-107" class="sourceLine" title="107"></a>        <span class="kw">padding</span>: <span class="dv">0</span> <span class="dv">16</span><span class="dt">px</span> <span class="dv">16</span><span class="dt">px</span> <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-108" class="sourceLine" title="108"></a>      }
<a id="cb4-109" class="sourceLine" title="109"></a>
<a id="cb4-110" class="sourceLine" title="110"></a>      <span class="fu">.image</span> {
<a id="cb4-111" class="sourceLine" title="111"></a>
<a id="cb4-112" class="sourceLine" title="112"></a>      }
<a id="cb4-113" class="sourceLine" title="113"></a>
<a id="cb4-114" class="sourceLine" title="114"></a>      <span class="co">/*</span>
<a id="cb4-115" class="sourceLine" title="115"></a><span class="co">      Use the more specific styling selectors</span>
<a id="cb4-116" class="sourceLine" title="116"></a><span class="co">      that select HTML elements based on their</span>
<a id="cb4-117" class="sourceLine" title="117"></a><span class="co">      class AND placement in the page.</span>
<a id="cb4-118" class="sourceLine" title="118"></a><span class="co">      */</span>
<a id="cb4-119" class="sourceLine" title="119"></a>      <span class="fu">.column-left</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb4-120" class="sourceLine" title="120"></a>
<a id="cb4-121" class="sourceLine" title="121"></a>      }
<a id="cb4-122" class="sourceLine" title="122"></a>
<a id="cb4-123" class="sourceLine" title="123"></a>      <span class="fu">.column-middle</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb4-124" class="sourceLine" title="124"></a>        <span class="kw">font-size</span>: <span class="dv">32</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-125" class="sourceLine" title="125"></a>      }
<a id="cb4-126" class="sourceLine" title="126"></a>
<a id="cb4-127" class="sourceLine" title="127"></a>      <span class="fu">.column-right</span> <span class="op">&gt;</span> <span class="fu">.card</span> <span class="op">&gt;</span> <span class="fu">.headline</span> {
<a id="cb4-128" class="sourceLine" title="128"></a>        <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-129" class="sourceLine" title="129"></a>      }
<a id="cb4-130" class="sourceLine" title="130"></a>
<a id="cb4-131" class="sourceLine" title="131"></a>      <span class="fu">.timestamp</span> {
<a id="cb4-132" class="sourceLine" title="132"></a>        <span class="kw">padding-top</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-133" class="sourceLine" title="133"></a>        <span class="kw">color</span>: <span class="cn">gray</span><span class="op">;</span>
<a id="cb4-134" class="sourceLine" title="134"></a>        <span class="kw">font-size</span>: <span class="dv">12</span><span class="dt">px</span><span class="op">;</span>
<a id="cb4-135" class="sourceLine" title="135"></a>      }
<a id="cb4-136" class="sourceLine" title="136"></a>
<a id="cb4-137" class="sourceLine" title="137"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb4-138" class="sourceLine" title="138"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb4-139" class="sourceLine" title="139"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb4-140" class="sourceLine" title="140"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"wrapper"</span><span class="kw">&gt;</span>
<a id="cb4-141" class="sourceLine" title="141"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>
<a id="cb4-142" class="sourceLine" title="142"></a>        <span class="kw">&lt;span</span><span class="ot"> id=</span><span class="st">"site-name"</span><span class="kw">&gt;</span>clonage<span class="kw">&lt;/span&gt;</span>
<a id="cb4-143" class="sourceLine" title="143"></a>        <span class="kw">&lt;span</span><span class="ot"> id=</span><span class="st">"login"</span><span class="ot"> class=</span><span class="st">"clearfix"</span><span class="kw">&gt;</span>Login<span class="kw">&lt;/span&gt;</span>
<a id="cb4-144" class="sourceLine" title="144"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb4-145" class="sourceLine" title="145"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;</span>
<a id="cb4-146" class="sourceLine" title="146"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Gear<span class="kw">&lt;/span&gt;</span>
<a id="cb4-147" class="sourceLine" title="147"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Gaming<span class="kw">&lt;/span&gt;</span>
<a id="cb4-148" class="sourceLine" title="148"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Entertainment<span class="kw">&lt;/span&gt;</span>
<a id="cb4-149" class="sourceLine" title="149"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Tomorrow<span class="kw">&lt;/span&gt;</span>
<a id="cb4-150" class="sourceLine" title="150"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Video<span class="kw">&lt;/span&gt;</span>
<a id="cb4-151" class="sourceLine" title="151"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Reviews<span class="kw">&lt;/span&gt;</span>
<a id="cb4-152" class="sourceLine" title="152"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Events<span class="kw">&lt;/span&gt;</span>
<a id="cb4-153" class="sourceLine" title="153"></a>        <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">nav-item</span><span class="kw">&gt;</span>Local Edition<span class="kw">&lt;/span&gt;</span>
<a id="cb4-154" class="sourceLine" title="154"></a>        <span class="kw">&lt;span</span><span class="ot"> id=</span><span class="st">"search"</span><span class="ot"> class=</span><span class="st">"clearfix"</span><span class="kw">&gt;</span>⌕<span class="kw">&lt;/span&gt;</span>
<a id="cb4-155" class="sourceLine" title="155"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb4-156" class="sourceLine" title="156"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"darkbox"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb4-157" class="sourceLine" title="157"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"content"</span><span class="ot"> class=</span><span class="st">"clearfix"</span><span class="kw">&gt;</span>
<a id="cb4-158" class="sourceLine" title="158"></a>        <span class="co">&lt;!--</span>
<a id="cb4-159" class="sourceLine" title="159"></a><span class="co">        Update all the .headline-small,</span>
<a id="cb4-160" class="sourceLine" title="160"></a><span class="co">        .headline-large, and .headline-medium</span>
<a id="cb4-161" class="sourceLine" title="161"></a><span class="co">        class tags to the .headline class.</span>
<a id="cb4-162" class="sourceLine" title="162"></a><span class="co">        --&gt;</span>
<a id="cb4-163" class="sourceLine" title="163"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>
<a id="cb4-164" class="sourceLine" title="164"></a>          <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"popular"</span><span class="kw">&gt;</span>Popular Now<span class="kw">&lt;/p&gt;</span>
<a id="cb4-165" class="sourceLine" title="165"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-166" class="sourceLine" title="166"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-167" class="sourceLine" title="167"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-small-1.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-168" class="sourceLine" title="168"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-169" class="sourceLine" title="169"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-170" class="sourceLine" title="170"></a>              Foods that boost your learning
<a id="cb4-171" class="sourceLine" title="171"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-172" class="sourceLine" title="172"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-173" class="sourceLine" title="173"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-174" class="sourceLine" title="174"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-175" class="sourceLine" title="175"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-176" class="sourceLine" title="176"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-small-2.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-177" class="sourceLine" title="177"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-178" class="sourceLine" title="178"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-179" class="sourceLine" title="179"></a>              Robot arms may be the next
<a id="cb4-180" class="sourceLine" title="180"></a>              technological frontier
<a id="cb4-181" class="sourceLine" title="181"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-182" class="sourceLine" title="182"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-183" class="sourceLine" title="183"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-184" class="sourceLine" title="184"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-185" class="sourceLine" title="185"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-186" class="sourceLine" title="186"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-small-3.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-187" class="sourceLine" title="187"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-188" class="sourceLine" title="188"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-189" class="sourceLine" title="189"></a>              Is virtual reality going to far?
<a id="cb4-190" class="sourceLine" title="190"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-191" class="sourceLine" title="191"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-192" class="sourceLine" title="192"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-193" class="sourceLine" title="193"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-194" class="sourceLine" title="194"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-195" class="sourceLine" title="195"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-small-4.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-196" class="sourceLine" title="196"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-197" class="sourceLine" title="197"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-198" class="sourceLine" title="198"></a>              The latest trends in cosplay
<a id="cb4-199" class="sourceLine" title="199"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-200" class="sourceLine" title="200"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-201" class="sourceLine" title="201"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-202" class="sourceLine" title="202"></a>
<a id="cb4-203" class="sourceLine" title="203"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb4-204" class="sourceLine" title="204"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-middle"</span><span class="kw">&gt;</span>
<a id="cb4-205" class="sourceLine" title="205"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-206" class="sourceLine" title="206"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-207" class="sourceLine" title="207"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-big-1.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-208" class="sourceLine" title="208"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-209" class="sourceLine" title="209"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-210" class="sourceLine" title="210"></a>              Before you buy, check our review of the
<a id="cb4-211" class="sourceLine" title="211"></a>              hottest cars on the market
<a id="cb4-212" class="sourceLine" title="212"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-213" class="sourceLine" title="213"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-214" class="sourceLine" title="214"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-215" class="sourceLine" title="215"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-216" class="sourceLine" title="216"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-217" class="sourceLine" title="217"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-big-2.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-218" class="sourceLine" title="218"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-219" class="sourceLine" title="219"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-220" class="sourceLine" title="220"></a>              Health benefits of fresh fruits
<a id="cb4-221" class="sourceLine" title="221"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-222" class="sourceLine" title="222"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-223" class="sourceLine" title="223"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-224" class="sourceLine" title="224"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb4-225" class="sourceLine" title="225"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-right"</span><span class="kw">&gt;</span>
<a id="cb4-226" class="sourceLine" title="226"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-227" class="sourceLine" title="227"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-228" class="sourceLine" title="228"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-medium-1.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-229" class="sourceLine" title="229"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-230" class="sourceLine" title="230"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-231" class="sourceLine" title="231"></a>              The best places to visit on Jupiter
<a id="cb4-232" class="sourceLine" title="232"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-233" class="sourceLine" title="233"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-234" class="sourceLine" title="234"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-235" class="sourceLine" title="235"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-236" class="sourceLine" title="236"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-237" class="sourceLine" title="237"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-medium-2.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-238" class="sourceLine" title="238"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-239" class="sourceLine" title="239"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-240" class="sourceLine" title="240"></a>              The latest smart watches monitor your
<a id="cb4-241" class="sourceLine" title="241"></a>              body's vitals while looking stylish
<a id="cb4-242" class="sourceLine" title="242"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-243" class="sourceLine" title="243"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-244" class="sourceLine" title="244"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-245" class="sourceLine" title="245"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb4-246" class="sourceLine" title="246"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb4-247" class="sourceLine" title="247"></a>              <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"32-medium-3.jpg"</span><span class="kw">&gt;</span>
<a id="cb4-248" class="sourceLine" title="248"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-249" class="sourceLine" title="249"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline"</span><span class="kw">&gt;</span>
<a id="cb4-250" class="sourceLine" title="250"></a>              Keeping yourself safe while shopping online
<a id="cb4-251" class="sourceLine" title="251"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb4-252" class="sourceLine" title="252"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;</span>🕔 2 Hours<span class="kw">&lt;/div&gt;</span>
<a id="cb4-253" class="sourceLine" title="253"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb4-254" class="sourceLine" title="254"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb4-255" class="sourceLine" title="255"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb4-256" class="sourceLine" title="256"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="kw">&gt;</span>Copyright 2018<span class="kw">&lt;/div&gt;</span>
<a id="cb4-257" class="sourceLine" title="257"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb4-258" class="sourceLine" title="258"></a>
<a id="cb4-259" class="sourceLine" title="259"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb4-260" class="sourceLine" title="260"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h2 id="final-words">Final Words</h2>
<p>You’ve received a brief introduction to one advanced CSS selector known as a <strong>combinator</strong>. This <em>combinator</em> (denoted with the symbol ‘<strong>&gt;</strong>’) specifies an explicit <strong>parent-child</strong> relationship for the selection.</p>
<p>The next few tutorials will cover in more detail the various <strong>combinators</strong>, <strong>pseudo-classes</strong>, and <strong>pseudo-elements</strong> that can be used for advanced CSS selection of HTML elements (there are more than 50 of them).</p>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://drafts.csswg.org/selectors-3/">CSS Selectors</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-inheritance-and-default-values//">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-specificity-advanced-css-selectors-part-2/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">Ok, styling rules can become very messy, very quickly if you are not clear in what you are doing. Always ensure you constructing your rules in a well ordered rather than <em>ad-hoc</em> manner.<a class="footnote-back" href="#fnref1">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/">Advanced CSS Selectors &#8211; Part 1</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS &#8211; Understanding Inheritance and Default Values</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-inheritance-and-default-values/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 22 Mar 2019 19:59:11 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css default values]]></category>
		<category><![CDATA[css inheritance]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3801</guid>

					<description><![CDATA[<p>Learn which CSS properties child elements inherit from their parents and what their default values are.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-inheritance-and-default-values/">CSS &#8211; Understanding Inheritance and Default Values</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>You’ve implicitly encountered inheritance and default values while working with CSS.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#inheritance">Inheritance</a></li>
<li><a href="#default-values">Default Values</a></li>
<li><a href="#table-of-inheritance-and-default-values">Table of Inheritance and Default Values</a></li>
<li><a href="#the-inherit-value">The ‘inherit’ Value</a></li>
<li><a href="#the-default-value">The ‘default’ Value</a></li>
<li><a href="#final-words">Final Words</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="inheritance">Inheritance</h2>
<p>When working with CSS, you probably noticed that styling like this:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb1-1" class="sourceLine" title="1"></a><span class="fu">.important</span> {
<a id="cb1-2" class="sourceLine" title="2"></a>  <span class="kw">font-size</span>: <span class="dv">32</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>When applied to HTML like this:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb2-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"important"</span><span class="kw">&gt;</span>
<a id="cb2-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;p&gt;</span>This is important!<span class="kw">&lt;/p&gt;</span>
<a id="cb2-3" class="sourceLine" title="3"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Results in output that looks like this:</p>
<div class="html-output">
<style>
  .x1-css-inheritance-important {
    font-size:32px;
  }
</style>
<div class="x1-css-inheritance-important">
<p>This is important!</p>
</div>
</div>
<p>This is because the <span class="html-tag">p</span> element <strong>inherits</strong> the <span class="css-property">font-size</span> property applied to its parent <span class="html-tag">div</span>.</p>
<p>Not all properties are inherited by child elements.</p>
<p>Consider the following CSS:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" title="1"></a><span class="fu">.important</span> {
<a id="cb3-2" class="sourceLine" title="2"></a>  <span class="kw">border</span>: <span class="dv">1</span><span class="dt">px</span> <span class="cn">red</span> <span class="dv">solid</span><span class="op">;</span>
<a id="cb3-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>When applied to the following HTML:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"important"</span><span class="kw">&gt;</span>
<a id="cb4-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;p&gt;</span>This is important!<span class="kw">&lt;/p&gt;</span>
<a id="cb4-3" class="sourceLine" title="3"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Results in the <span class="css-property">border</span> only applied to the <span class="html-tag">div</span> element and not the <span class="html-tag">p</span> element:</p>
<div class="html-output">
<style>
  .x2-css-inheritance-important {
    border:1px solid red;
  }
</style>
<div class="x2-css-inheritance-important">
<p>This is important!</p>
</div>
</div>
<p>If the <span class="html-tag">p</span> tag inherited the border property from the parent <span class="html-tag">div</span> tag, it would have looked like this:</p>
<div class="html-output">
<style>
  .x2-css-inheritance-important {
    border:1px solid red;
  }
</style>
<div class="x2-css-inheritance-important">
<p class="x2-css-inheritance-important">This is important!</p>
</div>
</div>
<p>Which is, probably, not what you want.</p>
<h2 id="default-values">Default Values</h2>
<p>When you write some HTML like:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" title="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb5-2" class="sourceLine" title="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb5-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb5-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;title&gt;</span>Hello World<span class="kw">&lt;/title&gt;</span>
<a id="cb5-5" class="sourceLine" title="5"></a>    <span class="kw">&lt;meta</span><span class="ot"> charset=</span><span class="st">"utf-8"</span>  <span class="kw">/&gt;</span>
<a id="cb5-6" class="sourceLine" title="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb5-7" class="sourceLine" title="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb5-8" class="sourceLine" title="8"></a>    <span class="kw">&lt;p&gt;</span>Hello World!<span class="kw">&lt;/p&gt;</span>
<a id="cb5-9" class="sourceLine" title="9"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb5-10" class="sourceLine" title="10"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>You see <strong>Hello World!</strong> displayed in the browser.</p>
<p>It is very likely that the font will be <strong>serif</strong> or <strong>sans serif</strong>, it will be 16px in size, the text will be <span class="css-value">black</span> on a <span class="css-value">white</span> background, and there is no border &#8211; and you didn’t have to style anything.</p>
<p>This is because every CSS property has a default value. The default value may be changed through inheritance or when you explicitly set the value.</p>
<h2 id="table-of-inheritance-and-default-values">Table of Inheritance and Default Values</h2>
<p>The following table shows which CSS properties (that we’ve seen) are inherited by child elements from their parents.</p>
<p>It also shows the default values for those CSS properties.</p>
<div class="p-note">
<p>Browser implementations sometimes set values other than what is defined in the CSS specification. Footnotes are given for many of the values and any alternate values given should be regarded as informative rather than absolute.</p>
</div>
<table style="margin-right: auto;">
<thead>
<tr class="header">
<th style="text-align: left;">CSS Property</th>
<th>Inherited</th>
<th>Default Value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">color</span></td>
<td><span class="green-text">Yes</span></td>
<td>Depends on the browser (usually <span class="css-value">black</span>)<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property" style="white-space: nowrap;">background-color</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">transparent</span><a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">padding</span></td>
<td><span class="red-text">No</span></td>
<td>See the individual properties</td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">padding-left</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">padding-right</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">padding-top</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">padding-bottom</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">margin</span></td>
<td><span class="red-text">No</span></td>
<td>See the individual properties</td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">margin-left</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">margin-right</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref8" class="footnote-ref" href="#fn8"><sup>8</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">margin-top</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref9" class="footnote-ref" href="#fn9"><sup>9</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">margin-bottom</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">0</span><a id="fnref10" class="footnote-ref" href="#fn10"><sup>10</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">border</span></td>
<td><span class="red-text">No</span></td>
<td>The border is <span class="css-value">transparent</span> and has a style of <span class="css-value">none</span></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">display</span></td>
<td><span class="red-text">No</span></td>
<td>Depends on the HTML element, but the most common are <span class="css-value">inline</span> and <span class="css-value">block</span><a id="fnref11" class="footnote-ref" href="#fn11"><sup>11</sup></a>.</td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">width</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">auto</span></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">height</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">auto</span></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">box-sizing</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">content-box</span></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">font-size</span></td>
<td><span class="green-text">Yes</span></td>
<td><span class="css-value">medium</span> (<em>usually</em> 16px)<a id="fnref12" class="footnote-ref" href="#fn12"><sup>12</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">font-family</span></td>
<td><span class="green-text">Yes</span></td>
<td>Depends on the browser</td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">font-weight</span></td>
<td><span class="green-text">Yes</span></td>
<td><span class="css-value">normal</span><a id="fnref13" class="footnote-ref" href="#fn13"><sup>13</sup></a></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">font-style</span></td>
<td><span class="green-text">Yes</span></td>
<td><span class="css-value">normal</span><a id="fnref14" class="footnote-ref" href="#fn14"><sup>14</sup></a></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">line-height</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">normal</span></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">text-align</span></td>
<td><span class="red-text">No</span></td>
<td>A <strong>nameless value</strong> that acts as ‘left’ if the text direction is left-to-right and ‘right’ if ‘direction’ is right-to-left.</td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">float</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">none</span></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><span class="css-property">clear</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">none</span></td>
</tr>
<tr class="even">
<td style="text-align: left;"><span class="css-property">content</span></td>
<td><span class="red-text">No</span></td>
<td><span class="css-value">normal</span></td>
</tr>
</tbody>
</table>
<h2 id="the-inherit-value">The ‘inherit’ Value</h2>
<p>You can force a child element to inherit its parent’s property by using the CSS value <span class="css-value">inherit</span>:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb6-1" class="sourceLine" title="1"></a><span class="fu">.important</span> {
<a id="cb6-2" class="sourceLine" title="2"></a>  <span class="kw">border</span>: <span class="dv">1</span><span class="dt">px</span> <span class="cn">red</span> <span class="dv">solid</span><span class="op">;</span>
<a id="cb6-3" class="sourceLine" title="3"></a>}
<a id="cb6-4" class="sourceLine" title="4"></a>
<a id="cb6-5" class="sourceLine" title="5"></a><span class="fu">.what-will-this-do</span> {
<a id="cb6-6" class="sourceLine" title="6"></a>  <span class="kw">border</span>: <span class="bu">inherit</span><span class="op">;</span>
<a id="cb6-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<p>When applied to the following HTML:</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb7-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"important"</span><span class="kw">&gt;</span>
<a id="cb7-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"what-will-this-do"</span><span class="kw">&gt;</span>This is important!<span class="kw">&lt;/p&gt;</span>
<a id="cb7-3" class="sourceLine" title="3"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Will cause the child element to inherit the parent’s <span class="css-property">border</span> property:</p>
<div class="html-output">
<style>
  .x3-css-inheritance-important {
    border:1px solid red;
  }
  .x3-what-will-this-do {
    border: inherit;
  }
</style>
<div class="x3-css-inheritance-important">
<p class="x3-what-will-this-do">This is important!</p>
</div>
</div>
<h2 id="the-default-value">The ‘default’ Value</h2>
<p>If you want to reset an element’s property to its default value, you can use the CSS value <span class="css-value">initial</span><a id="fnref15" class="footnote-ref" href="#fn15"><sup>15</sup></a>.</p>
<p>Consider the following styling:</p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" title="1"></a>p {
<a id="cb8-2" class="sourceLine" title="2"></a>  <span class="kw">color</span>: <span class="cn">red</span><span class="op">;</span>  
<a id="cb8-3" class="sourceLine" title="3"></a>}
<a id="cb8-4" class="sourceLine" title="4"></a><span class="fu">.default</span> {
<a id="cb8-5" class="sourceLine" title="5"></a>  <span class="kw">color</span>: initial<span class="op">;</span>
<a id="cb8-6" class="sourceLine" title="6"></a>}</code></pre>
</div>
<p>When applied to the following code:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb9-1" class="sourceLine" title="1"></a><span class="kw">&lt;p</span> <span class="kw">&gt;</span>This is some styled text!<span class="kw">&lt;/p&gt;</span>
<a id="cb9-2" class="sourceLine" title="2"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"default"</span><span class="kw">&gt;</span>This is some default styled text<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Results in the following:<a id="fnref16" class="footnote-ref" href="#fn16"><sup>16</sup></a></p>
<div class="html-output x4">
<style>
  .x4 p {
    color: red;
  }
  .x4 .x4-default {
    color: initial;
  }
</style>
<div>
<p>This is some styled text!</p>
<p class="x4-default">This is some default styled text</p>
</div>
</div>
<h2 id="final-words">Final Words</h2>
<p>Child elements may inherit CSS values from their parents &#8211; it depends on the specific CSS property.</p>
<p>All HTML elements have default styles applied to them. Some of these styles are determined by browser settings, others from the CSS specification.</p>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://www.w3.org/TR/html5/rendering.html">CSS Default Properties</a></li>
<li><a href="https://www.w3.org/TR/2011/REC-CSS2-20110607/propidx.html#q24.0">CSS Inheritance</a></li>
<li><a href="https://dxr.mozilla.org/mozilla-central/source/layout/style/res/html.css">Firefox’s Default Style Settings</a></li>
<li><a href="https://gist.github.com/ambidexterich/34828a904dd97dd2a345">Chrome’s Default Style Settings</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/comments-in-html-and-css/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/advanced-css-selectors-part-1/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">The &lt;mark&gt; tag has a default <span class="css-property">color</span> of <span class="css-value">black</span>. The &lt;a&gt; tag default color is defined by the browser &#8211; it is usually <span class="css-value">#0000EE</span> for an unvisited link, <span class="css-value">#551A8B</span> for a visited link, and <span class="css-value">#EE0000</span> for a link you are hovering over.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">The &lt;mark&gt; tag has a default <span class="css-property">background-color</span> of <span class="css-value">yellow</span>.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref6">↩</a></li>
<li id="fn7">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref7">↩</a></li>
<li id="fn8">This is true for all the HTML elements we have seen so far. Some HTML elements we haven’t seen may have a non-zero default value.<a class="footnote-back" href="#fnref8">↩</a></li>
<li id="fn9">This is true for most HTML elements we have seen so far. For &lt;p&gt; tags it is equal to the font-size. The &lt;h1&gt; &lt;through &lt;h6&gt; also have default values for top and bottom margin that are non-zero &#8211; the specific value depends on the tag.<a class="footnote-back" href="#fnref9">↩</a></li>
<li id="fn10">This is true for most HTML elements we have seen so far. For &lt;p&gt; tags it is equal to the font-size. The &lt;h1&gt; &lt;through &lt;h6&gt; also have default values for top and bottom margin that are non-zero &#8211; the specific value depends on the tag.<a class="footnote-back" href="#fnref10">↩</a></li>
<li id="fn11">The following tags have a default <span class="css-property">display</span> of <span class="css-value">none</span>: &lt;head&gt;, &lt;title&gt;, and &lt;meta&gt;. The following tags have a a default <span class="css-property">display</span> of <span class="css-value">block</span>: &lt;html&gt;, &lt;body&gt;, &lt;h1&gt; through &lt;h6&gt;, &lt;img&gt;, &lt;ol&gt;, &lt;ul&gt;, &lt;li&gt;, and &lt;p&gt;. The following tags have a a default <span class="css-property">display</span> of <span class="css-value">inline</span>: &lt;strong&gt;, &lt;em&gt;, &lt;i&gt;, &lt;mark&gt;, and &lt;a&gt;.<a class="footnote-back" href="#fnref11">↩</a></li>
<li id="fn12">The &lt;h1&gt; through &lt;h6&gt; tags have varying default font sizes. Assuming 16px as the default font size: H1 = 32px, H2 = 24px, H3 = 19px, H4 = 16px, H5 = 13px, and H6 = 11px.<a class="footnote-back" href="#fnref12">↩</a></li>
<li id="fn13">The &lt;h1&gt; through &lt;h6&gt; and the &lt;b&gt; and &lt;strong&gt; tags have a default <span class="css-property">font-weight</span> of <span class="css-value">bold</span>.<a class="footnote-back" href="#fnref13">↩</a></li>
<li id="fn14">The &lt;i&gt; and &lt;em&gt; tags have a default <span class="css-property">font-style</span> of <span class="css-value">italic</span>.<a class="footnote-back" href="#fnref14">↩</a></li>
<li id="fn15">Yes, it would make more sense if it was called <span class="css-value">default</span>, but the CSS specification calls it <span class="css-value">initial</span>.<a class="footnote-back" href="#fnref15">↩</a></li>
<li id="fn16">If your default <span class="css-property">color</span> (set in the browser) is <span class="css-value">red</span>, then both outputs will be red.<a class="footnote-back" href="#fnref16">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-inheritance-and-default-values/">CSS &#8211; Understanding Inheritance and Default Values</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Prevent People from Displaying Your Content on Their Web Pages Inside of a Frame</title>
		<link>https://complete-concrete-concise.com/web-tools/how-to-prevent-people-from-displaying-your-content-on-their-web-pages-inside-of-a-frame/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 06 Dec 2013 22:01:58 +0000</pubDate>
				<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[clickjacking]]></category>
		<category><![CDATA[frame]]></category>
		<category><![CDATA[framebusting]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[linking]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[prevent]]></category>
		<category><![CDATA[theft]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=3055</guid>

					<description><![CDATA[<p>Tired of having your bandwidth and content siphoned off by other websites? </p>
<p>The post <a href="https://complete-concrete-concise.com/web-tools/how-to-prevent-people-from-displaying-your-content-on-their-web-pages-inside-of-a-frame/">How to Prevent People from Displaying Your Content on Their Web Pages Inside of a Frame</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>This technique shows how to prevent a web site from displaying your content inside of a frame on their web page.</p>
<p>It looks something like this:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/12/in-frame-1-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/in-frame-1.png" alt="" border="0" class="centered"/></a></p>
<p>The section shaded in green is my content being displaying inside someone else&#8217;s web site. This is done by putting my content inside a <code>&lt;frame&gt;</code> or <code>&lt;iframe&gt;</code> tag.</p>
<div class="c2">
<p>If you are looking on how to deal with people who have copy and pasted your content on their web site, then see <a href="//complete-concrete-concise.com/blog/how-to-deal-with-content-theft">this article</a>.</p>
</div>
<p>This is easy to prevent, but it requires editing your <code>.htaccess</code> file.</p>
</div>
<h1>Why is this a problem?</h1>
<p>First, someone else is using your hard work this means a potential loss of traffic to your site.</p>
<div class="c1">
<p>I say &#8220;potential loss&#8221; of traffic because my experience is that these are usually very small and insignificant sites and they are not really taking away any traffic.</p>
</div>
<p>Second, someone can be benefitting from your work if they run ads on their site.</p>
<p>Third, it dilutes your content: you created it, you should keep control over it.</p>
<p>Finally, some sites doing this can be &#8220;clickjacking&#8221; using your site and content. Essentially, they use your content to drive traffic (or force downloads) by putting up invisible buttons. This type of behaviour can tarnish your web site&#8217;s reputation.</p>
<h1>Preventing Framing</h1>
<p><strong>1) Open</strong> your <code>.htaccess</code> file for editing.</p>
<div class="c1">
<p>Instructions for opening and editing <code>.htaccess</code> from <u>cPanel</u> can be found <a href="//complete-concrete-concise.com/web-tools/how-to-edit-htaccess-in-cpanel">here</a>.</p>
</div>
<p><strong>2) Add</strong> <u>one</u> of the following lines:</p>
<pre><code>Header append X-FRAME-OPTIONS "DENY"</code></pre>
<p>or</p>
<pre><code>Header append X-FRAME-OPTIONS "SAMEORIGIN"</code></pre>
<div class="c1">
<h3>How it Works</h3>
<p>Each line results in some additional information being sent with your web page. This information tells any compliant browser (and they should all be compliant now) how to deal with content inside a frame.</p>
<p><p>If it is &#8220;DENY&#8221;, then the browser will refuse to load the content into the frame.</p>
<p>If it is &#8220;SAMEORIGIN&#8221;, then the browser will only load content into the frame if the page with the frame and the page loaded into the frame are both on the same web site.</p>
<p>For complete details on this see <a href="http://tools.ietf.org/html/rfc7034">RFC 7034</a> (<strong>note:</strong> this is an external link). It also explains the option &#8220;ALLOW-FROM&#8221;.</p>
</div>
<div class="c3">
<p>Unless you use frames on your site, it is best to go with the first line.</p>
</div>
<p><strong>3) Save</strong> the <code>.htaccess</code> file.</p>
<h1>Other Options</h1>
<p>A commonly promoted option is something called a &#8220;Framebuster&#8221;. This is a piece of javascript code that tries to force your web page out of the frame. Unfortunately, it can be defeated if (1) the user has javascript turned off, or (2) the web site framing your content runs anti-framebuster code. You can read more <a href="http://en.wikipedia.org/wiki/Framekiller">here</a> (<strong>note:</strong> this is an external site).</p>
<p><p>The other common option is to add code to <code>.htaccess</code> to have the rewrite engine reload the page from the correct URL. I tried this technique first, but it didn&#8217;t work for me. The page I got this from is <a href="http://www.delphifaq.com/faq/web_publishing/f944.shtml">here</a> (<strong>note:</strong> this is an external site).</p>

<p>The post <a href="https://complete-concrete-concise.com/web-tools/how-to-prevent-people-from-displaying-your-content-on-their-web-pages-inside-of-a-frame/">How to Prevent People from Displaying Your Content on Their Web Pages Inside of a Frame</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Replacing the Toner Cartridge in a Brother HL-3140CW Printer</title>
		<link>https://complete-concrete-concise.com/blog/replacing-the-toner-cartridge-in-a-brother-hl-3140cw-printer/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 03 Dec 2013 15:14:42 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[hl-3140cw]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[toner]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=3050</guid>

					<description><![CDATA[<p>It's not difficult, but not entirely obvious either.</p>
<p>The post <a href="https://complete-concrete-concise.com/blog/replacing-the-toner-cartridge-in-a-brother-hl-3140cw-printer/">Replacing the Toner Cartridge in a Brother HL-3140CW Printer</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>Replacing the toner cartridge in the Brother HL-3140CW laser printer is not difficult, but it is not immediately obvious because the toner and drum assembly are joined together.</p>
</div>
<p><strong>1) Open</strong> the laser printer by lifting the the top part. There are no catches to unlock, so it is easy enough to open:</p>
<p><img fetchpriority="high" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-1.jpg" width="480" height="320" alt="" border="0" class="centered"/></p>
<p><strong>2) Remove</strong> the toner cartridge to replace. It will be one of the four cartridges shaded in green. The entire cartridge assembly lifts right out, there are no latches to unlock:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-2.jpg" width="480" height="320" alt="" border="0" class="centered"/></p>
<div class="c1">
<p>What you have in your hands is two pieces &#8211; the toner and the drum &#8211; even if it looks like just one part:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-3.jpg" width="480" height="193" alt="" border="0" class="centered"/></p>
<p>Disassembled, the two parts look like this:</p>
<p><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-4.jpg" width="480" height="418" alt="" border="0" class="centered"/></p>
<p>The part in blue is the drum. Be careful not to get fingerprints on the drum itself (the round cylinder at the end).</p>
<p>The part in green is the toner.</p>
</div>
<p><strong>3) Lay</strong> the toner and drum assembly on a clean, flat surface (preferably with a sheet of paper underneath in case some toner spills out) with the green tabs facing up:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-3.jpg" width="480" height="193" alt="" border="0" class="centered"/></p>
<p><strong>4) Press</strong> down on the green latch (bottom left, if you have oriented your assembly like the image above) to unlatch the toner from the drum and remove the toner:</p>
<p><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/12/3140-replace-toner-5.jpg" width="480" height="454" alt="" border="0" class="centered"/></p>
<p><strong>5) Insert</strong> the new toner into the drum assembly. It should fit and latch easily.</p>
<div class="c2">
<p>Before inserting the new toner, remember to gently tilt it from side to side to evenly distribute the toner inside.</p>
</div>
<p><strong>6) Slide</strong> the green slider on the drum assembly back and forth a few times. <strong>Remember</strong> to return it to its latched position.</p>
<p><strong>7) Reinsert</strong> the toner and drum assembly back into the printer. It should drop in easily.</p>
<p><strong>8) Close</strong> the printer an wait for it to go through its cycle.</p>

<p>The post <a href="https://complete-concrete-concise.com/blog/replacing-the-toner-cartridge-in-a-brother-hl-3140cw-printer/">Replacing the Toner Cartridge in a Brother HL-3140CW Printer</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ubuntu 13.04 &#8211; Command Line Basics: Editing Files</title>
		<link>https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-command-line-basics-editing-files/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 01 May 2013 03:12:06 +0000</pubDate>
				<category><![CDATA[Ubuntu 13.04]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[edit files]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[nano]]></category>
		<category><![CDATA[pico]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu 13.04]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2926</guid>

					<description><![CDATA[<p>The instructions are for Ubuntu 13.04, but should be the same for other versions.</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-command-line-basics-editing-files/">Ubuntu 13.04 &#8211; Command Line Basics: Editing Files</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>This tutorial is for Ubuntu 13.04.</p>
<p>It is probably the same for other versions of Ubuntu and (probably) most other Linux distributions, but no guarantee is made.</p>
<p>Detailed instructions for opening a command line / terminal can be found <a href="//complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-get-a-command-line-shell-or-terminal">here</a>.</div>
<p>When you work at the command line, from time to time, it may be necessary to edit files.</p>
<p>You can use an editor like <code>gedit</code> (the GUI based editor that comes with Ubuntu), however, by default, it will not permit you to edit system configuration files (which are likely the files you are trying to edit if you happen to be at the command line).</p>
<h1>Starting gedit with Administrator Privileges</h1>
<p>Enter the following command to start <code>gedit</code> with administrator privileges:</p>
<pre><code>sudo gedit</code></pre>
<div class="c3">
<p><strong>Note:</strong> when you type your password, nothing will happen on the screen. This is normal. As a security feature, Linux does not echo back any indication of the characters you are typing in.</p>
<p>You should only be prompted to enter a password if you have not used the <code>sudo</code> command in the last 15 minutes or so.</p>
</div>
<p>You can also append the file you wish to open to the command. This will cause <code>gedit</code> to automatically open the file. For example:</p>
<pre><code>sudo gedit history.log</code></pre>
<div class="c3">
<p><strong>Note:</strong> this will only work if the file is in the current directory. However, if you are at the command line, then you probably have navigated to the directory in question.</p>
</div>
<h1>Editing with nano</h1>
<p>Sometimes, you cannot use <code>gedit</code> because you have no graphical interface (GUI) &#8211; for example, you need to edit some x-server settings because you can&#8217;t get a graphical display, so you are exclusively at a command line.</p>
<p>While <code>vi</code> or one of its clones (<code>vim</code>, <code>elvis</code>, <code>nvi</code>, and <code>vile</code> to name some) tend to be the preferred text editor among Unix / Linux geeks &#8211; it is not the friendliest for casual (or one-off) users. The other major editor is <code>emacs</code>, but it is not installed by default in Ubuntu and it is not user friendly either.</p>
<p><code>nano</code> is a clone of the <code>pico</code> editor.</p>
<p>To launch <code>nano</code> enter the command:</p>
<pre><code>sudo nano</code></pre>
<div class="c3">
<p><strong>Note:</strong> It will also launch if you type in <code>pico</code></p>
<p>As with <code>gedit</code> you can append the name of the file you want to edit to the command.</p>
</div>
<h1>Using nano</h1>
<p><code>nano</code> is a simple editor that allows you to navigate through the text using the arrow keys on your keyboard.</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/03/ubuntu-12.04-command-line-basics-1.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/03/ubuntu-12.04-command-line-basics-1-thumb.png" alt="" border="0" class="centered" /></a></p>
<p>At the bottom of the screen, there are two lines (highlighted in blue) that display a number of common commands.</p>
<p>The caret (<code>^</code>) symbol means <code>Ctrl</code>, as in, <code>Ctrl + X</code>. This means, <em>&#8220;while holding down the <code>Ctrl</code> key, you press the other key as though you intend to type it&#8221;</em>.</p>
<div class="c2">
<p><strong>DO NOT</strong> press the Shift key because <code>Ctrl + Shift + X</code> is different from <code>Ctrl + X</code>.</p>
<p>It does <strong>NOT</strong> matter if your Caps Lock is on or off.</p>
</div>
<p>The most common commands you are likely to use are:</p>
<ul>
<li><code>^X</code> &#8211; (<code>Ctrl + X</code>) exit the editor</li>
<li><code>^O</code> &#8211; (<code>Ctrl + O</code>) save / write the contents of the editor</li>
<li><code>^R</code> &#8211; (<code>Ctrl + R</code>) open / read another file</li>
</ul>
<p>If you decide to browse through the help (<code>Ctrl + G</code>), then be aware of the following:</p>
<ul>
<li><code>^^</code> means <code>Ctrl + ^</code> not <code>Ctrl + Ctrl</code></li>
<li><code>M-</code> means the <code>Alt</code> key. The <code>Alt</code> key is used the same way the <code>Ctrl</code> key is: it is held down while another key is typed. For example: <code>M-\</code> means: <em>while holding down the </em><code>Alt</code><em> key, press the <code>\</code> key as though you intend to type it.</em></li>
<li>Some commands have parentheses around them, the parentheses are not to be typed. For example, <code>(M-X)</code> simply means <code>Alt + X</code> &#8211; the parentheses have nothing to do with it and should be ignored.</li>
</ul>

<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-command-line-basics-editing-files/">Ubuntu 13.04 &#8211; Command Line Basics: Editing Files</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ubuntu 13.04 &#8211; Basic Unity Interface / Desktop Tutorial</title>
		<link>https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-basic-unity-interface-desktop-tutorial/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 30 Apr 2013 07:26:35 +0000</pubDate>
				<category><![CDATA[Ubuntu 13.04]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[introductory]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu 13.04]]></category>
		<category><![CDATA[unity]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2917</guid>

					<description><![CDATA[<p>The basics of Unity are easy to pick up.</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-basic-unity-interface-desktop-tutorial/">Ubuntu 13.04 &#8211; Basic Unity Interface / Desktop Tutorial</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>This is a basic tutorial for the Unity Interface / Desktop which comes with Ubuntu 13.04 &#8211; it should help get you up and running.</p>
<p>Each new version of Unity (introduced in 11.04) improves on the functionality of the desktop.</p>
<div class="c2">
<p>This tutorial reflects the way I understand and use the Unity interface.</p>
</div>
</div>
<p>The Unity interface consists of four main parts:</p>
<ol>
<li>Panel</li>
<li>Launcher</li>
<li>Dash</li>
<li>HUD</li>
</ol>
<h2>The Panel</h2>
<p>The Panel is the strip at the top of the interface:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-1-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-1-thumb.png" alt="" border="0" class="centered"/></a></p>
<p>The menu bar that you are used to seeing near the top of an application&#8217;s window is now displayed in the panel:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-2-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-2-thumb.png" alt="" border="0" class="centered"/></a></a></p>
<p>There is a catch:</p>
<ol>
<li>The menus displayed in the Panel are <u>only</u> for the active (topmost) application window.</li>
<li>The menus are <u>only</u> displayed when you <u>hover</u> your mouse over the Panel, otherwise, the Panel is empty.</li>
<li>If a window is maximized (full screen), the buttons (icons) for minimize, maximize, and close are hidden unless you hover your mouse over the panel.</li>
</ol>
<p>This might seem like a step backward. Why hide the menu bar? Why make the user have to move the mouse all the way to the panel to access it? While it gives a little extra window space to the application, it is also inefficient – and this was the problem with Unity in Ubuntu 11.04 and 11.10.</p>
<p>Since Ubuntu 12.04, Unity has the HUD. The HUD makes mousing / navigating through menus obsolete (mostly).</p>
<p>Additional things displayed in the Panel include:</p>
<ul>
<li>the name of the active (topmost) application (green)</li>
<li>various indicators (blue)</li>
<li>the time (yellow)</li>
<li>the system menu (red)</li>
</ul>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-3-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-3-thumb.png" alt="" border="0" class="centered"/></a></p>
<h2>The Launcher</h2>
<div class="c1">
<p>Despite being the most prominent feature of the Unity interface, it is the one I use the least.</p>
</div>
<p>This is the panel of buttons on the left hand side of the screen:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-4-big.jpg" target="_blank"><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-4-thumb.jpg" width="480" height="360" alt="" border="0" class="centered"/></a></p>
<p>It serves 3 functions:</p>
<ol>
<li><strong>Application Launcher:</strong> clicking on an icon will launch the application associated with that icon. e.g. Clicking on the FireFox icon launches the FireFox browser.</p>
</li>
<li><strong>Visual indicator of running applications:</strong> any running application has its icon placed in the Launcher and an indicator showing its status.
<ol>
<li><strong>Two solid triangles:</strong> this is the active application (the one on top).</li>
<li><strong>Single solid triangle:</strong> the application is running, but does not have focus (is not on top).</li>
<li><strong>Single open triangle:</strong> the application is running in a different workspace (by default, Ubuntu 13.04 sets up only a single workspace. You can read how to enable workspaces <a href="//complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-enable-multiple-workspaces">here</a>.).</li>
</ol>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-launcher-2.jpg" alt="" border="0" class="centered" /></p>
<li><strong>Application Switcher:</strong> you can switch to an application (bring it to the front) by clicking on its icon in the Launcher.</li>
</ol>
<h3>Removing an Application from the Launcher</h3>
<div class="c1">
<p><strong>Note:</strong> removing an application from the Launcher does <u><strong>not</strong></u> uninstall the application.</p>
</div>
<p>The Launcher can become cluttered with applications (when you install an application using the Ubuntu Software Center, it is usually automatically placed in the Launcher).</p>
<p><strong>1) Right-click</strong> on the application you want to remove from the launcher. This will display a popup menu.</p>
<p><strong>2) Click</strong> on <u>Unlock from Launcher</u> in the popup menu:</p>
<p><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-5.jpg" width="480" height="203" alt="" border="0" class="centered"/></p>
<h3>Adding an Application to the Launcher</h3>
<p>Sometimes, an application is not added to the Launcher, or you had previously removed it.</p>
<p><strong>1) Start</strong> the application / program you want to add to the Launcher.</p>
<p><strong>2) Find</strong> the application&#8217;s icon in the Launcher.</p>
<p><strong>3) Right-click</strong> on the icon. This will display a popup menu.</p>
<p><strong>4) Click</strong> on <u>Lock to Launcher</u> to add the program to the Launcher:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-6.png" alt="" border="0" class="centered"/></p>
<div class="c2">
<p>In general, only the most commonly used applications should be in the launcher.</p>
</div>
<h2>Dash</h2>
<div class="c1">
<p>The Dash replaces searching through menu hierarchies for applications.</p>
<p>Like anything new, it feels all wrong, but, I found it very easy to pick up and now prefer it over the traditional menu navigating paradigm.</p>
</div>
<p>Instead or navigating a hierarchy of menus, Dash provides a query field in which you type the name of the application or document you want to open.</p>
<p>Using the Dash interface is very much like searching with Google &#8211; as you type in what you are looking for, Dash displays possible results.</p>
<div class="c2">
<p>I think the greatest strength of Dash is that you can navigate it completely via the keyboard, so you never alternate between typing and reaching for the mouse.</p>
</div>
<p>Dash is activated by either:</p>
<p><strong>1) Clicking</strong> on the Dash icon in the Launcher:</p>
<p><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-7.jpg" width="480" height="149" alt="" border="0" class="centered"/></p>
<p><strong>2) Tapping</strong> the <u>Windows</u> key on your keyboard</p>
<div class="c2">
<p><strong>Note:</strong> tapping the <u>Windows</u> keys means pressing it as though you intend to type it. It does not mean holding down the key (holding down the key does something else).</p>
<p>Ubuntu calls this the <u>Super</u> key</p>
</div>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-dash-2.jpg" alt="" border="0" class="centered" /></p>
<p>The Dash panel looks something like this (click for a larger image):</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-8-big.jpg" target="_blank"><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-unity-tutorial-8-thumb.jpg" width="480" height="327" alt="" border="0" class="centered"/></a></p>
<p>It is divided into upto 5 sections:</p>
<ol>
<li>
<p>The query field (<span class="i1">outlined in green</span>) is where the keyboard focus goes when you activate the Dash.</p>
<p>Type the name of the application you want to run, or document you want to open. As you type, Dash will update the list of applications and documents.</p>
<p>It has improved greatly since 11.04, if you type in <code>game</code> you will get <u>Mahjong</u>, <u>AisleRiot Solitaire</u> and <u>Freecell Solitaire</u>, and <u>Sudoku</u>.</p>
<p>I suspect it may still miss certain applications because they are not listed in the &#8220;obvious&#8221; way. For example, previous versions of Unity would not display <u>Sudoku</u> if you typed in <code>game</code> &#8211; you needed to type in <code>puzzle</code>.</p>
<p>If you type in <code>games</code> it will only display <u>AisleRiot Solitaire</u>, but none of the other games.</p>
</li>
<li>
<p>A list of the most recently used applications (<span class="i3">outlined in red</span>) is displayed. If you type in the query field, the list of applications is modified to match your search.
</p>
<p>You can use your mouse to select an application, or you can use the arrow keys to navigate to the desired application (and then press <code>Enter</code>. I like using the arrow keys because my hands don&#8217;t have to leave the keyboard.</p>
</li>
<li>
<p>A list of the most recent viewed documents (<span class="i2">outlined in blue</span>) is displayed. If you type in the query field, the list of documents is modified to match your search.</p>
<p>You can use your mouse or the arrow keys to navigate and select the desired document. I like using the arrow keys because my hands don&#8217;t have to leave the keyboard.</p>
</li>
<li>
<p>Relevant search results from Amazon (<span class="i4">outlined in yellow</span>) . As you type your query, it is sent to Amazon (anonymously via Ubuntu) and relevant results are displayed.</p>
<p>Many people find this intrusive and disable this feature. Instructions to disable Amazon search results are here.</p>
<p>I don&#8217;t have a problem with it, but wish it was more customizable. For instance, I don&#8217;t want Amazon search results in my main Dash panel. I don&#8217;t mind them if I am using the music lens or movie lens (explained in more detail below). Unfortunately, there is no way to selectively enable Amazon search results.</p>
</li>
<li>
<p>At the very bottom of the Dash (<span class="i2">shaded in green</span>) are a number of icons. These are &#8220;lenses&#8221;.  A lens is a specifically focussed (or themed) query. The five lenses at the bottom are:</p>
<ol>
<li>Dash lens: this is the default lens &#8211; it searches everything you are possibly connected to which includes your computer as well as any cloud services you use.</li>
<li>Applications lens: this focuses searches only within applications.</li>
<li>Folders and Documents lens: this focuses searches only on folders and documents.</li>
<li>Music lens: focuses search on music.</li>
<li>Photos Lens: focuses search on photos.</li>
<li>Video lens: focuses search on videos.</li>
</ol>
<p>You can navigate to the lenses using either the mouse or keyboard.</p>
<p>Typing <code>Ctrl + Tab</code> will navigate through the lenses.</p>
<div class="c2">
<p><strong>Note:</strong> typing <code>Ctrl + Tab</code> means, &#8220;While holding down the <code>Ctrl</code> key, press the <code>Tab</code> key as though you intend to type it.&#8221;</p>
</div>
<p>If you hold the <u>Windows</u> (Super) key down for a few seconds, a cheat sheet of commands will be displayed (click for larger image):</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-dash-4-big.jpg" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-dash-4-thumb.jpg" alt="" border="0" class="centered" /></a></p>
<div class="c2">
<p><strong>Note:</strong> the cheat sheet only appears if your screen resolution is 1024&#215;768 or greater.</p>
</div>
<h2>HUD</h2>
<div class="c1">
<p>The HUD was introduced in Ubuntu 12.04 and combined with Dash it provides a powerful way of interacting with your applications.</p>
<p>Just as Dash replaces navigating a hierarchy of menus to find applications and documents, HUD replaces navigating a hierarchy of menus in an application.</p>
<p>Like anything new, it feels all wrong, but, I found it very easy to pick up and now prefer it over the traditional menu navigating paradigm.</p>
</div>
<p>Instead or navigating a hierarchy of menus, HUD provides a query field in which you type the name of the action you want to perform with your applications.</p>
<p>Normally, to do something in a program you either use a keyboard shortcut (like <code>Ctrl+B</code> to bold text in a word processor), or you use the mouse to select an option from a menu or toolbar.</p>
<p>With HUD, you type in what you want to do. The HUD interface will then locate appropriate / matching menu entries and display them to you to select. Again, you can use the mouse to perform the selection or the arrow keys and the <u>Enter</u> key.</p>
<div class="c2">
<p>I think the greatest strength of HUD is that you can navigate it completely via the keyboard, so you never alternate between typing and reaching for the mouse.</p>
</div>
<p>The HUD is activated when you tap on the <u>Alt</u> key:</p>
<div class="c2">
<p><strong>Note:</strong> tapping the <u>Alt</u> keys means pressing it as though you intend to type it. It does not mean holding down the key.</p>
<p>If you hold the <code>Alt</code> key down for about 2 seconds, the application menu bar will display in the Panel. As soon as yo let go of the <code>Alt</code> key, it will disappear &#8211; thus encouraging use of the keyboard to select a menu option (e.g. <code>Alt + F</code> to open the <u>F</u>ile menu).</p>
</div>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-hud-1.jpg" alt="" border="0" class="centered" /></p>
<p>The HUD panel looks something like this:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-hud-2.jpg" alt="" border="0" class="centered" /></p>
<ol>
<li>
<p>The query field (<span class="i3">outlined in red</span>) is where you type the operation you want to perform in the application, e.g. <code>open</code>, <code>new</code>, <code>auto white balance</code>, etc.</p>
<p>This is where the focus goes when you activate the HUD.</p>
<p>As you type, a list of possible commands will be displayed below it. You can navigate those commands using the mouse and clicking to select or the keyboard (arrow keys) and pressing <u>Enter</u> to select. By default, the top command is always selected and will be executed if you press <u>Enter</u>. A nice thing is that you do not have to type the whole command.</p>
<div class="c1">
<p><strong>Note:</strong> if a command is not available (for example, it is greyed out), then it will not appear in the list of commands.</p>
<p>For example, if you have just opened GIMP without any image, it is not possible to perform image operations on it (like unsharp mask, or auto color enhance, etc). So if you type <code>unsharp</code> into the query field, you will not receive any options.</p>
<p>I think it would be better if the HUD somehow indicated that the operation is unavailable rather than just not showing it at all.</p>
</div>
</li>
<li>
<p>On the left, the icon (<span class="i1">outlined in green</span>) shows which application the command is for.</p>
<p>The HUD may display commands for other programs (not just the active one). This can be confusing if you are not paying attention.</p>
</li>
<li>
<p>Below the query field is a list of matching commands (<span class="i2">outlined in blue</span>.</p>
</li>
</ol>
<div class="c4">
<p><strong>Note:</strong> HUD may not work with all applications &#8211; it depends on how the menus in an application were coded. Prior to Ubuntu 13.04, LibreOffice was an application that did not work with the HUD (there was a patch available to make it work, though).</p>
</div>
<h2>Final Words</h2>
<p>Unity is a new way of interacting with the computer: instead of navigating a hierarchy of menus, you type what you want to do.</p>
<p>As an old timer (my first interactions with a computer were via a teletype), I never really liked the mouse / GUI way of doing things because it required me to take one hand off the keyboard. As a consequence, I have always configured shortcut keys to perform common tasks.</p>
<p>With Unity, I am able to keep my hands on the keyboard and easily perform the tasks I need. I still program my shortcut keys, but I know longer have to navigate through menus to find some lesser used operation.</p>
<p>Play with it. I think you will find it easy to learn. I have found it easier to adapt to than the Ribbon interface Microsoft introduced a few years ago.</p>
<p>I find the Dash and HUD work well when I am very familiar with the programs / applications I am working with and I know the command set.</p>
<p>I find the HUD awkward to work with when I am not familiar with an application. For example, perhaps I install Blender to try out some 3D graphics development. Not being familiar with Blender, it is very awkward to try typing commands into the HUD in the hope of finding the right one. This is definitely a case where being able to browse through a bunch of menus can be helpful.</p>
<p>Of course, I can always type <code>help</code> and hope a help file comes up.</p>
<p>It is with new or unfamiliar applications that I miss the menu bar at the top, but even if a menu bar was visible, there have been times when I could not find what I wanted and had to google to discover how it was named or where it was located.</p>

<h2>Additional Resources</h2>
<p>While these aren&#8217;t tutorials, they offer some insight into Canonical&#8217;s focus and direction (they are written by Mark Shuttleworth  – Canonical&#8217;s CEO):</p>
<p><a href="http://www.markshuttleworth.com/archives/939">Introducing the HUD. Say hello to the future of the menu.</a></p>
<p><a href="http://www.markshuttleworth.com/archives/717">Dash takes shape for 11.10 Unity</a> (note: the Dash panel has changed somewhat from the screen capture he presents)</p>
<p>This shows a side by side comparison between using the tradition menu driven way to perform a task and using HUD. While a number of commenters have complained that it isn&#8217;t an objective comparison, I think it shows very nicely the difference in working in both environments:</p>
<p><iframe loading="lazy" width="560" height="315" src="http://www.youtube.com/embed/lSkXgXZL7G4" frameborder="0" allowfullscreen></iframe></p>
<p>This is another video showing the HUD In action:</p>
<p><iframe loading="lazy" width="560" height="315" src="http://www.youtube.com/embed/w_WW-DHqR3c" frameborder="0" allowfullscreen></iframe></p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-basic-unity-interface-desktop-tutorial/">Ubuntu 13.04 &#8211; Basic Unity Interface / Desktop Tutorial</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ubuntu 13.04 &#8211; How to Display Hidden Files and Folders</title>
		<link>https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-display-hidden-files-and-folders/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 29 Apr 2013 11:33:26 +0000</pubDate>
				<category><![CDATA[Ubuntu 13.04]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[folders]]></category>
		<category><![CDATA[hidden]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[show]]></category>
		<category><![CDATA[ubuntu 13.04]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2902</guid>

					<description><![CDATA[<p>Learn how to display hidden files in Ubuntu 13.04 running the Unity Desktop and using the Nautilus file manager.</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-display-hidden-files-and-folders/">Ubuntu 13.04 &#8211; How to Display Hidden Files and Folders</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>This tutorial is for Ubuntu 13.04 running the Unity Desktop and using the Nautilus file manager &#8211; this is the default configuration for Ubuntu 13.04.</p>
<p>The instructions may be the same or similar for other versions but no guarantee is made.</p>
<div class="c2">
<p><strong>Note:</strong> for some reason, Nautilus has changed quite drastically in Ubuntu 13.04 from previous versions. Not sure, yet, if this is heavy Ubuntu customization or changes in Nautilus itself. On significant (minor?) change is that in the <u>About</u> dialog, it is now called <u>Files</u> &#8211; never mind that it shows up as <u>nautilus</u> in the process viewer.</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-show-hidden-files-0.png" alt="" border="0" class="centered"/></div>
</div>
<p><strong>1) Open</strong> the <u>Files</u> application:</p>
<p><strong>2) Tap</strong> the <code>Alt</code> key. <span class="i1">Note: tapping the <code>Alt</code> key, means pressing it as though you intend to type it. It does not mean holding the key down.</span> This will bring up the HUD:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-show-hidden-files-01.png" alt="" border="0" class="centered"/></p>
<p><strong>3) Type</strong> <u>preferences</u> into the HUD query field:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-show-hidden-files-1.png" alt="" border="0" class="centered"/></p>
<p><strong>4) Press</strong> the <u>Enter</u> key. This will open the <u>Preferences</u> dialog:</p>
<div class="c1">
<p><strong>Note:</strong> you can press the <u>Enter</u> key as soon as <u>Preferences</u> is the topmost displayed option.</p>
<p>You can also select <u>Preferences</u> by clicking on it with your mouse, or navigating to it using the keyboard arrow keys and pressing <u>Enter</u>.</p>
</div>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-show-hidden-files-2.png" alt="" border="0" class="centered"/></p>
<p><strong>5) Click</strong> on the <u>Show hidden and backup files</u> checkbox to enable it. <strong>Click</strong> on <u>Close</u></p>
<p>:<br />
<img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-show-hidden-files-3.png" alt="" border="0" class="centered"/></p>
<p><strong>6) Restart</strong> the <u>Files</u> application to enable the setting.</p>
<div class="c2">
<p>I think this is a bug because I would expect the changes to take place immediately after closing the <u>Preferences</u> dialog.</p>
</div>

<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-display-hidden-files-and-folders/">Ubuntu 13.04 &#8211; How to Display Hidden Files and Folders</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ubuntu 13.04 &#8211; How to Enable Multiple Workspaces</title>
		<link>https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-enable-multiple-workspaces/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 26 Apr 2013 13:58:20 +0000</pubDate>
				<category><![CDATA[Ubuntu 13.04]]></category>
		<category><![CDATA[enable]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ubuntu 13..04]]></category>
		<category><![CDATA[workspaces]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2850</guid>

					<description><![CDATA[<p>Ubuntu 13.04 set the number of workspaces to 1, learn how to up that number.</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-enable-multiple-workspaces/">Ubuntu 13.04 &#8211; How to Enable Multiple Workspaces</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>These instructions are for Ubuntu 13.04 running the Unity interface.</p>
<p>The instructions may be similar for other versions, but no guarantee is made.</p>
</div>
<div class="c2">
<p>An article on how to switch between workspaces can be found <a href="//complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-switch-between-workspaces">here</a>.</p>
</div>
<p>In Ubuntu 13.04, the number of workspaces was set to 1. This is probably the way most people use their computer anyway &#8211; a single workspace where all their application windows are open. However, some users (like me) like to have multiple workspaces because it allows for multiple full screen applications to be open simultaneously without overlapping.</p>
<p><strong>1) Tap</strong> the Windows (Super) key to open the Dash panel:</p>
<div class="c2">
<p><strong>Note:</strong> tapping the <u>Windows</u> keys means pressing it as though you intend to type it. It does not mean holding down the key (holding down the key does something else).</p>
<p>Ubuntu calls this the <u>Super</u> key</p>
</div>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-dash-2.jpg" alt="" border="0" class="centered" /></p>
<p><strong>2) Type</strong> <u>appearance</u> into the Dash search field:</p>
<p><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-enable-workspaces-1.jpg" width="480" height="257" alt="" border="0" class="centered"/></p>
<p><strong>3) Press</strong> the <u>Enter</u> key to launch the <u>Appearance</u> application:</p>
<div class="c2">
<p><strong>Note:</strong> pressing the <u>Enter</u> key will select the first Dash entry. If <u>Appearance</u> is not the first entry, then use the keyboard arrow keys or mouse to navigate to the appropriate icon.</p>
<p>If pressing <u>Enter</u> does not launch the Appearance management dialog, then click on the <u>Appearance</u> icon.</p>
</div>
<p><strong>4) Click</strong> on the <u>Behaviour</u> tab:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-enable-workspaces-2-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-enable-workspaces-2-thumb.png" alt="" border="0" class="centered"/></a></p>
<p><strong>5) Click</strong> on the <u>Enable workspaces</u> checkbox to enable workspaces:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-enable-workspaces-3-big.png" target="_blank"><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-enable-workspaces-3-thumb.png" alt="" border="0" class="centered"s/></a><br />
</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-enable-multiple-workspaces/">Ubuntu 13.04 &#8211; How to Enable Multiple Workspaces</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ubuntu 13.04 &#8211; How to Switch Between Workspaces</title>
		<link>https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-switch-between-workspaces/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 26 Apr 2013 13:57:48 +0000</pubDate>
				<category><![CDATA[Ubuntu 13.04]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[navigate]]></category>
		<category><![CDATA[ubuntu 13.04]]></category>
		<category><![CDATA[workspace]]></category>
		<category><![CDATA[workspaces]]></category>
		<guid isPermaLink="false">http://complete-concrete-concise.com/?p=2856</guid>

					<description><![CDATA[<p>These instructions are for Ubuntu 13.04 running the Unity Desktop. They may be similar or the same for other versions, but no guarantee is made. There are three ways to switch between workspaces. Your preference will depend on how you navigate your desktop. Using the Arrow Keys Press Ctrl + Alt + &#60;arrow key&#62; to [&#8230;]</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-switch-between-workspaces/">Ubuntu 13.04 &#8211; How to Switch Between Workspaces</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="c1">
<p>These instructions are for Ubuntu 13.04 running the Unity Desktop.</p>
<p>They may be similar or the same for other versions, but no guarantee is made.</p>
</div>
<p>There are three ways to switch between workspaces. Your preference will depend on how you navigate your desktop.</p>
<h1>Using the Arrow Keys</h1>
<p><strong>Press</strong> <code>Ctrl + Alt + <em>&lt;arrow key&gt;</em></code> to navigate between workspaces.</p>
<div class="c1">
<p><strong>Note:</strong> pressing <code>Ctrl + Alt + <em>&lt;arrow key&gt;</em></code> means, &#8220;while simultaneously holding down the <code>Ctrl</code> key and the <code>Alt</code> key, press an arrow key as though you intend to type it.&#8221;</p>
</div>
<p>There are a few things to be aware of:</p>
<ol>
<li>the arrow keys on the numeric keypad do not work &#8211; you have to use the dedicated arrow keys. Additionally, if <code>NumLock</code> is <u>on</u> some of the key presses will resize and reposition your application windows.</li>
<li>the default arrangement of the workspaces is a 2&#215;2 grid.</li>
<li>if a key press cannot navigate to a new workspace then nothing happens (for example, if you are in the first workspace, which is located in the top left corner, then pressing the <code>up</code> or <code>left</code> arrow key will do nothing).</li>
<li>if you do navigate to a new workspace, in the centre of the screen will be displayed a a small grid of the workspaces. See image below, click for the full size version.</li>
</ol>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-navigate-workspace-1-big.jpg" target="_blank"><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-navigate-workspace-1-thumb.jpg" width="480" height="233" alt="" border="0" class="centered"/></a></p>
<h1>Using the Windows (Super) Key</h1>
<p><strong>Press</strong> <code>Windows + S</code>.</p>
<div class="c1">
<p><strong>Note:</strong> pressing  <u>Windows</u> keys means, &#8220;while holding down the Windows (Super) key,  press the <code>S</code> key as though you intend to type it&#8221;.</p>
<p>Ubuntu calls the <code>Windows</code> key the <u>Super</u> key</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2012/04/ubuntu-12.04-basic-unity-tutorial-dash-2.jpg" alt="" border="0" class="centered" /></p>
</div>
<p>This will cause all the workspaces to be displayed simultaneously. See the image below, click for a full size version:</p>
<p><a href="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-navigate-workspace-2-big.jpg" target="_blank"><img loading="lazy" decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-navigate-workspace-2-thumb.jpg" width="480" height="360" alt="" border="0" class="centered"/></a></p>
<p>Things to be aware of:</p>
<ol>
<li>you can navigate the workspaces using the arrow keys. The selected workspace will be brighter and have a coloured border (by default an orange colour). You can go to the selected workspace by pressing the <u>Enter</u> key.</li>
<li>you can select a workspace by clicking on it with your mouse.</li>
<li>you can drag windows from one workspace to another using your mouse.</li>
</ol>
<h1>Clicking on the Workspace Switcher Icon</h1>
<p><strong>Click</strong> on the <u>Workspace Switcher</u> icon which is located near the bottom of the <u>Launcher</u> ribbon:</p>
<p><img decoding="async" src="//complete-concrete-concise.com/wp-content/uploads/2013/04/1304-navigate-workspace-3.png" alt="" border="0" class="centered"/></p>
<p>This will present the same workspace view as the <code>Windows + S</code> method. Navigation is exactly the same as for <code>Windows + S</code><br />
</p>
<p>The post <a href="https://complete-concrete-concise.com/ubuntu-2/ubuntu-13-04/ubuntu-13-04-how-to-switch-between-workspaces/">Ubuntu 13.04 &#8211; How to Switch Between Workspaces</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
