 
    
<?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>Tutorials Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/category/tutorials/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Sat, 18 Mar 2023 19:55:18 +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>Comments in HTML and CSS</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/comments-in-html-and-css/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 11 Feb 2019 15:36:32 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3789</guid>

					<description><![CDATA[<p>Comments help to document and explain your code to others and your future self.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/comments-in-html-and-css/">Comments in HTML and CSS</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>An important part of coding is documenting your code with comments</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#introduction-to-comments">Introduction to Comments</a></li>
<li><a href="#html-comments">HTML Comments</a></li>
<li><a href="#css-comments">CSS Comments</a></li>
<li><a href="#guidelines-for-writing-good-comments">Guidelines for Writing Good Comments</a></li>
<li><a href="#final-words">Final Words</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="introduction-to-comments">Introduction to Comments</h2>
<p>In a perfect world, code would be self documenting and as you read it from top to bottom you would perfectly understand its structure and behaviour.</p>
<p>In the real world &#8211; except for trivial code examples (the kind you fit in a dozen lines or less and can keep in your head) &#8211; understanding any significant piece of code takes considerable effort.</p>
<p>Comments are textual information that are added to the code to help document the code. Comments do not affect the behaviour of the code in any way and are ignored when the code is processed. Comments are there to help humans understand the code easier &#8211; but only if they are useful and accurate.</p>
<h2 id="html-comments">HTML Comments</h2>
<p>HTML comments begin with <code>&lt;!--</code> and end with <code>--&gt;</code>. In between those characters, you can have almost any type of text string you like and it can span multiple lines.</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb1-1" title="1"><span class="co">&lt;!--This is an HTML comment--&gt;</span></a>
<a class="sourceLine" id="cb1-2" title="2"></a>
<a class="sourceLine" id="cb1-3" title="3"><span class="co">&lt;!-- While a space is not necessary after</span></a>
<a class="sourceLine" id="cb1-4" title="4"><span class="co">     the opening characters, it does make it</span></a>
<a class="sourceLine" id="cb1-5" title="5"><span class="co">     easier to read and avoid certain problems --&gt;</span></a>
<a class="sourceLine" id="cb1-6" title="6"></a>
<a class="sourceLine" id="cb1-7" title="7"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb1-8" title="8"><span class="co">  You can also put the comment markers on</span></a>
<a class="sourceLine" id="cb1-9" title="9"><span class="co">  separate lines to make it a little neater.</span></a>
<a class="sourceLine" id="cb1-10" title="10"><span class="co">--&gt;</span></a>
<a class="sourceLine" id="cb1-11" title="11"></a>
<a class="sourceLine" id="cb1-12" title="12"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb1-13" title="13"><span class="co">  The HTML code inside this comment</span></a>
<a class="sourceLine" id="cb1-14" title="14"><span class="co">  will never be processed.</span></a>
<a class="sourceLine" id="cb1-15" title="15"></a>
<a class="sourceLine" id="cb1-16" title="16"><span class="co">  &lt;div&gt;</span></a>
<a class="sourceLine" id="cb1-17" title="17"><span class="co">    &lt;div&gt;</span></a>
<a class="sourceLine" id="cb1-18" title="18"><span class="co">      &lt;p&gt;A paragraph inside divs&lt;/p&gt;</span></a>
<a class="sourceLine" id="cb1-19" title="19"><span class="co">    &lt;/div&gt;</span></a>
<a class="sourceLine" id="cb1-20" title="20"><span class="co">  &lt;/div&gt;</span></a>
<a class="sourceLine" id="cb1-21" title="21"></a>
<a class="sourceLine" id="cb1-22" title="22"><span class="co">--&gt;</span></a></code></pre>
</div>
<p>The specification has a few rules regarding HTML comments:</p>
<ol class="incremental" type="1">
<li>the text must not start with the string <code>&gt;</code>,</li>
<li>nor start with the string <code>-&gt;</code>,</li>
<li>nor contain the strings <code>&lt;!--</code>, <code>--&gt;</code>, or <code>--!&gt;</code>, +</li>
<li>nor end with the string <code>&lt;!-</code></li>
</ol>
<p>Basically, as long as you don’t try to nest HTML comments inside HTML comments, you will be fine.</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb2-1" title="1"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="co">  &lt;!</span><span class="er">--</span><span class="co"> Nested comments are bad --&gt;</span></a>
<a class="sourceLine" id="cb2-3" title="3">--&gt;</a></code></pre>
</div>
<h2 id="css-comments">CSS Comments</h2>
<p>CSS comments begin with <code>/*</code> and end with <code>*/</code>. In between those characters you can have almost any types of text string you like and it can span multiple lines.</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb3-1" title="1"><span class="co">/*This is a CSS comment*/</span></a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="co">/* A leading space makes the comment</span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="co">   easier to read */</span></a>
<a class="sourceLine" id="cb3-5" title="5"></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="co">/*</span></a>
<a class="sourceLine" id="cb3-7" title="7"><span class="co">   You can also put the comment markers on</span></a>
<a class="sourceLine" id="cb3-8" title="8"><span class="co">   separate lines to make it a little neater.</span></a>
<a class="sourceLine" id="cb3-9" title="9"><span class="co">*/</span></a>
<a class="sourceLine" id="cb3-10" title="10"></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co">/*</span></a>
<a class="sourceLine" id="cb3-12" title="12"><span class="co">   The CSS code inside this comment</span></a>
<a class="sourceLine" id="cb3-13" title="13"><span class="co">   will never be processed.</span></a>
<a class="sourceLine" id="cb3-14" title="14"></a>
<a class="sourceLine" id="cb3-15" title="15"><span class="co">   .my-style {</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="co">     font-size: 24px;</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="co">     color: green;</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="co">     padding: 5px;</span></a>
<a class="sourceLine" id="cb3-19" title="19"><span class="co">     background: orange;</span></a>
<a class="sourceLine" id="cb3-20" title="20"><span class="co"> }</span></a>
<a class="sourceLine" id="cb3-21" title="21"></a>
<a class="sourceLine" id="cb3-22" title="22"><span class="co">*/</span>   </a></code></pre>
</div>
<p>As with HTML comments, you cannot nest CSS comments, so the first <code>*/</code> will always end the comment:</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">  /* Nested comments are bad */</span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="op">*</span>/</a></code></pre>
</div>
<h2 id="guidelines-for-writing-good-comments">Guidelines for Writing Good Comments</h2>
<p>Comments are written for two types of audience:</p>
<ol class="incremental" type="1">
<li>Your future self</li>
<li>Others</li>
</ol>
<p>Your future self (technically speaking) is somebody else because, 6 months or a year or 10 years in the future, you are unlikely to still be in the same frame of mind as when you wrote the code. So everything that was “obvious” when you were writing your code is no longer <em>obvious</em>.</p>
<p>Comments are written for two different purposes:</p>
<ol class="incremental" type="1">
<li>Documenting (<strong>what</strong> you are doing)</li>
<li>Clarifying (<strong>why</strong> you are doing it)</li>
</ol>
<p>Comments should answer the questions: <strong>what</strong> and <strong>why</strong>. The <strong>how</strong> is answered by the code itself because that is the implementation.</p>
<p>Let’s comment the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/your-first-webpage-hello-world/">first HTML program we encountered</a> in this tutorial series:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb5-1" title="1"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="co">  The following is not HTML, it is a document declaration.</span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="co">  It tells the browser what type of document it is.</span></a>
<a class="sourceLine" id="cb5-4" title="4"><span class="co">  It is case-insensitive. This declaration tells the</span></a>
<a class="sourceLine" id="cb5-5" title="5"><span class="co">  browser that all the code that follows is HTML5 code.</span></a>
<a class="sourceLine" id="cb5-6" title="6"><span class="co">--&gt;</span></a>
<a class="sourceLine" id="cb5-7" title="7"><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span></a>
<a class="sourceLine" id="cb5-8" title="8"></a>
<a class="sourceLine" id="cb5-9" title="9"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-10" title="10"><span class="co">  This is an HTML tag and marks the start of the HTML</span></a>
<a class="sourceLine" id="cb5-11" title="11"><span class="co">  document.</span></a>
<a class="sourceLine" id="cb5-12" title="12"></a>
<a class="sourceLine" id="cb5-13" title="13"><span class="co">  There is a corresponding closing tag &lt;/html&gt;. Most</span></a>
<a class="sourceLine" id="cb5-14" title="14"><span class="co">  HTML tags come in pairs.</span></a>
<a class="sourceLine" id="cb5-15" title="15"><span class="co">--&gt;</span></a>
<a class="sourceLine" id="cb5-16" title="16"><span class="kw">&lt;html&gt;</span></a>
<a class="sourceLine" id="cb5-17" title="17"></a>
<a class="sourceLine" id="cb5-18" title="18">  <span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-19" title="19"><span class="co">     The head section contains metadata (a fancy way of</span></a>
<a class="sourceLine" id="cb5-20" title="20"><span class="co">     saying information) about the document. Things which</span></a>
<a class="sourceLine" id="cb5-21" title="21"><span class="co">     are not part of the content of the document tend to</span></a>
<a class="sourceLine" id="cb5-22" title="22"><span class="co">     go in this section.</span></a>
<a class="sourceLine" id="cb5-23" title="23"></a>
<a class="sourceLine" id="cb5-24" title="24"><span class="co">     There is a corresponding closing tag &lt;/head&gt; which</span></a>
<a class="sourceLine" id="cb5-25" title="25"><span class="co">     marks the end of the head section</span></a>
<a class="sourceLine" id="cb5-26" title="26"><span class="co">  --&gt;</span></a>
<a class="sourceLine" id="cb5-27" title="27">  <span class="kw">&lt;head&gt;</span></a>
<a class="sourceLine" id="cb5-28" title="28"></a>
<a class="sourceLine" id="cb5-29" title="29">    <span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-30" title="30"><span class="co">      The title of the document. Typically appears in</span></a>
<a class="sourceLine" id="cb5-31" title="31"><span class="co">      the browser tab.</span></a>
<a class="sourceLine" id="cb5-32" title="32"><span class="co">    --&gt;</span></a>
<a class="sourceLine" id="cb5-33" title="33">    <span class="kw">&lt;title&gt;</span>Hello World<span class="kw">&lt;/title&gt;</span></a>
<a class="sourceLine" id="cb5-34" title="34"></a>
<a class="sourceLine" id="cb5-35" title="35">    <span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-36" title="36"><span class="co">      Use UTF-8 character encoding for this page. In</span></a>
<a class="sourceLine" id="cb5-37" title="37"><span class="co">      general, it should always be UTF-8.</span></a>
<a class="sourceLine" id="cb5-38" title="38"><span class="co">    --&gt;</span></a>
<a class="sourceLine" id="cb5-39" title="39">    <span class="kw">&lt;meta</span><span class="ot"> charset=</span><span class="st">&quot;utf-8&quot;</span>  <span class="kw">/&gt;</span></a>
<a class="sourceLine" id="cb5-40" title="40"></a>
<a class="sourceLine" id="cb5-41" title="41">  <span class="kw">&lt;/head&gt;</span> <span class="co">&lt;!-- The end of the head section --&gt;</span></a>
<a class="sourceLine" id="cb5-42" title="42"></a>
<a class="sourceLine" id="cb5-43" title="43">  <span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-44" title="44"><span class="co">    The body section contains the content that is</span></a>
<a class="sourceLine" id="cb5-45" title="45"><span class="co">    displayed in the web browser.</span></a>
<a class="sourceLine" id="cb5-46" title="46"></a>
<a class="sourceLine" id="cb5-47" title="47"><span class="co">    There is a corresponding closing tag &lt;/body&gt; which</span></a>
<a class="sourceLine" id="cb5-48" title="48"><span class="co">    marks the end of the body section.</span></a>
<a class="sourceLine" id="cb5-49" title="49"><span class="co">  --&gt;</span></a>
<a class="sourceLine" id="cb5-50" title="50">  <span class="kw">&lt;body&gt;</span></a>
<a class="sourceLine" id="cb5-51" title="51"></a>
<a class="sourceLine" id="cb5-52" title="52">    <span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb5-53" title="53"><span class="co">      Content is, generally, contained between paragraph</span></a>
<a class="sourceLine" id="cb5-54" title="54"><span class="co">      tags.</span></a>
<a class="sourceLine" id="cb5-55" title="55"><span class="co">    --&gt;</span></a>
<a class="sourceLine" id="cb5-56" title="56">    <span class="kw">&lt;p&gt;</span>Hello World!<span class="kw">&lt;/p&gt;</span></a>
<a class="sourceLine" id="cb5-57" title="57"></a>
<a class="sourceLine" id="cb5-58" title="58">  <span class="kw">&lt;/body&gt;</span> <span class="co">&lt;!-- The end of the body section --&gt;</span></a>
<a class="sourceLine" id="cb5-59" title="59"><span class="kw">&lt;/html&gt;</span> <span class="co">&lt;!-- The end of the HTML document --&gt;</span></a></code></pre>
</div>
<p>In general, you shouldn’t comment as extensively as I did in the example above &#8211; but for a tutorial it is fine.</p>
<p>When you are learning, it is a good idea to comment freely &#8211; explain what you are doing and why you are doing it. As your knowledge develops, you will find yourself documenting less and less.</p>
<p>Your comments should document why you are doing something. For example, you might have a requirement for a particular type of webpage, you could embed the webpage description as a comment:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb6-1" title="1"><span class="co">&lt;!-- This is a page with a single column layout that has</span></a>
<a class="sourceLine" id="cb6-2" title="2"><span class="co">     the following general structure:</span></a>
<a class="sourceLine" id="cb6-3" title="3"></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="co">     Header</span></a>
<a class="sourceLine" id="cb6-5" title="5"><span class="co">     Navbar</span></a>
<a class="sourceLine" id="cb6-6" title="6"><span class="co">     body of articles</span></a>
<a class="sourceLine" id="cb6-7" title="7"><span class="co">     Footer</span></a>
<a class="sourceLine" id="cb6-8" title="8"></a>
<a class="sourceLine" id="cb6-9" title="9"><span class="co">     The body has a width of 960px and is centered on the</span></a>
<a class="sourceLine" id="cb6-10" title="10"><span class="co">     page.</span></a>
<a class="sourceLine" id="cb6-11" title="11"></a>
<a class="sourceLine" id="cb6-12" title="12"><span class="co">     Each article in the body is a card which fits the full</span></a>
<a class="sourceLine" id="cb6-13" title="13"><span class="co">     width of the body less 35px padding on the left and</span></a>
<a class="sourceLine" id="cb6-14" title="14"><span class="co">     right side.</span></a>
<a class="sourceLine" id="cb6-15" title="15"></a>
<a class="sourceLine" id="cb6-16" title="16"><span class="co">     Each card consists of an image with a 16:9 aspect</span></a>
<a class="sourceLine" id="cb6-17" title="17"><span class="co">     ratio, a title with a font-size of 24px, followed</span></a>
<a class="sourceLine" id="cb6-18" title="18"><span class="co">     by a byline at 12px and a published date (also 12px)</span></a>
<a class="sourceLine" id="cb6-19" title="19"><span class="co">     The text content of the card has a font size of 16px.</span></a>
<a class="sourceLine" id="cb6-20" title="20"><span class="co">--&gt;</span></a></code></pre>
</div>
<p>Of course, this information could be in an external design document instead of the webpage.</p>
<p>The big problem is maintaining the code comments up to date. You have to be diligent to ensure that you update the comments when making changes to the code that don’t do what the comments say.</p>
<p>I recommend you comment freely as you learn to develop. Comment what you have learned:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb7-1" title="1"><span class="co">&lt;!--</span></a>
<a class="sourceLine" id="cb7-2" title="2"><span class="co">  There are two kinds of HTML lists:</span></a>
<a class="sourceLine" id="cb7-3" title="3"><span class="co">  - ordered &lt;ol&gt; and</span></a>
<a class="sourceLine" id="cb7-4" title="4"><span class="co">  - unordered &lt;ul&gt;.</span></a>
<a class="sourceLine" id="cb7-5" title="5"></a>
<a class="sourceLine" id="cb7-6" title="6"><span class="co">  List can take and attribute called &#39;reversed&#39; todo</span></a>
<a class="sourceLine" id="cb7-7" title="7"><span class="co">  display the list in reverse order.</span></a>
<a class="sourceLine" id="cb7-8" title="8"><span class="co">--&gt;</span></a>
<a class="sourceLine" id="cb7-9" title="9"></a>
<a class="sourceLine" id="cb7-10" title="10"><span class="kw">&lt;p&gt;</span>Normal list ordering:<span class="kw">&lt;/p&gt;</span></a>
<a class="sourceLine" id="cb7-11" title="11"><span class="kw">&lt;ol&gt;</span></a>
<a class="sourceLine" id="cb7-12" title="12">  <span class="kw">&lt;li&gt;</span>Item one<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-13" title="13">  <span class="kw">&lt;li&gt;</span>Item two<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-14" title="14">  <span class="kw">&lt;li&gt;</span>Item three<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-15" title="15"><span class="kw">&lt;/ol&gt;</span></a>
<a class="sourceLine" id="cb7-16" title="16"></a>
<a class="sourceLine" id="cb7-17" title="17"><span class="kw">&lt;p&gt;</span>Reversed list ordering:<span class="kw">&lt;/p&gt;</span></a>
<a class="sourceLine" id="cb7-18" title="18"><span class="kw">&lt;ol</span><span class="ot"> reversed</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb7-19" title="19">  <span class="kw">&lt;li&gt;</span>Item one<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-20" title="20">  <span class="kw">&lt;li&gt;</span>Item two<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-21" title="21">  <span class="kw">&lt;li&gt;</span>Item three<span class="kw">&lt;/li&gt;</span></a>
<a class="sourceLine" id="cb7-22" title="22"><span class="kw">&lt;/ol&gt;</span></a></code></pre>
</div>
<p>Eventually, you will stop writing mundane comments.</p>
<p>You should avoid commenting what is obvious from reading the code because it adds nothing to the information:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb8-1" title="1"><span class="fu">.header</span> {</a>
<a class="sourceLine" id="cb8-2" title="2">  <span class="co">/* set the background color to blue */</span></a>
<a class="sourceLine" id="cb8-3" title="3">  <span class="kw">background-color</span>: <span class="cn">blue</span><span class="op">;</span></a>
<a class="sourceLine" id="cb8-4" title="4">}</a></code></pre>
</div>
<p>But you can document specific requirements:<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb9-1" title="1"><span class="fu">.header</span> {</a>
<a class="sourceLine" id="cb9-2" title="2">  <span class="kw">background-color</span>: <span class="cn">#1DA1F2</span><span class="op">;</span> <span class="co">/* Twitter blue */</span></a>
<a class="sourceLine" id="cb9-3" title="3">}</a></code></pre>
</div>
<p>One use of comments is to structure your code:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb10-1" title="1"><span class="co">/* Global */</span></a>
<a class="sourceLine" id="cb10-2" title="2"></a>
<a class="sourceLine" id="cb10-3" title="3"></a>
<a class="sourceLine" id="cb10-4" title="4"><span class="co">/* Header */</span></a>
<a class="sourceLine" id="cb10-5" title="5"></a>
<a class="sourceLine" id="cb10-6" title="6"></a>
<a class="sourceLine" id="cb10-7" title="7"><span class="co">/* Content */</span></a>
<a class="sourceLine" id="cb10-8" title="8"></a>
<a class="sourceLine" id="cb10-9" title="9"></a>
<a class="sourceLine" id="cb10-10" title="10"><span class="co">/* Footer */</span></a></code></pre>
</div>
<p>Unfortunately, your code won’t always cooperate to break down into such nice clear categories.</p>
<h2 id="final-words">Final Words</h2>
<ol class="incremental" type="1">
<li>Comment your code freely.</li>
<li>Don’t comment anything that is obvious.</li>
<li>You can explain <strong>what</strong> you are doing.</li>
<li>You can explain <strong>why</strong> you are doing something.</li>
<li>Don’t explain <strong>how</strong> how you are doing something because that is the code itself.</li>
<li>Keep your comments up to date (in general, you should avoid comments that could be rendered obsolete)</li>
</ol>
<h2 id="references">References</h2>
<ol class="incremental" type="1">
<li><a href="https://html.spec.whatwg.org/multipage/syntax.html#comments">HTML comments</a></li>
<li><a href="https://www.w3.org/TR/CSS21/syndata.html#comments">CSS comments</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-inheritance-and-default-values/">Next</a></p>
</div>
<div class="clear">
</div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">
<p><a href="https://about.twitter.com/content/dam/about-twitter/company/brand-resources/en_us/Twitter_Brand_Guidelines_V2_0.pdf">Read more about Twitter’s brand requirements</a>. Many organizations and companies have very specific rules regarding the use of colours or fonts or any other aspects that are associated with their brand.<a href="#fnref1" class="footnote-back">↩</a></p>
</li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/comments-in-html-and-css/">Comments in HTML and CSS</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A Quick Introduction to Two Development Tools Built into your Browser</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 05 Feb 2019 18:33:44 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[inspect element]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[view page source]]></category>
		<category><![CDATA[view source]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3778</guid>

					<description><![CDATA[<p>Every modern browser has a number of web inspection and development tools built in. </p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/">A Quick Introduction to Two Development Tools Built into your Browser</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
<p>Using a text editor for writing code and a browser for viewing the results works well. However, you can increase your productivity by using two of the tools built into modern browsers:</p>
<ol class="incremental" type="1">
<li><strong>View Page Source</strong> and</li>
<li><strong>Inspect Element</strong></li>
</ol>
<p>Every modern browser has a number of web inspection and development tools built in. While it is beyond the scope of this article to cover everything in detail, I can still point you in the right direction and you can learn as you go along. You won’t use all the features and &#8211; depending on what you are doing &#8211; will focus on a small subset of the available features.</p>
</div>
<h2 id="contents">Contents</h2>
<ol class="incremental" type="1">
<li><a href="#overview">Overview</a></li>
<li><a href="#firefox">FireFox</a></li>
<li><a href="#chrome">Chrome</a></li>
<li><a href="#edge">Edge</a></li>
<li><a href="#view-page-source">View Page Source</a></li>
<li><a href="#inspect-element">Inspect Element</a>
<ol class="incremental" type="1">
<li><a href="#html-elements">HTML Elements</a></li>
<li><a href="#css-styles">CSS Styles</a></li>
<li><a href="#experimenting">Experimenting</a></li>
</ol>
</li>
<li><a href="#final-comments">Final Comments</a></li>
</ol>
<h2 id="overview">Overview</h2>
<p>The tools vary a little from browser to browser, but the basic functionality is the same.</p>
<p>Right clicking on a webpage will bring up a menu with options. Depending on where you right-click, some options may not be available.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></p>
<p>Below are 3 examples of the right-click menu from various browsers in January 2019:</p>
<h3 id="firefox">FireFox</h3>
<p><img fetchpriority="high" decoding="async" width="600" height="544" class="aligncenter size-full wp-image-3781" src="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-chrome-min.jpg" alt="Firefox right-click menu" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-chrome-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-chrome-min-300x272.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<h3 id="chrome">Chrome</h3>
<p><img decoding="async" width="600" height="544" class="aligncenter size-full wp-image-3783" src="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-ff-min.jpg" alt="Chrome right-click menu" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-ff-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-ff-min-300x272.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<h3 id="edge">Edge</h3>
<p><img decoding="async" width="600" height="544" class="aligncenter size-full wp-image-3782" src="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-edge-min.jpg" alt="Edge right-click menu" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-edge-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-edge-min-300x272.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<h2 id="view-page-source">View Page Source</h2>
<p>Depending on the browser being used, the name might vary a bit, but it will probably have the word <strong>source</strong> in it.</p>
<p>When you select this menu item, it will open a new<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a> tab and display the HTML code of the page. This is a good way for you to inspect the actual HTML code making up the page or to print it out.</p>
<p>Selecting <strong>View Page Source</strong> on the <a href="https://complete-concrete-concise.com/sample/32-float.html">previous example page</a> in Firefox 64 looks something like this:<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></p>
<p><img loading="lazy" decoding="async" width="600" height="723" class="aligncenter size-full wp-image-3784" src="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-view-source.png" alt="Sample of View Page Source screenshot" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-view-source.png 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-view-source-249x300.png 249w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<h2 id="inspect-element">Inspect Element</h2>
<p><strong>Inspect Element</strong> offers a wealth of features to you &#8211; well beyond the scope of this article to explore &#8211; but feel free to explore on your own.</p>
<p>You don’t have to worry about damaging the web page or accidentally overwriting your code because browsers cannot modify the source files &#8211; only what is being displayed. A fresh reload overwrites any changes you have made.</p>
<p>Depending on the browser being used, the name might vary a bit, but it will probably have the word <strong>Inspect</strong> in it.</p>
<p>Your browser will split its display window and show the webpage in one section and the HTML and other information in another section. It will go to the location in the HTML source that chose to inspect.</p>
<p>Selecting <strong>Inspect Element</strong> on the <a href="https://complete-concrete-concise.com/sample/32-float.html">previous example page</a> in Firefox 64 looks something like this:<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></p>
<p><a href="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min.jpg"><img loading="lazy" decoding="async" width="1060" height="780" class="aligncenter size-full wp-image-3780" src="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min.jpg" alt="Sample Inspect Element screenshot" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min.jpg 1060w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min-300x221.jpg 300w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min-768x565.jpg 768w, https://complete-concrete-concise.com/wp-content/uploads/2019/02/33-inspect-element-min-1024x754.jpg 1024w" sizes="auto, (max-width: 1060px) 100vw, 1060px" /></a></p>
<h3 id="html-elements">HTML Elements</h3>
<p>One of the inspector panes should display the HTML source code &#8211; shaded in red in the image above.</p>
<ol class="incremental" type="1">
<li>As you move your mouse over the HTML elements, you will notice that parts of the webpage get shaded. This shows you which part of the webpage this element affects.</li>
<li>You can left-click on the little triangles found on the left-hand side to expand elements and inspect their sub elements.</li>
<li>Right-clicking on an element will bring up a menu with various options. These often include: edit as HTML and delete element. (don’t worry about damaging your source code, any changes you make in the Element Inspector are <strong>not</strong> permanent &#8211; you can always reload the page to get back to the original).</li>
</ol>
<h3 id="css-styles">CSS Styles</h3>
<p>Another inspector pane should display the CSS styles being applied to the selected element &#8211; shaded in green in the image above.</p>
<ol class="incremental" type="1">
<li>You can disable a particular style by unticking the checkbox.</li>
<li>You can edit the value of a CSS attribute by right-clicking it.</li>
<li>You can add more CSS attributes by right-clicking just after the last CSS style element.</li>
</ol>
<h3 id="experimenting">Experimenting</h3>
<p>There are many options available and it is impossible to cover all of them here. However, feel free to experiment and use a search engine to research the various features.</p>
<p>In general, it should be fairly self-obvious what things are doing. At the moment, you should restrict yourself to just the HTML source and CSS styles. You are free to explore further.</p>
<h2 id="final-comments">Final Comments</h2>
<p>The more you play, work, and practice with these tools, the more familiar they will become and the easier they will be to use.</p>
<p>You are likely to only use a small subset of the features available in <strong>Inspect Element</strong>.</p>
<p>If you use this to inspect live websites, you will &#8211; very likely &#8211; find they are much more complicated than what you have learned so far. Don’t worry about it.</p>
<p>Many websites are built around something called a CMS (Content Management System) &#8211; like WordPress. Content Management Systems automate a lot of things for you and often do many extra things. While the output of a CMS is HTML + CSS, the backend relies on other languages to generate the HTML + CSS displayed in the browser. You still have to be able to create the HTML and CSS and then (programmatically) instruct the CMS when and how to send it to the browser. As a someone learning about web development and starting out with fundamentals of HTML and CSS, you don’t need to worry about all that.</p>
<p>Another thing many websites include is JavaScript code &#8211; which you haven’t seen either.</p>
<p>Focus on getting the fundamentals down and writing clean, well structured HTML and CSS first before worrying about how to integrate it with a CMS or using JavaScript on your pages.</p>
<p>&nbsp;</p>
<section class="footnotes">
<hr>
<ol>
<li id="fn1">This usually happens when you click on an image or video. Just right-click somewhere else on the webpage.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">Depending on your browser (or browser settings) it might open in your current tab instead.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">Different browsers and browser versions may display things slightly differently.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">Different browsers and browser versions may display things slightly differently.<a class="footnote-back" href="#fnref4">↩</a></li>
</ol>
</section>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/comments-in-html-and-css/">Next</a></p>
</div>
<div class="clear"></div>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/">A Quick Introduction to Two Development Tools Built into your Browser</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS &#8211; A More Advanced Float Example: Part 3</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 18:51:51 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3765</guid>

					<description><![CDATA[<p>A detailed walk through the completed code.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">CSS &#8211; A More Advanced Float Example: 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>A detailed walk through the code.</p>
</div>
<h2>Contents</h2>
<ol class="incremental" type="1">
<li><a href="#the-final-page">The Final Page</a></li>
<li><a href="#source-code">Source Code</a></li>
<li><a href="#detailed-code-walkthrough">Detailed Code Walkthrough</a>
<ol class="incremental" type="1">
<li><a href="#setting-some-page-level-defaults">Setting Some Page Level Defaults</a></li>
<li><a href="#the-highest-level-structure">The Highest Level Structure</a></li>
<li><a href="#the-wrapper">The Wrapper</a></li>
<li><a href="#the-title">The Title</a></li>
<li><a href="#the-navigation-bar">The Navigation Bar</a></li>
<li><a href="#the-dark-box">The Dark Box</a></li>
<li><a href="#the-content">The Content</a></li>
<li><a href="#the-column-left">The column-left</a></li>
<li><a href="#the-column-middle">The column-middle</a></li>
<li><a href="#the-column-right">The column-right</a></li>
<li><a href="#the-card">The card</a></li>
<li><a href="#the-footer">The footer</a></li>
</ol>
</li>
<li><a href="#final-thoughts">Final Thoughts</a></li>
<li><a href="#image-credits">Image Credits</a></li>
</ol>
<h2 id="the-final-page">The Final Page</h2>
<p>You can see the finished page <a href="https://complete-concrete-concise.com/sample/32-float.html">here</a>.</p>
<p>It is best viewed in a browser window that is 960px wide or larger.</p>
<h2 id="source-code">Source Code</h2>
<div id="cb1" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb1-1" class="sourceLine" title="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb1-2" class="sourceLine" title="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb1-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb1-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;title&gt;</span>Clone Page<span class="kw">&lt;/title&gt;</span>
<a id="cb1-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="cb1-6" class="sourceLine" title="6"></a>
<a id="cb1-7" class="sourceLine" title="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb1-8" class="sourceLine" title="8"></a>
<a id="cb1-9" class="sourceLine" title="9"></a>      <span class="op">*</span> {
<a id="cb1-10" class="sourceLine" title="10"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span><span class="op">;</span>
<a id="cb1-11" class="sourceLine" title="11"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span><span class="op">;</span>
<a id="cb1-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="cb1-13" class="sourceLine" title="13"></a>      }
<a id="cb1-14" class="sourceLine" title="14"></a>
<a id="cb1-15" class="sourceLine" title="15"></a>      img {
<a id="cb1-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="cb1-17" class="sourceLine" title="17"></a>      }
<a id="cb1-18" class="sourceLine" title="18"></a>
<a id="cb1-19" class="sourceLine" title="19"></a>      <span class="pp">#wrapper</span> {
<a id="cb1-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="cb1-21" class="sourceLine" title="21"></a>        <span class="kw">margin</span>: <span class="bu">auto</span><span class="op">;</span>
<a id="cb1-22" class="sourceLine" title="22"></a>      }
<a id="cb1-23" class="sourceLine" title="23"></a>
<a id="cb1-24" class="sourceLine" title="24"></a>      <span class="pp">#title</span> {
<a id="cb1-25" class="sourceLine" title="25"></a>        <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-26" class="sourceLine" title="26"></a>        <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb1-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="cb1-28" class="sourceLine" title="28"></a>      }
<a id="cb1-29" class="sourceLine" title="29"></a>
<a id="cb1-30" class="sourceLine" title="30"></a>      <span class="pp">#site-name</span> {
<a id="cb1-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="cb1-32" class="sourceLine" title="32"></a>        <span class="kw">font-weight</span>: <span class="dv">bold</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="pp">#login</span> {
<a id="cb1-36" class="sourceLine" title="36"></a>        <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb1-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="cb1-38" class="sourceLine" title="38"></a>        <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb1-39" class="sourceLine" title="39"></a>      }
<a id="cb1-40" class="sourceLine" title="40"></a>
<a id="cb1-41" class="sourceLine" title="41"></a>      <span class="pp">#search</span> {
<a id="cb1-42" class="sourceLine" title="42"></a>        <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb1-43" class="sourceLine" title="43"></a>        <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb1-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="cb1-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="cb1-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="cb1-47" class="sourceLine" title="47"></a>      }
<a id="cb1-48" class="sourceLine" title="48"></a>
<a id="cb1-49" class="sourceLine" title="49"></a>      <span class="pp">#navbar</span> {
<a id="cb1-50" class="sourceLine" title="50"></a>        <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb1-51" class="sourceLine" title="51"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-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="cb1-53" class="sourceLine" title="53"></a>      }
<a id="cb1-54" class="sourceLine" title="54"></a>
<a id="cb1-55" class="sourceLine" title="55"></a>      <span class="pp">#darkbox</span> {
<a id="cb1-56" class="sourceLine" title="56"></a>        <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb1-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="cb1-58" class="sourceLine" title="58"></a>      }
<a id="cb1-59" class="sourceLine" title="59"></a>
<a id="cb1-60" class="sourceLine" title="60"></a>      <span class="pp">#content</span> {
<a id="cb1-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="cb1-62" class="sourceLine" title="62"></a>      }
<a id="cb1-63" class="sourceLine" title="63"></a>
<a id="cb1-64" class="sourceLine" title="64"></a>      <span class="pp">#popular</span> {
<a id="cb1-65" class="sourceLine" title="65"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-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="cb1-67" class="sourceLine" title="67"></a>        <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb1-68" class="sourceLine" title="68"></a>      }
<a id="cb1-69" class="sourceLine" title="69"></a>
<a id="cb1-70" class="sourceLine" title="70"></a>      <span class="pp">#footer</span> {
<a id="cb1-71" class="sourceLine" title="71"></a>        <span class="kw">text-align</span>: <span class="dv">center</span><span class="op">;</span>
<a id="cb1-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="cb1-73" class="sourceLine" title="73"></a>        <span class="kw">background</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb1-74" class="sourceLine" title="74"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-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="cb1-76" class="sourceLine" title="76"></a>      }
<a id="cb1-77" class="sourceLine" title="77"></a>
<a id="cb1-78" class="sourceLine" title="78"></a>      <span class="fu">.nav-item</span> {
<a id="cb1-79" class="sourceLine" title="79"></a>        <span class="kw">display</span>: <span class="dv">inline-block</span><span class="op">;</span>
<a id="cb1-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="cb1-81" class="sourceLine" title="81"></a>      }
<a id="cb1-82" class="sourceLine" title="82"></a>
<a id="cb1-83" class="sourceLine" title="83"></a>      <span class="fu">.column-left</span> {
<a id="cb1-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="cb1-85" class="sourceLine" title="85"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-86" class="sourceLine" title="86"></a>      }
<a id="cb1-87" class="sourceLine" title="87"></a>
<a id="cb1-88" class="sourceLine" title="88"></a>      <span class="fu">.column-middle</span> {
<a id="cb1-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="cb1-90" class="sourceLine" title="90"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-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="cb1-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="cb1-93" class="sourceLine" title="93"></a>      }
<a id="cb1-94" class="sourceLine" title="94"></a>
<a id="cb1-95" class="sourceLine" title="95"></a>      <span class="fu">.column-right</span> {
<a id="cb1-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="cb1-97" class="sourceLine" title="97"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-98" class="sourceLine" title="98"></a>      }
<a id="cb1-99" class="sourceLine" title="99"></a>
<a id="cb1-100" class="sourceLine" title="100"></a>      <span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb1-101" class="sourceLine" title="101"></a>        <span class="kw">clear</span>: <span class="dv">both</span><span class="op">;</span>
<a id="cb1-102" class="sourceLine" title="102"></a>        <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb1-103" class="sourceLine" title="103"></a>        <span class="kw">content</span>: <span class="st">""</span><span class="op">;</span>
<a id="cb1-104" class="sourceLine" title="104"></a>      }
<a id="cb1-105" class="sourceLine" title="105"></a>
<a id="cb1-106" class="sourceLine" title="106"></a>      <span class="fu">.card</span> {
<a id="cb1-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="cb1-108" class="sourceLine" title="108"></a>      }
<a id="cb1-109" class="sourceLine" title="109"></a>
<a id="cb1-110" class="sourceLine" title="110"></a>      <span class="fu">.image</span> {
<a id="cb1-111" class="sourceLine" title="111"></a>
<a id="cb1-112" class="sourceLine" title="112"></a>      }
<a id="cb1-113" class="sourceLine" title="113"></a>
<a id="cb1-114" class="sourceLine" title="114"></a>      <span class="fu">.headline-small</span> {
<a id="cb1-115" class="sourceLine" title="115"></a>
<a id="cb1-116" class="sourceLine" title="116"></a>      }
<a id="cb1-117" class="sourceLine" title="117"></a>
<a id="cb1-118" class="sourceLine" title="118"></a>      <span class="fu">.headline-medium</span> {
<a id="cb1-119" class="sourceLine" title="119"></a>        <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-120" class="sourceLine" title="120"></a>      }
<a id="cb1-121" class="sourceLine" title="121"></a>
<a id="cb1-122" class="sourceLine" title="122"></a>      <span class="fu">.headline-large</span> {
<a id="cb1-123" class="sourceLine" title="123"></a>        <span class="kw">font-size</span>: <span class="dv">32</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-124" class="sourceLine" title="124"></a>      }
<a id="cb1-125" class="sourceLine" title="125"></a>
<a id="cb1-126" class="sourceLine" title="126"></a>      <span class="fu">.timestamp</span> {
<a id="cb1-127" class="sourceLine" title="127"></a>        <span class="kw">padding-top</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-128" class="sourceLine" title="128"></a>        <span class="kw">color</span>: <span class="cn">gray</span><span class="op">;</span>
<a id="cb1-129" class="sourceLine" title="129"></a>        <span class="kw">font-size</span>: <span class="dv">12</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-130" class="sourceLine" title="130"></a>      }
<a id="cb1-131" class="sourceLine" title="131"></a>
<a id="cb1-132" class="sourceLine" title="132"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb1-133" class="sourceLine" title="133"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb1-134" class="sourceLine" title="134"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb1-135" class="sourceLine" title="135"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"wrapper"</span><span class="kw">&gt;</span>
<a id="cb1-136" class="sourceLine" title="136"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>
<a id="cb1-137" class="sourceLine" title="137"></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="cb1-138" class="sourceLine" title="138"></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="cb1-139" class="sourceLine" title="139"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-140" class="sourceLine" title="140"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;</span>
<a id="cb1-141" class="sourceLine" title="141"></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="cb1-142" class="sourceLine" title="142"></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="cb1-143" class="sourceLine" title="143"></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="cb1-144" class="sourceLine" title="144"></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="cb1-145" class="sourceLine" title="145"></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="cb1-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>Reviews<span class="kw">&lt;/span&gt;</span>
<a id="cb1-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>Events<span class="kw">&lt;/span&gt;</span>
<a id="cb1-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>Local Edition<span class="kw">&lt;/span&gt;</span>
<a id="cb1-149" class="sourceLine" title="149"></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="cb1-150" class="sourceLine" title="150"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-151" class="sourceLine" title="151"></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="cb1-152" class="sourceLine" title="152"></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="cb1-153" class="sourceLine" title="153"></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="cb1-154" class="sourceLine" title="154"></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="cb1-155" class="sourceLine" title="155"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-156" class="sourceLine" title="156"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-157" class="sourceLine" title="157"></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="cb1-158" class="sourceLine" title="158"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-159" class="sourceLine" title="159"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-small"</span><span class="kw">&gt;</span>
<a id="cb1-160" class="sourceLine" title="160"></a>              Foods that boost your learning
<a id="cb1-161" class="sourceLine" title="161"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-162" class="sourceLine" title="162"></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="cb1-163" class="sourceLine" title="163"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-164" class="sourceLine" title="164"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-165" class="sourceLine" title="165"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-166" class="sourceLine" title="166"></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="cb1-167" class="sourceLine" title="167"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-168" class="sourceLine" title="168"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-small"</span><span class="kw">&gt;</span>
<a id="cb1-169" class="sourceLine" title="169"></a>              Robot arms may be the next
<a id="cb1-170" class="sourceLine" title="170"></a>              technological frontier
<a id="cb1-171" class="sourceLine" title="171"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-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="cb1-173" class="sourceLine" title="173"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-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="cb1-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="cb1-176" class="sourceLine" title="176"></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="cb1-177" class="sourceLine" title="177"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-178" class="sourceLine" title="178"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-small"</span><span class="kw">&gt;</span>
<a id="cb1-179" class="sourceLine" title="179"></a>              Is virtual reality going to far?
<a id="cb1-180" class="sourceLine" title="180"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-181" class="sourceLine" title="181"></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="cb1-182" class="sourceLine" title="182"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-183" class="sourceLine" title="183"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-184" class="sourceLine" title="184"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-185" class="sourceLine" title="185"></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="cb1-186" class="sourceLine" title="186"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-187" class="sourceLine" title="187"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-small"</span><span class="kw">&gt;</span>
<a id="cb1-188" class="sourceLine" title="188"></a>              The latest trends in cosplay
<a id="cb1-189" class="sourceLine" title="189"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-190" class="sourceLine" title="190"></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="cb1-191" class="sourceLine" title="191"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-192" class="sourceLine" title="192"></a>
<a id="cb1-193" class="sourceLine" title="193"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb1-194" class="sourceLine" title="194"></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="cb1-195" class="sourceLine" title="195"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-196" class="sourceLine" title="196"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-197" class="sourceLine" title="197"></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="cb1-198" class="sourceLine" title="198"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-199" class="sourceLine" title="199"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-large"</span><span class="kw">&gt;</span>
<a id="cb1-200" class="sourceLine" title="200"></a>              Before you buy, check our review of the
<a id="cb1-201" class="sourceLine" title="201"></a>              hottest cars on the market
<a id="cb1-202" class="sourceLine" title="202"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-203" class="sourceLine" title="203"></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="cb1-204" class="sourceLine" title="204"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-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="cb1-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="cb1-207" class="sourceLine" title="207"></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="cb1-208" class="sourceLine" title="208"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-209" class="sourceLine" title="209"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-large"</span><span class="kw">&gt;</span>
<a id="cb1-210" class="sourceLine" title="210"></a>              Health benefits of fresh fruits
<a id="cb1-211" class="sourceLine" title="211"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-212" class="sourceLine" title="212"></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="cb1-213" class="sourceLine" title="213"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-214" class="sourceLine" title="214"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb1-215" class="sourceLine" title="215"></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="cb1-216" class="sourceLine" title="216"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-217" class="sourceLine" title="217"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-218" class="sourceLine" title="218"></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="cb1-219" class="sourceLine" title="219"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-220" class="sourceLine" title="220"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-medium"</span><span class="kw">&gt;</span>
<a id="cb1-221" class="sourceLine" title="221"></a>              The best places to visit on Jupiter
<a id="cb1-222" class="sourceLine" title="222"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-223" class="sourceLine" title="223"></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="cb1-224" class="sourceLine" title="224"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-225" class="sourceLine" title="225"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb1-226" class="sourceLine" title="226"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"image"</span><span class="kw">&gt;</span>
<a id="cb1-227" class="sourceLine" title="227"></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="cb1-228" class="sourceLine" title="228"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-229" class="sourceLine" title="229"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-medium"</span><span class="kw">&gt;</span>
<a id="cb1-230" class="sourceLine" title="230"></a>              The latest smart watches monitor your
<a id="cb1-231" class="sourceLine" title="231"></a>              body's vitals while looking stylish
<a id="cb1-232" class="sourceLine" title="232"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-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="cb1-234" class="sourceLine" title="234"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-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="cb1-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="cb1-237" class="sourceLine" title="237"></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="cb1-238" class="sourceLine" title="238"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-239" class="sourceLine" title="239"></a>            <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"headline-medium"</span><span class="kw">&gt;</span>
<a id="cb1-240" class="sourceLine" title="240"></a>              Keeping yourself safe while shopping online
<a id="cb1-241" class="sourceLine" title="241"></a>            <span class="kw">&lt;/div&gt;</span>
<a id="cb1-242" class="sourceLine" title="242"></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="cb1-243" class="sourceLine" title="243"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-244" class="sourceLine" title="244"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb1-245" class="sourceLine" title="245"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-246" class="sourceLine" title="246"></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="cb1-247" class="sourceLine" title="247"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb1-248" class="sourceLine" title="248"></a>
<a id="cb1-249" class="sourceLine" title="249"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb1-250" class="sourceLine" title="250"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h2 id="detailed-code-walkthrough">Detailed Code Walkthrough</h2>
<h3 id="setting-some-page-level-defaults">Setting Some Page Level Defaults</h3>
<div id="cb2" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb2-1" class="sourceLine" title="1"></a><span class="op">*</span> {
<a id="cb2-2" class="sourceLine" title="2"></a>  <span class="kw">box-sizing</span>: <span class="dv">border-box</span><span class="op">;</span>
<a id="cb2-3" class="sourceLine" title="3"></a>  <span class="kw">font-family</span>: <span class="dv">sans-serif</span><span class="op">;</span>
<a id="cb2-4" class="sourceLine" title="4"></a>  <span class="kw">font-size</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb2-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>The <span class="css-property">box-sizing</span> property<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a> is set to <span class="css-value">border-box</span> &#8211; instead of the default <span class="css-property">content-box</span> &#8211; for all elements. You almost always want to do this because it makes layout much easier.</p>
<p>The <span class="css-property">font-family</span> is set to <span class="css-value">sans-serif</span>, but you are free to choose <span class="css-value">serif</span> or <span class="css-value">monospace</span>.<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></p>
<p>The <span class="css-property">font-size</span> is set to <span class="css-value">16px</span>. This is the default value for almost all web browsers.</p>
<p>These settings will be applied to all the HTML elements unless overridden by more specific styling.<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></p>
<h3 id="the-highest-level-structure">The Highest Level Structure</h3>
<p>When writing the code, it became obvious that another element &#8211; which I call <strong>darkbox</strong> &#8211; was needed below the <strong>navbar</strong>.</p>
<p>It didn’t have to be added to the high level structure, it could have been nested inside the <strong>navbar</strong> &#8211; but it seemed simpler this way.</p>
<p>At the highest level, the (new) HTML structure looks like this:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb3-1" class="sourceLine" title="1"></a><span class="kw">&lt;body&gt;</span>
<a id="cb3-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"wrapper"</span><span class="kw">&gt;</span>
<a id="cb3-3" class="sourceLine" title="3"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-5" class="sourceLine" title="5"></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="cb3-6" class="sourceLine" title="6"></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="cb3-7" class="sourceLine" title="7"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-8" class="sourceLine" title="8"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-middle"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-9" class="sourceLine" title="9"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-10" class="sourceLine" title="10"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb3-11" class="sourceLine" title="11"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-12" class="sourceLine" title="12"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb3-13" class="sourceLine" title="13"></a><span class="kw">&lt;/body&gt;</span></code></pre>
</div>
<p>As we walk through the code, it should become clear why it was added.</p>
<h3 id="the-wrapper">The Wrapper</h3>
<p>The <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content/">standard way of laying out a webpage</a> is to add a content wrapper between the <span class="html-tag">body</span> tags rather than directly adding content to the <strong>body</strong> section of the document.</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;body&gt;</span>
<a id="cb4-2" class="sourceLine" title="2"></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-3" class="sourceLine" title="3"></a>
<a id="cb4-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb4-5" class="sourceLine" title="5"></a><span class="kw">&lt;/body&gt;</span></code></pre>
</div>
<p>There is no change from the design decision to make the content 960px wide and to center it inside the <strong>body</strong> section by setting the margins to <span class="css-value">auto</span>:</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="pp">#wrapper</span> {
<a id="cb5-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">960</span><span class="dt">px</span><span class="op">;</span>
<a id="cb5-3" class="sourceLine" title="3"></a>  <span class="kw">margin</span>: <span class="bu">auto</span><span class="op">;</span>
<a id="cb5-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<h3 id="the-title">The Title</h3>
<div id="cb6" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb6-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>
<a id="cb6-2" class="sourceLine" title="2"></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="cb6-3" class="sourceLine" title="3"></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="cb6-4" class="sourceLine" title="4"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <strong>Title</strong> section consists of a single line with two parts:</p>
<ol class="incremental" type="1">
<li>the site title</li>
<li>the login</li>
</ol>
<p>The <span class="html-tag">span</span> tag is used to style elements in a line.<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></p>
<p>We want one element to be to the left and one to the right. This can be accomplished by floating the <strong>login</strong> to the right.<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a></p>
<p>A <span class="css-class">.clearfix</span> is applied to the final element to remove the effect of the float.<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a></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="pp">#title</span> {
<a id="cb7-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb7-3" class="sourceLine" title="3"></a>  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb7-4" class="sourceLine" title="4"></a>  <span class="kw">padding</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb7-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>Some basic properties are set for the title area:</p>
<ul class="incremental">
<li>background colour,</li>
<li>text colour,</li>
<li>and a little bit of padding to make it look nice.</li>
</ul>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" title="1"></a><span class="pp">#site-name</span> {
<a id="cb8-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="cb8-3" class="sourceLine" title="3"></a>  <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb8-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<p>To make the site name stand out, the font size is set to 32px and made bold. You could also make the site name an image &#8211; this would allow you to use a logo as well.</p>
<p>The title could be floated to the left, but it left justifies automatically, so it is unnecessary. You can add <span class="css-property">float:</span><span class="css-value">left</span> to the class &#8211; if you want.</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">#login</span> {
<a id="cb9-2" class="sourceLine" title="2"></a>  <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb9-3" class="sourceLine" title="3"></a>  <span class="kw">padding-top</span>: <span class="dv">8</span><span class="dt">px</span><span class="op">;</span>
<a id="cb9-4" class="sourceLine" title="4"></a>  <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb9-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>The <strong>login</strong> is subdued compared to the surrounding text, so it was set to <strong>grey</strong> instead of <strong>black</strong>. A custom hexadecimal RGB value could be used as well.</p>
<p>8px of padding was added to the top to vertically align the <strong>login</strong> text with the site name.<a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a> If you wanted to adjust the <span class="css-property">margin</span> instead of the <span class="css-property">padding</span>, then the <span class="css-property">display</span> mode of the span must be changed to <span class="css-value">inline-block</span>.<a id="fnref8" class="footnote-ref" href="#fn8"><sup>8</sup></a></p>
<p>The HTML element was also floated to the right of the page.</p>
<h3 id="the-navigation-bar">The Navigation Bar</h3>
<div id="cb10" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb10-1" class="sourceLine" title="1"></a><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;</span>
<a id="cb10-2" class="sourceLine" title="2"></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="cb10-3" class="sourceLine" title="3"></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="cb10-4" class="sourceLine" title="4"></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="cb10-5" class="sourceLine" title="5"></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="cb10-6" class="sourceLine" title="6"></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="cb10-7" class="sourceLine" title="7"></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="cb10-8" class="sourceLine" title="8"></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="cb10-9" class="sourceLine" title="9"></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="cb10-10" class="sourceLine" title="10"></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="cb10-11" class="sourceLine" title="11"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Each menu or navigation item is enclosed inside a <span class="html-tag">span</span> element. This allows each item to be individually styled.<a id="fnref9" class="footnote-ref" href="#fn9"><sup>9</sup></a> Recall that HTML eliminates all excess whitespace characters.<a id="fnref10" class="footnote-ref" href="#fn10"><sup>10</sup></a></p>
<p>The element containing the “search” icon is given the id <strong>search</strong> since there should be only one search item on the page. It is floated to the right. A suitably sized image of a magnifying glass could have been used, instead similar looking text character is used instead &#8211; it is a <a href="https://www.compart.com/en/unicode/U+2315">“telephone recorder” (⌕)</a>. This simplifies everything by keeping everything text instead of mixing text and images (not that there is anything wrong with doing that). Finally, the <span class="css-class">.clearfix</span> is applied to clear the float.</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="pp">#navbar</span> {
<a id="cb11-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb11-3" class="sourceLine" title="3"></a>  <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb11-4" class="sourceLine" title="4"></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="cb11-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>The background is dark, but not black. A thin border is set on the bottom.</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="fu">.nav-item</span> {
<a id="cb12-2" class="sourceLine" title="2"></a>  <span class="kw">display</span>: <span class="dv">inline-block</span><span class="op">;</span>
<a id="cb12-3" class="sourceLine" title="3"></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="cb12-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<p>Each <span class="css-class">.nav-item</span> has <span class="css-property">display</span> set to <span class="css-value">inline-block</span>. This allows us full control of the margins (including the top and bottom).</p>
<p>The <span class="css-property">padding</span> is set to something I considered pleasing looking.</p>
<div id="cb13" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb13-1" class="sourceLine" title="1"></a><span class="pp">#search</span> {
<a id="cb13-2" class="sourceLine" title="2"></a>  <span class="kw">color</span>: <span class="cn">grey</span><span class="op">;</span>
<a id="cb13-3" class="sourceLine" title="3"></a>  <span class="kw">float</span>: <span class="dv">right</span><span class="op">;</span>
<a id="cb13-4" class="sourceLine" title="4"></a>  <span class="kw">padding-top</span>: <span class="dv">18</span><span class="dt">px</span><span class="op">;</span>
<a id="cb13-5" class="sourceLine" title="5"></a>  <span class="kw">padding-right</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb13-6" class="sourceLine" title="6"></a>  <span class="kw">font-size</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb13-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<p>The <strong>search</strong> element is floated to the right. The colour is a more muted and set to grey. Because the “telephone recorder” is a bit small, the font-size was increased to 24 px. This required adjusting the top padding to make it look centred.</p>
<h3 id="the-dark-box">The Dark Box</h3>
<p>This is the trickiest element and requires a bit of lateral thinking.</p>
<p>If you look at the original page layout, you see the columns overlap a dark region above them. You also notice that there is a vertical line dividing the columns and a horizontal line dividing the navigation bar from the columns:<a id="fnref11" class="footnote-ref" href="#fn11"><sup>11</sup></a><br />
<img loading="lazy" decoding="async" width="600" height="426" class="aligncenter size-full wp-image-3749" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg" alt="A screenshot of a website home page." srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min-300x213.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /><br />
The horizontal dividing line is made by setting the <span class="css-property">border-bottom</span> of the navbar container to something visible.</p>
<p>Placing an identically coloured element below the navigation bar, it looks like there is a horizontal line dividing the dark region into a top and bottom.</p>
<div id="cb14" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb14-1" class="sourceLine" title="1"></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></code></pre>
</div>
<p>The <span class="css-id">darkbox</span> is an empty <span class="html-tag">div</span> with some <span class="css-property">height</span> applied.</p>
<p>Perhaps a better name would be <strong>navbar-extension</strong> instead of <strong>darkbox</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="pp">#darkbox</span> {
<a id="cb15-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb15-3" class="sourceLine" title="3"></a>  <span class="kw">height</span>: <span class="dv">100</span><span class="dt">px</span><span class="op">;</span>
<a id="cb15-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<p>The <span class="css-property">background-color</span> is set the same as for the <span class="css-id">navbar</span>.</p>
<p>A <span class="css-property">height</span> of 100px looks about the right size.</p>
<h3 id="the-content">The Content</h3>
<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"> id=</span><span class="st">"content"</span><span class="ot"> class=</span><span class="st">"clearfix"</span><span class="kw">&gt;</span>
<a id="cb16-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb16-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-middle"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb16-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb16-5" class="sourceLine" title="5"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <span class="css-id">content</span> is a container holding three left floating columns. It is styled with <span class="css-class">.clearfix</span> to restore normal flow. The <span class="css-class">.clearfix</span> could be applied only to <span class="css-class">.column-right</span>, but it seems better to clear at the parent container level.</p>
<div id="cb17" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb17-1" class="sourceLine" title="1"></a><span class="pp">#content</span> {
<a id="cb17-2" class="sourceLine" title="2"></a>  <span class="kw">margin-top</span>: <span class="dv">-90</span><span class="dt">px</span><span class="op">;</span>
<a id="cb17-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The <span class="css-property">margin-top</span> is set to -90px. This causes the <span class="css-id">content</span> area to be shifted upwards 90px. This causes it to overlap the <span class="css-id">darkbox</span>. It is possible to use negative values for positioning elements.</p>
<h3 id="the-column-left">The column-left</h3>
<p>The <span class="css-class">.column-left</span> contains the title <strong>Popular</strong> and 4 cards.</p>
<div id="cb18" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb18-1" class="sourceLine" title="1"></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="cb18-2" class="sourceLine" title="2"></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="cb18-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb18-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb18-5" class="sourceLine" title="5"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb18-6" class="sourceLine" title="6"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb18-7" class="sourceLine" title="7"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <span class="css-class">.column-left</span> is styled to have a <span class="css-property">width</span> of 20% and to <span class="css-property">float</span> left.</p>
<div id="cb19" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb19-1" class="sourceLine" title="1"></a><span class="fu">.column-left</span> {
<a id="cb19-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">20</span><span class="dt">%</span><span class="op">;</span>
<a id="cb19-3" class="sourceLine" title="3"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb19-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<p>The <strong>Popular</strong> title is styled using the <span class="css-id">#popular</span> class which sets the text <span class="css-property">color</span> to white, adds 16px of <span class="css-property">padding-left</span> to nicely align the title and set the <span class="css-property">font-weight</span> to bold so it stands out.</p>
<div id="cb20" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb20-1" class="sourceLine" title="1"></a><span class="pp">#popular</span> {
<a id="cb20-2" class="sourceLine" title="2"></a>  <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb20-3" class="sourceLine" title="3"></a>  <span class="kw">padding-left</span>: <span class="dv">16</span><span class="dt">px</span><span class="op">;</span>
<a id="cb20-4" class="sourceLine" title="4"></a>  <span class="kw">font-weight</span>: <span class="dv">bold</span><span class="op">;</span>
<a id="cb20-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>We will examine the details of the <span class="css-class">.card</span> class a little later.</p>
<h3 id="the-column-middle">The column-middle</h3>
<p>The <span class="css-class">.column-middle</span> consists of two cards.</p>
<div id="cb21" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb21-1" class="sourceLine" title="1"></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="cb21-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb21-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb21-4" class="sourceLine" title="4"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>If you wanted to be more like the Verge website, which has a single large card and then two columns of cards beneath it, the code would look something like this this:</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">"column-middle"</span><span class="kw">&gt;</span>
<a id="cb22-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"dual-columns"</span><span class="kw">&gt;</span>  
<a id="cb22-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"dual-left"</span><span class="kw">&gt;</span>
<a id="cb22-5" class="sourceLine" title="5"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-6" class="sourceLine" title="6"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-7" class="sourceLine" title="7"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-8" class="sourceLine" title="8"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb22-9" class="sourceLine" title="9"></a>    <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"dual-right"</span><span class="kw">&gt;</span>
<a id="cb22-10" class="sourceLine" title="10"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-11" class="sourceLine" title="11"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-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>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-13" class="sourceLine" title="13"></a>    <span class="kw">&lt;/div&gt;</span>      
<a id="cb22-14" class="sourceLine" title="14"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb22-15" class="sourceLine" title="15"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>There might be better class names or you might want to use IDs instead of classes.</p>
<p>The <span class="css-class">.column-middle</span> is styled to have a <span class="css-property">width</span> of 55% and to <span class="css-property">float</span> left. It also has a thin border on the left and right side &#8211; this gives a nice visual esthetic. How could you make these vertical borders touch the horizontal border applied to the <span class="css-id">#navbar</span>?<a id="fnref12" class="footnote-ref" href="#fn12"><sup>12</sup></a></p>
<div id="cb23" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb23-1" class="sourceLine" title="1"></a><span class="fu">.column-middle</span> {
<a id="cb23-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">55</span><span class="dt">%</span><span class="op">;</span>
<a id="cb23-3" class="sourceLine" title="3"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb23-4" class="sourceLine" title="4"></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="cb23-5" class="sourceLine" title="5"></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="cb23-6" class="sourceLine" title="6"></a>}</code></pre>
</div>
<h3 id="the-column-right">The column-right</h3>
<p>The <span class="css-class">.column-right</span> consists of three cards.</p>
<div id="cb24" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb24-1" class="sourceLine" title="1"></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="cb24-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb24-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb24-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>  <span class="kw">&lt;/div&gt;</span>
<a id="cb24-5" class="sourceLine" title="5"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <span class="css-class">.column-right</span> is styled to have a <span class="css-property">width</span> of 25% and to <span class="css-property">float</span> left.</p>
<div id="cb25" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb25-1" class="sourceLine" title="1"></a><span class="fu">.column-right</span> {
<a id="cb25-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">25</span><span class="dt">%</span><span class="op">;</span>
<a id="cb25-3" class="sourceLine" title="3"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb25-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<h3 id="the-card">The card</h3>
<p>A <span class="css-class">.card</span> encapsulates an:</p>
<ol class="incremental" type="1">
<li>image,</li>
<li>headline,</li>
<li>and timestamp .</li>
</ol>
<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;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb26-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="cb26-3" class="sourceLine" title="3"></a>    <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"image.jpg"</span><span class="kw">&gt;</span>
<a id="cb26-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb26-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="cb26-6" class="sourceLine" title="6"></a>    A Headline
<a id="cb26-7" class="sourceLine" title="7"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb26-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>🕔 A Timestamp<span class="kw">&lt;/div&gt;</span>
<a id="cb26-9" class="sourceLine" title="9"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The <span class="html-tag">img</span> is wrapped inside a <span class="html-tag">div</span>. This is common practice.<a id="fnref13" class="footnote-ref" href="#fn13"><sup>13</sup></a> It allows the image and everything associated with the image to be encapsulated in its own container.</p>
<p>The <strong>headline</strong> contains some text. It could be wrapped inside a <span class="html-tag">p</span> tag, but it is not necessary.</p>
<p>The <strong>timestamp</strong> also contains some &#8211; which also could be wrapped inside a <span class="html-tag">p</span> tag. The clock (🕔) could be an image, but there are some Unicode clock characters<a id="fnref14" class="footnote-ref" href="#fn14"><sup>14</sup></a> &#8211; which what is used. It is easier to work with text instead of mixing text and images. However, whatever gets the job done is (usually) good.</p>
<p>The <span class="css-class">.card</span> is styled to have 16px of <span class="css-property">padding</span> on the left, right, and bottom. This padding allows the card to have some esthetic spacing on the sides and between cards. If 16px of padding were also applied to the top, then there would be 32px of spacing between the bottom of one card and the top of the next card.</p>
<div id="cb27" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb27-1" class="sourceLine" title="1"></a><span class="fu">.card</span> {
<a id="cb27-2" class="sourceLine" title="2"></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="cb27-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The <span class="html-tag">img</span> tag is styled with a <span class="css-property">width</span> of 100%. This causes the image scale correctly to fit whatever container it is in &#8211; the same <span class="css-class">.card</span> is used in all the columns (20%, 55%, and 25%).<a id="fnref15" class="footnote-ref" href="#fn15"><sup>15</sup></a></p>
<div id="cb28" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb28-1" class="sourceLine" title="1"></a>img {
<a id="cb28-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb28-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>The wrapper for the [img]{html-tag} has the class <span class="css-class">.image</span> applied to it. At the moment, it doesn’t apply any styling, but it is available for modification in the future.<a id="fnref16" class="footnote-ref" href="#fn16"><sup>16</sup></a></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="fu">.image</span> {
<a id="cb30-2" class="sourceLine" title="2"></a>
<a id="cb30-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<h3 id="the-footer">The footer</h3>
<p>The footer has its own ID and is styled to match the rest of the content on the page.</p>
<div id="cb31" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb31-1" class="sourceLine" title="1"></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></code></pre>
</div>
<div id="cb32" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb32-1" class="sourceLine" title="1"></a><span class="pp">#footer</span> {
<a id="cb32-2" class="sourceLine" title="2"></a>  <span class="kw">text-align</span>: <span class="dv">center</span><span class="op">;</span>
<a id="cb32-3" class="sourceLine" title="3"></a>  <span class="kw">padding</span>: <span class="dv">24</span><span class="dt">px</span><span class="op">;</span>
<a id="cb32-4" class="sourceLine" title="4"></a>  <span class="kw">background</span>: <span class="cn">#333333</span><span class="op">;</span>
<a id="cb32-5" class="sourceLine" title="5"></a>  <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb32-6" class="sourceLine" title="6"></a>  <span class="kw">font-size</span>: <span class="dv">20</span><span class="dt">px</span><span class="op">;</span>
<a id="cb32-7" class="sourceLine" title="7"></a>}</code></pre>
</div>
<h2 id="final-thoughts">Final Thoughts</h2>
<p>Using only what we’ve covered so far, it is possible to create quite sophisticated looking webpages.</p>
<p>You can go a step further and make the page “functional” by adding links to all the articles<a id="fnref17" class="footnote-ref" href="#fn17"><sup>17</sup></a> and creating the corresponding pages.</p>
<p>While it is a lot of work to create a webpage, it is not difficult work.</p>
<p>I encourage you to try and “clone” webpages from other sites. Remember, the goal is to practice and hone your skills, not to wear yourself out.</p>
<p>There is still a lot more to developing webpages and websites. Responsiveness[^responsive] is an important one: your webpage should look good on a 320px X 480px phone display as on a 1920px X 1080px desktop display. But this is something you don’t worry about in the beginning. First get the skills down to make pages that look good on the screen you are working on. In future lessons, we will look at how to make the page look good on varying display sizes.</p>
<h2 id="image-credits">Image Credits</h2>
<p>The images used in the example page are courtesy of:</p>
<ol class="incremental" type="1">
<li>Apple and Books by <a href="https://pixabay.com/en/apple-red-delicious-fruit-256263/">jarmoluk</a></li>
<li>Robotic Arm by <a href="https://pixabay.com/en/cybernetics-robot-robot-arm-1869205/">PIRO4D</a></li>
<li>Virtual Reality Cyclist by <a href="https://pixabay.com/en/augmented-reality-bicycle-bike-1853592/">VR Pexels</a></li>
<li>Cosplay Girl by <a href="https://pixabay.com/en/girl-portrait-bokeh-model-skin-2941823/">ptksgc</a></li>
<li>Toy Cars by <a href="https://pixabay.com/en/toys-hot-wheels-porsche-panamera-3582278/">kamal1118</a></li>
<li>Fruit Salad by <a href="https://pixabay.com/en/fruit-fruits-fruit-salad-fresh-bio-2305192/">silviarita</a></li>
<li>Astronaut and Jupiter by <a href="https://pixabay.com/en/cave-jupiter-astronaut-space-912219/">DasWortgewand</a></li>
<li>Watch by <a href="https://pixabay.com/en/watch-basketball-sport-active-1663246/">the5th</a></li>
<li>Keyboard by <a href="https://pixabay.com/en/shopping-keyboard-enter-button-3696867/">atthree23</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-2/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-quick-introduction-to-two-development-tools-built-into-your-browser/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr>
<ol>
<li id="fn1">This was covered in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/#box-sizing">None More CSS Properties to Play With</a><a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">A future tutorial will show how to use specific fonts like: Arial, Courier, Times New Roman, etc.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">A future tutorial will explore how CSS properties are applied when the same property is styled differently in multiple rules. This can happen when two or more classes are applied to the same element (or and ID and a class).<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">This was covered in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content/#span">Sectioning Using HTML and Auto Centering Content</a>. I could have floated the title to the left and the login to the right, but it wasn’t necessary. This is a design decision. You are free to float the title to the left.<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">See <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/#floated-elements-flow-sideways">CSS &#8211; Understanding How Float Works &#8211; Part 2</a><a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">See <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">CSS – Understanding How Float Works – Part 1</a> for a discussion of <strong>clearfix</strong>.<a class="footnote-back" href="#fnref6">↩</a></li>
<li id="fn7">The site is set to 32px, and the default text size is set to 16px. This means the default text is 16px smaller than the site name. This is divided between the top and bottom of the <strong>login</strong> (or 8px on the top and 8px on the bottom). We know that floats move up as far as they can, so it is only necessary to add 8px of padding to the top. You can also use trial and error until it looks the way you want.<a class="footnote-back" href="#fnref7">↩</a></li>
<li id="fn8">This was discussed in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/html-flow-and-the-css-box-model-the-display-property/#inline-block">HTML Flow and the CSS Box Model – the ‘Display’ Property</a><a class="footnote-back" href="#fnref8">↩</a></li>
<li id="fn9">It is more common to use an unordered list (<span class="html-tag">ul</span>) and make each element a list item (<span class="html-tag">li</span>). The list items are styled with <span class="css-property">display</span>:<span class="css-value">inline</span> instead of the default <span class="css-property">display</span>:<span class="css-value">list-item</span>. This requires using a property I haven’t discussed yet: <span class="css-property">list-style-type</span> which controls what is displayed next to each list item. Some of the values are: <span class="css-value">disc</span>, <span class="css-value">circle</span>, <span class="css-value">square</span>, <span class="css-value">none</span>. If you want to use a list instead, then apply <span class="css-property">list-style-type</span>:<span class="css-value">none</span> to the unordered list.<a class="footnote-back" href="#fnref9">↩</a></li>
<li id="fn10">See <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/html-basic-conclusion/#an-overview-of-html">HTML Basics – Conclusion</a><a class="footnote-back" href="#fnref10">↩</a></li>
<li id="fn11">OK, the lines are not so visible in the tiny little image I provide, but they are visible if you go to the engadget website.<a class="footnote-back" href="#fnref11">↩</a></li>
<li id="fn12">You move the content area up 100px &#8211; the full height of the <span class="css-id">#darkbox</span> &#8211; instead of 90px. You then add a bit of padding (maybe 10px) to the top of the content area so there is some spacing between the content and the horizontal line.<a class="footnote-back" href="#fnref12">↩</a></li>
<li id="fn13">Common practices, are often called <strong>design patterns</strong>. A <strong>design pattern</strong> is a generic solution for problems that repeatedly come up in software engineering. There are many different types of <strong>design patterns</strong>.<a class="footnote-back" href="#fnref13">↩</a></li>
<li id="fn14">Some of the available Unicode time characters are:
<div style="font-size: 32px;">
<style> .this-page {margin:0 !important;line-height:32px;} .this-span {font-size:16px;}</style>
<p class="this-page">⏰ &#8211; <span class="this-span">Alarm Clock</span></p>
<p class="this-page">🕰 &#8211; <span class="this-span">Mantelpiece Clock</span></p>
<p class="this-page">⌚ &#8211; <span class="this-span">Watch</span></p>
<p class="this-page">⏱ &#8211; <span class="this-span">Stopwatch</span></p>
<p class="this-page">⏲ &#8211; <span class="this-span">Timer</span></p>
<p class="this-page">⌛ &#8211; <span class="this-span">Hourglass</span></p>
<p class="this-page">⏳- <span class="this-span">Hourglass with flowing sand</span></p>
<p class="this-page">⧗ &#8211; <span class="this-span">Black Hourglass</span></p>
<p class="this-page">⧖ &#8211; <span class="this-span">White Hourglass</span></p>
<p class="this-page">🕛 &#8211; <span class="this-span">12:00</span></p>
<p class="this-page">🕧 &#8211; <span class="this-span">12:30</span></p>
<p class="this-page">🕐 &#8211; <span class="this-span">1:00</span></p>
<p class="this-page">🕜 &#8211; <span class="this-span">1:30</span></p>
<p class="this-page">🕑 &#8211; <span class="this-span">2:00</span></p>
<p class="this-page">🕝 &#8211; <span class="this-span">2:30</span></p>
<p class="this-page">🕒 &#8211; <span class="this-span">3:00</span></p>
<p class="this-page">🕞 &#8211; <span class="this-span">3:30</span></p>
<p class="this-page">🕓 &#8211; <span class="this-span">4:00</span></p>
<p class="this-page">🕟 &#8211; <span class="this-span">4:30</span></p>
<p class="this-page">🕔 &#8211; <span class="this-span">5:00</span></p>
<p class="this-page">🕠 &#8211; <span class="this-span">5:30</span></p>
<p class="this-page">🕕 &#8211; <span class="this-span">6:00</span></p>
<p class="this-page">🕡 &#8211; <span class="this-span">6:30</span></p>
<p class="this-page">🕖 &#8211; <span class="this-span">7:00</span></p>
<p class="this-page">🕢 &#8211; <span class="this-span">7:30</span></p>
<p class="this-page">🕗 &#8211; <span class="this-span">8:00</span></p>
<p class="this-page">🕣 &#8211; <span class="this-span">8:30</span></p>
<p class="this-page">🕘 &#8211; <span class="this-span">9:00</span></p>
<p class="this-page">🕤 &#8211; <span class="this-span">9:30</span></p>
<p class="this-page">🕙 &#8211; <span class="this-span">10:00</span></p>
<p class="this-page">🕥 &#8211; <span class="this-span">10:30</span></p>
<p class="this-page">🕚 &#8211; <span class="this-span">11:00</span></p>
<p class="this-page">🕦 &#8211; <span class="this-span">11:30</span></p>
</div>
<p><a class="footnote-back" href="#fnref14">↩</a></li>
<li id="fn15">This was covered in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/#width-and-the-img-tag">Nine More CSS Properties to Play With</a><a class="footnote-back" href="#fnref15">↩</a></li>
<li id="fn16">You could argue that if there is no styling being applied, the class <span class="css-class">.image</span> shouldn’t exist. It is difficult to always know what is needed or what sort of changed might be made in the future. Having the class allows you to add a border or background colour. It is common to see unique empty classes applied to certain elements on a page for future styling. For example, you could add a unique paragraph class to each <span class="html-tag">p</span>:
<div id="cb29" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb29-1" class="sourceLine" title="1"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"par-1234"</span><span class="kw">&gt;</span>Some text<span class="kw">&lt;/p&gt;</span>
<a id="cb29-2" class="sourceLine" title="2"></a><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"par-1235"</span><span class="kw">&gt;</span>Some other text<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>This allows you to change the appearance of individual paragraphs at a future date without having to change the HTML code &#8211; just the CSS. This can be applied to images, or other blocks of text.<a class="footnote-back" href="#fnref16">↩</a></li>
<li id="fn17">There is complexity in adding links to the articles. By default, anchored text, has a different default colour from surrounding text, hovering a mouse over the link unlerlines the link, a previously visited link has a different colour. You can style the <span class="html-tag">a</span> tag, but the options are more restricted (for security reasons).When <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">.clearfix was discussed</a>, you saw the <span class="css-pseudo-element">::after</span> pseudo element selector. CSS has other selectors as well. The most commonly used with anchor tags are: <span class="css-selector">:hover</span> for styling when the mouse is over the content and <span class="css-selector">:visited</span> which allows styling visited links. You are free to experiment with them now, but they will be covered in a future tutorial.
<p>To disable underlining when hovering over a link, you would apply the following style:</p>
<div id="cb33" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb33-1" class="sourceLine" title="1"></a>a<span class="in">:hover</span> {
<a id="cb33-2" class="sourceLine" title="2"></a>  <span class="kw">text-decoration</span>: <span class="dv">none</span><span class="op">;</span>
<a id="cb33-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p><a class="footnote-back" href="#fnref17">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">CSS &#8211; A More Advanced Float Example: Part 3</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS &#8211; A More Advanced Float Example: Part 2</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-2/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 14:36:01 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3759</guid>

					<description><![CDATA[<p>Having our project in mind, we break it down into the components that we need to think about as we code the page.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-2/">CSS &#8211; A More Advanced Float Example: 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>Every complicated task needs to be broken down into smaller, simpler tasks.</p>
<p>Here we define the general structure before filling in the details in the next tutorial.</p>
</div>
<h2>Contents</h2>
<ol class="incremental" type="1">
<li><a href="#deciding-on-the-overall-structure">Deciding on the Overall Structure</a></li>
<li><a href="#a-skeleton-to-work-with">A Skeleton to Work With</a>
<ol class="incremental" type="1">
<li><a href="#id-styles-in-more-detail">ID Styles in More Detail</a>
<ol class="incremental" type="1">
<li><a href="#wrapper">#wrapper</a></li>
<li><a href="#title">#title</a></li>
<li><a href="#navbar">#navbar</a></li>
<li><a href="#content">#content</a></li>
<li><a href="#footer">#footer</a></li>
</ol>
</li>
<li><a href="#class-styles-in-more-detail">Class Styles in More Detail</a>
<ol class="incremental" type="1">
<li><a href="#column">.column</a></li>
<li><a href="#clearfix">.clearfix</a></li>
</ol>
</li>
<li><a href="#the-html-in-more-detail">The HTML in More Detail</a></li>
</ol>
</li>
<li><a href="#cards">Cards</a></li>
</ol>
<h2 id="deciding-on-the-overall-structure">Deciding on the Overall Structure</h2>
<p>When we examine the <a href="https://engadget.com">engadget</a> website:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3749" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg" alt="A screenshot of a website home page." width="600" height="426" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min-300x213.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>we see that its general structure looks something like this:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3761" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-min.png" alt="High level overview of the page layout" width="600" height="375" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-min.png 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-min-300x188.png 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>It consists of 6 rectangles:</p>
<ul class="incremental">
<li>2 stacked one atop the other at the top</li>
<li>3 stacked side-by-side in the middle</li>
<li>1 at the bottom of the page</li>
</ul>
<p>It should be obvious that the 3 side-by-side columns are positioned using <span class="css-property">float</span>.</p>
<p>Estimating the columns widths, it looks like:</p>
<ul class="incremental">
<li>the narrowest column occupies about 20% of the display</li>
<li>the widest column occupies about 50% of the display</li>
<li>this leaves 30% for the medium width column</li>
</ul>
<p>This is a rough guess, but it is a starting point. As we refine the page, we may adjust the relative widths of the columns to make the layout appear more pleasing.</p>
<p>I will make the content section 960px wide.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a> I previously mentioned that 960px is a good rule of thumb for the content width of a webpage<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></p>
<h2 id="a-skeleton-to-work-with">A Skeleton to Work With</h2>
<p>A rough page skeleton might look something like this:</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="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb1-2" class="sourceLine" title="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb1-3" class="sourceLine" title="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb1-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;title&gt;</span>Rough Layout<span class="kw">&lt;/title&gt;</span>
<a id="cb1-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="cb1-6" class="sourceLine" title="6"></a>
<a id="cb1-7" class="sourceLine" title="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb1-8" class="sourceLine" title="8"></a>
<a id="cb1-9" class="sourceLine" title="9"></a>      <span class="pp">#wrapper</span> {
<a id="cb1-10" class="sourceLine" title="10"></a>        <span class="kw">width</span>: <span class="dv">960</span><span class="dt">px</span><span class="op">;</span>
<a id="cb1-11" class="sourceLine" title="11"></a>        <span class="kw">margin</span>: <span class="bu">auto</span><span class="op">;</span>
<a id="cb1-12" class="sourceLine" title="12"></a>      }
<a id="cb1-13" class="sourceLine" title="13"></a>
<a id="cb1-14" class="sourceLine" title="14"></a>      <span class="pp">#title</span> {
<a id="cb1-15" class="sourceLine" title="15"></a>        <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<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">width</span>: <span class="dv">100</span><span class="dt">%</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="pp">#navbar</span> {
<a id="cb1-21" class="sourceLine" title="21"></a>        <span class="kw">background-color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb1-22" class="sourceLine" title="22"></a>        <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb1-23" class="sourceLine" title="23"></a>        <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-24" class="sourceLine" title="24"></a>      }
<a id="cb1-25" class="sourceLine" title="25"></a>
<a id="cb1-26" class="sourceLine" title="26"></a>      <span class="pp">#content</span> {
<a id="cb1-27" class="sourceLine" title="27"></a>        <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-28" class="sourceLine" title="28"></a>      }
<a id="cb1-29" class="sourceLine" title="29"></a>
<a id="cb1-30" class="sourceLine" title="30"></a>      <span class="pp">#footer</span> {
<a id="cb1-31" class="sourceLine" title="31"></a>        <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-32" class="sourceLine" title="32"></a>      }
<a id="cb1-33" class="sourceLine" title="33"></a>
<a id="cb1-34" class="sourceLine" title="34"></a>      <span class="fu">.column-left</span> {
<a id="cb1-35" class="sourceLine" title="35"></a>        <span class="kw">width</span>: <span class="dv">20</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-36" class="sourceLine" title="36"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-37" class="sourceLine" title="37"></a>      }
<a id="cb1-38" class="sourceLine" title="38"></a>
<a id="cb1-39" class="sourceLine" title="39"></a>      <span class="fu">.column-middle</span> {
<a id="cb1-40" class="sourceLine" title="40"></a>        <span class="kw">width</span>: <span class="dv">50</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-41" class="sourceLine" title="41"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-42" class="sourceLine" title="42"></a>      }
<a id="cb1-43" class="sourceLine" title="43"></a>
<a id="cb1-44" class="sourceLine" title="44"></a>      <span class="fu">.column-right</span> {
<a id="cb1-45" class="sourceLine" title="45"></a>        <span class="kw">width</span>: <span class="dv">30</span><span class="dt">%</span><span class="op">;</span>
<a id="cb1-46" class="sourceLine" title="46"></a>        <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb1-47" class="sourceLine" title="47"></a>      }
<a id="cb1-48" class="sourceLine" title="48"></a>
<a id="cb1-49" class="sourceLine" title="49"></a>      <span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb1-50" class="sourceLine" title="50"></a>        <span class="kw">clear</span>: <span class="dv">both</span><span class="op">;</span>
<a id="cb1-51" class="sourceLine" title="51"></a>        <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb1-52" class="sourceLine" title="52"></a>        <span class="kw">content</span>: <span class="st">""</span><span class="op">;</span>
<a id="cb1-53" class="sourceLine" title="53"></a>      }
<a id="cb1-54" class="sourceLine" title="54"></a>
<a id="cb1-55" class="sourceLine" title="55"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb1-56" class="sourceLine" title="56"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb1-57" class="sourceLine" title="57"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb1-58" class="sourceLine" title="58"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"wrapper"</span><span class="kw">&gt;</span>
<a id="cb1-59" class="sourceLine" title="59"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>Title and Login<span class="kw">&lt;/div&gt;</span>
<a id="cb1-60" class="sourceLine" title="60"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;</span>Navigation Bar and Search<span class="kw">&lt;/div&gt;</span>
<a id="cb1-61" class="sourceLine" title="61"></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="cb1-62" class="sourceLine" title="62"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>Narrowest Column<span class="kw">&lt;/div&gt;</span>
<a id="cb1-63" class="sourceLine" title="63"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-middle"</span><span class="kw">&gt;</span>Widest Column<span class="kw">&lt;/div&gt;</span>
<a id="cb1-64" class="sourceLine" title="64"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-right"</span><span class="kw">&gt;</span>Medium Width Column<span class="kw">&lt;/div&gt;</span>
<a id="cb1-65" class="sourceLine" title="65"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-66" class="sourceLine" title="66"></a>      <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="kw">&gt;</span>The Footer<span class="kw">&lt;/div&gt;</span>
<a id="cb1-67" class="sourceLine" title="67"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb1-68" class="sourceLine" title="68"></a>
<a id="cb1-69" class="sourceLine" title="69"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb1-70" class="sourceLine" title="70"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>The rough layout consists of 5 ID styles and 4 class styles.</p>
<h3 id="id-styles-in-more-detail">ID Styles in More Detail</h3>
<p>If you remember, each ID must be unique<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a> on the page and each HTML element can have only one ID.<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></p>
<p>IDs are used to refer to elements that the should only ever be one of on the page.</p>
<h4 id="wrapper">#wrapper</h4>
<div id="cb2" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb2-1" class="sourceLine" title="1"></a><span class="pp">#wrapper</span> {
<a id="cb2-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">960</span><span class="dt">px</span><span class="op">;</span>
<a id="cb2-3" class="sourceLine" title="3"></a>  <span class="kw">margin</span>: <span class="bu">auto</span><span class="op">;</span>
<a id="cb2-4" class="sourceLine" title="4"></a>}</code></pre>
</div>
<p>Because we are restricting the content width to 960px, we need to wrap all the content in a container that is 960px wide. We also set the <span class="css-property">margin</span> to <span class="css-value">auto</span> so the browser will automatically horizontally center the container in the browser window.<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a></p>
<p>All other elements are styled to occupy the full width of the <strong>#wrapper</strong> by setting their width to 100%.<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a> By using percentages for all other element dimensions, we can change the content width by altering a single value in <strong>#wrapper</strong> instead of having to change it everywhere we use <strong>px</strong>.</p>
<h4 id="title">#title</h4>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" title="1"></a><span class="pp">#title</span> {
<a id="cb3-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb3-3" class="sourceLine" title="3"></a>  <span class="kw">color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb3-4" class="sourceLine" title="4"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb3-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>There should only be one <strong>title</strong> section on a page. We set the background to white (but you can make it any colour you like, you can be creative in your reimagining of the page).</p>
<h4 id="navbar">#navbar</h4>
<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">#navbar</span> {
<a id="cb4-2" class="sourceLine" title="2"></a>  <span class="kw">background-color</span>: <span class="cn">black</span><span class="op">;</span>
<a id="cb4-3" class="sourceLine" title="3"></a>  <span class="kw">color</span>: <span class="cn">white</span><span class="op">;</span>
<a id="cb4-4" class="sourceLine" title="4"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb4-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>There should be only one <strong>navbar</strong> on a page. The background is set to black (but you can make it a different colour if you like). The text colour is set to white so it contrasts against the black background.</p>
<h4 id="content">#content</h4>
<div id="cb5" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb5-1" class="sourceLine" title="1"></a><span class="pp">#content</span> {
<a id="cb5-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb5-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>There should be only one <strong>content</strong> section (even if though it contains 3 columns).</p>
<h4 id="footer">#footer</h4>
<div id="cb6" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb6-1" class="sourceLine" title="1"></a><span class="pp">#footer</span> {
<a id="cb6-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">100</span><span class="dt">%</span><span class="op">;</span>
<a id="cb6-3" class="sourceLine" title="3"></a>}</code></pre>
</div>
<p>There should be only one <strong>footer</strong> on a page.</p>
<h3 id="class-styles-in-more-detail">Class Styles in More Detail</h3>
<h4 id="column">.column</h4>
<div id="cb7" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb7-1" class="sourceLine" title="1"></a><span class="fu">.column-left</span> {
<a id="cb7-2" class="sourceLine" title="2"></a>  <span class="kw">width</span>: <span class="dv">20</span><span class="dt">%</span><span class="op">;</span>
<a id="cb7-3" class="sourceLine" title="3"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb7-4" class="sourceLine" title="4"></a>}
<a id="cb7-5" class="sourceLine" title="5"></a>
<a id="cb7-6" class="sourceLine" title="6"></a><span class="fu">.column-middle</span> {
<a id="cb7-7" class="sourceLine" title="7"></a>  <span class="kw">width</span>: <span class="dv">50</span><span class="dt">%</span><span class="op">;</span>
<a id="cb7-8" class="sourceLine" title="8"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb7-9" class="sourceLine" title="9"></a>}
<a id="cb7-10" class="sourceLine" title="10"></a>
<a id="cb7-11" class="sourceLine" title="11"></a><span class="fu">.column-right</span> {
<a id="cb7-12" class="sourceLine" title="12"></a>  <span class="kw">width</span>: <span class="dv">30</span><span class="dt">%</span><span class="op">;</span>
<a id="cb7-13" class="sourceLine" title="13"></a>  <span class="kw">float</span>: <span class="dv">left</span><span class="op">;</span>
<a id="cb7-14" class="sourceLine" title="14"></a>}</code></pre>
</div>
<p>Because we have 3 unique columns, they could have been made IDs. I decided to make them classes because if I decide to go with a 4 column or 5 column layout, I might be able to reuse existing classes (I could have named the columns better).</p>
<p>They are all floated left and have their widths set as a percentage totaling 100%.</p>
<h4 id="clearfix">.clearfix</h4>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" title="1"></a><span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb8-2" class="sourceLine" title="2"></a>  <span class="kw">clear</span>: <span class="dv">both</span><span class="op">;</span>
<a id="cb8-3" class="sourceLine" title="3"></a>  <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb8-4" class="sourceLine" title="4"></a>  <span class="kw">content</span>: <span class="st">""</span><span class="op">;</span>
<a id="cb8-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>The <strong>clearfix</strong> for the <strong>#content</strong> could have been written as:</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">#content</span><span class="in">::after</span> {
<a id="cb9-2" class="sourceLine" title="2"></a>  <span class="kw">clear</span>: <span class="dv">both</span><span class="op">;</span>
<a id="cb9-3" class="sourceLine" title="3"></a>  <span class="kw">display</span>: <span class="dv">block</span><span class="op">;</span>
<a id="cb9-4" class="sourceLine" title="4"></a>  <span class="kw">content</span>: <span class="st">""</span><span class="op">;</span>
<a id="cb9-5" class="sourceLine" title="5"></a>}</code></pre>
</div>
<p>But, we may find ourselves using <span class="css-property">float</span> in more places as we refine the page, so it is better to have it as a generic <strong>clearfix</strong> that can be applied as needed.</p>
<h3 id="the-html-in-more-detail">The HTML in More Detail</h3>
<div id="cb10" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb10-1" class="sourceLine" title="1"></a><span class="kw">&lt;body&gt;</span>
<a id="cb10-2" class="sourceLine" title="2"></a>  <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"wrapper"</span><span class="kw">&gt;</span>
<a id="cb10-3" class="sourceLine" title="3"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>Title and Login<span class="kw">&lt;/div&gt;</span>
<a id="cb10-4" class="sourceLine" title="4"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"navbar"</span><span class="kw">&gt;</span>Navigation Bar and Search<span class="kw">&lt;/div&gt;</span>
<a id="cb10-5" class="sourceLine" title="5"></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="cb10-6" class="sourceLine" title="6"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-left"</span><span class="kw">&gt;</span>Narrowest Column<span class="kw">&lt;/div&gt;</span>
<a id="cb10-7" class="sourceLine" title="7"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-middle"</span><span class="kw">&gt;</span>Widest Column<span class="kw">&lt;/div&gt;</span>
<a id="cb10-8" class="sourceLine" title="8"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"column-right"</span><span class="kw">&gt;</span>Medium Width Column<span class="kw">&lt;/div&gt;</span>
<a id="cb10-9" class="sourceLine" title="9"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb10-10" class="sourceLine" title="10"></a>    <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="kw">&gt;</span>The Footer<span class="kw">&lt;/div&gt;</span>
<a id="cb10-11" class="sourceLine" title="11"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb10-12" class="sourceLine" title="12"></a>
<a id="cb10-13" class="sourceLine" title="13"></a><span class="kw">&lt;/body&gt;</span></code></pre>
</div>
<p>It should be straightforward:</p>
<ul class="incremental">
<li>the <span class="css-id">#wrapper</span> encloses all the other html</li>
<li>the <span class="css-id">#title</span>, <span class="css-id">#navbar</span>, <span class="css-id">#content</span>, and <span class="css-id">#footer</span> stack one atop the other in <strong>normal flow</strong></li>
<li>the <strong>columns</strong> are left floated inside the #content</li>
</ul>
<h2 id="cards">Cards</h2>
<p>Having completed the basic structure, we can now focus on some of the internal details.</p>
<p>Each column contains a number of stacked cards containing information about the article. Each card contains:</p>
<ol class="incremental" type="1">
<li>An image</li>
<li>A title</li>
<li>A timestamp</li>
</ol>
<p>The HTML should look something like this:</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="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"card"</span><span class="kw">&gt;</span>
<a id="cb11-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="cb11-3" class="sourceLine" title="3"></a>    <span class="kw">&lt;img&gt;</span>
<a id="cb11-4" class="sourceLine" title="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb11-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;&lt;/div&gt;</span>
<a id="cb11-6" class="sourceLine" title="6"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"timestamp"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb11-7" class="sourceLine" title="7"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>It should be straightforward:</p>
<ul class="incremental">
<li>a card consists of a wrapper which I call <span class="css-class">card</span></li>
<li>inside the card wrapper we have the <span class="css-class">image</span>, the article <span class="css-class">headline</span>, and the <span class="css-class">timestamp</span></li>
<li>the actual image is placed inside an <span class="css-class">image</span> container because the image only has a single tag and it is easier to manipulate if we place it inside a <span class="html-tag">div</span> element.<a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a></li>
</ul>
<p>And with some styling it could look something like this:</p>
<div style="width: 240px; background: white; margin: auto;">
<div class="card">
<div class="image"><img loading="lazy" decoding="async" width="960" height="635" class="aligncenter size-full wp-image-3762" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-small-1.jpg" alt="An apple sitting on top of books resting atop a desk." srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-small-1.jpg 960w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-small-1-300x198.jpg 300w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-small-1-768x508.jpg 768w" sizes="auto, (max-width: 960px) 100vw, 960px" /></div>
<div class="headline-small">Foods that boost your learning</div>
<div class="timestamp">🕔 2 Hours</div>
</div>
</div>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-1/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-3/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr>
<ol>
<li id="fn1">If you are curious, the engadget content is 1275px wide. The narrowest column is 255px, the widest column is 680px, and the medium width column is 340px. Corresponding to column widths of 20%, 53.3%, and 26.7% respectively.<a href="#fnref1" class="footnote-back">↩</a></li>
<li id="fn2">See note 4 in the tutorial <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/#playing-around">CSS – Understanding How Float Works – Part 2</a>. It’s a good rule of thumb for desktop webpages because it will render correctly on most desktop browsers.<a href="#fnref2" class="footnote-back">↩</a></li>
<li id="fn3">This was covered in the article <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#id-selector">CSS &#8211; Selecting Specific Elements for Styling</a>.<a href="#fnref3" class="footnote-back">↩</a></li>
<li id="fn4">This was mentioned in a footnote in the article <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-selecting-specific-elements-for-styling/#fn2">CSS &#8211; Selecting Specific Elements for Styling</a>.<a href="#fnref4" class="footnote-back">↩</a></li>
<li id="fn5">Of course, if the browser window is narrower than 960px the page will overflow the browser window &#8211; the likely result being a horizontal scroll bar. In future tutorials, we will see how to dynamically adjust the page width and layout to fit different browser window widths. This is known as <strong>Responsive Web Design</strong><a href="#fnref5" class="footnote-back">↩</a></li>
<li id="fn6">Using percentage as a width value was discussed in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/#percentage-as-a-dimension"></a><a href="#fnref6" class="footnote-back">↩</a></li>
<li id="fn7">This is a common design style: start with the largest structures and nest things inside until we get to the individual elements. It may seem unnecessary, but it makes for easier maintainability. Remember, <span class="html-tag">div</span> has no semantic meaning, it only provides structure. See <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content/#div">Sectioning Using HTML and Auto Centering Content</a><a href="#fnref7" class="footnote-back">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-2/">CSS &#8211; A More Advanced Float Example: Part 2</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS &#8211; A More Advanced Float Example: Part 1</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-1/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 14:23:29 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3748</guid>

					<description><![CDATA[<p>Taking everything we've learned so far and using it to make a more sophisticated page layout using floats.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-1/">CSS &#8211; A More Advanced Float Example: 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>Taking what we know about <span class="css-property">float</span> and creating a more sophisticated webpage layout.</p>
<p>Instead of creating our own layout, we will copy &#8211; more or less &#8211; an existing design.</p>
<p>It doesn’t have to be an exact copy.</p>
</div>
<h2>Contents</h2>
<ol class="incremental" type="1">
<li><a href="#the-objective">The Objective</a></li>
<li><a href="#simplifications">Simplifications</a></li>
<li><a href="#a-tease-of-what-it-could-look-like">A Tease of What It Could Look Like</a></li>
</ol>
<h2 id="the-objective">The Objective</h2>
<ol class="incremental" type="1">
<li>Copy &#8211; more or less &#8211; the layout of the homepage of the website <a href="https://engadget.com">Engadget</a> which can be done using <span class="css-property">float</span>.</li>
<li>Don’t clone the <em>whole</em> page, just the part that you see in your web browser without scrolling. In my browser window, Engadget looks something like this (I eliminated the ads from the page for simplicity):<img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3749" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg" alt="A screenshot of a website home page." width="600" height="426" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/30-float-2-min-300x213.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" />It might look different in your browser.</li>
<li>Don’t make the webpage functional &#8211; just go for the look. Creating clickable article links, a working navigation menu, search and login functions are beyond the scope of this exercise. This exercise is just about layout.</li>
<li>Include a footer at the bottom.</li>
</ol>
<h2 id="simplifications">Simplifications</h2>
<p>To make things easier:</p>
<ol class="incremental" type="1">
<li>Assume the articles in the central column are the same size instead being a large item on top and two smaller items beneath.</li>
<li>Since the only fonts you know<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a> are <span class="css-value">serif</span>, <span class="css-value">sans-serif</span>, and <span class="css-value">monospace</span> don’t worry about trying to match the fonts.<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a></li>
</ol>
<h2 id="a-tease-of-what-it-could-look-like">A Tease of What It Could Look Like</h2>
<p>Over the next two tutorials, I will develop code to create a page that looks like this:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3750" src="https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-float-clone-min.jpg" alt="A screenshot of a website home page." width="600" height="591" srcset="https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-float-clone-min.jpg 600w, https://complete-concrete-concise.com/wp-content/uploads/2019/01/32-float-clone-min-300x296.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>This page is similar, but not identical, to the Engadget homepage.</p>
<p>Depending on your browser display width, the Engadget homepage may appear differently. For displays 960 pixels or wider, it should look similar.</p>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-how-and-when-to-use-float/">Prev</a></p>
</div>
<div class="next">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-2/">Next</a></p>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr>
<ol>
<li id="fn1">Fonts were covered in <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/#font-family">Nine More CSS Properties to Play With</a><a href="#fnref1" class="footnote-back">↩</a></li>
<li id="fn2">Future tutorials will cover how to specify other types of fonts, like: Times New Roman, Helvetica, Comic Sans, etc.<a href="#fnref2" class="footnote-back">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-1/">CSS &#8211; A More Advanced Float Example: 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; How and When to Use Float</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-how-and-when-to-use-float/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 25 Jun 2018 12:54:41 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[box-sizing]]></category>
		<category><![CDATA[calc()]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3743</guid>

					<description><![CDATA[<p>Floats are easier to use when you know when and how you should be using them.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-how-and-when-to-use-float/">CSS &#8211; How and When to Use Float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">While <span class="css-property">float</span> is not ideal for every column organizing idea, it is a tried and true method and works well with older web browsers.<br />
In this tutorial we are going to look at some best practices for the use of floating HTML elements.</div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#divide-the-page-so-floats-are-in-their-own-block">Divide the Page so Floats are in their own Block</a></li>
<li><a href="#float-everything-in-the-same-direction">Float Everything in the Same Direction</a>
<ol type="1">
<li><a href="#everything-floating-left">Everything Floating Left</a></li>
<li><a href="#everything-floating-right">Everything Floating Right</a></li>
<li><a href="#mixed-left-and-right-floats">Mixed Left and Right Floats</a></li>
</ol>
</li>
<li><a href="#when-you-want-floats-to-overlap-other-blocks">When You Want Floats to Overlap other Blocks</a></li>
<li><a href="#float-and-box-sizing"><span class="css-property">float</span> and <span class="css-property">box-sizing</span></a></li>
<li><a href="#calc"><span class="css-function">calc()</span></a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#playing-around">Playing Around</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="divide-the-page-so-floats-are-in-their-own-block">Divide the Page so Floats are in their own Block</h2>
<p>When you <span class="html-tag">div</span>ide up a page, you want to ensure that floating elements are contained inside their own stacking block and <span class="css-class">.clearfix</span> is applied to that block.<br />
Notice how the 3 small floating images are in their own block, with other elements stacking above and below:</p>
<div style="width: 70%; background: yellow; text-align: center; height: 50px; margin: auto; padding-top: 16px;">Header section</div>
<div style="width: 70%; background: green; margin: auto;">
<div style="width: 80%; background: cyan; margin: auto; padding: 2em 0 2em 0; text-align: center;">Large image goes here.</div>
<div style="border: 0.5em solid black;">
<div style="width: 80%; margin: auto;">
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="clear: both;"></div>
</div>
</div>
</div>
<div style="width: 70%; background: fuchsia; text-align: center; margin: auto;">Footer section</div>
<p>In general, you want to use floats to make elements flow horizontally inside a vertically stacking block.<br />
As much as possible, avoid having floating elements actually floating on top of other elements &#8211; but there are exceptions.</p>
<h2 id="float-everything-in-the-same-direction">Float Everything in the Same Direction</h2>
<p>As a general rule, you should float all your elements in the same direction. For English language websites (or any other language that is written from left-to-right), you want to use <span class="css-property">float: left</span>.</p>
<h3 id="everything-floating-left">Everything Floating Left</h3>
<p>Consider the following <span class="css-value">left</span> floating elements which overflow and wrap:</p>
<div style="text-align: center; line-height: 4em;">
<div style="width: 40%; background: yellow; float: left;">float:left</div>
<div style="width: 40%; background: lime; float: left;">float:left</div>
<div style="width: 40%; background: orange; float: left;">float:left</div>
<div style="clear: both; margin: 1em;"></div>
</div>
<p>While there is too much white space on the right side, the overall flow and alignment look fine.</p>
<h3 id="everything-floating-right">Everything Floating Right</h3>
<p>Consider the following <span class="css-value">right</span> floating elements which overflow and wrap:</p>
<div style="text-align: center; line-height: 4em;">
<div style="width: 40%; background: yellow; float: right;">float:right</div>
<div style="width: 40%; background: lime; float: right;">float:right</div>
<div style="width: 40%; background: orange; float: right;">float:right</div>
<div style="clear: both; margin: 1em;"></div>
</div>
<p>There is too much white space on the left side and the right alignment looks somewhat “unnatural” or out of place.<br />
Floating to the right is a good choice for webpages written in languages written from right to left.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></p>
<h3 id="mixed-left-and-right-floats">Mixed Left and Right Floats</h3>
<p>Consider the following floating elements which overflow and wrap. The left-most elements are floated <span class="css-value">left</span> and the right-most element is floated to the <span class="css-value">right</span>:</p>
<div style="text-align: center; line-height: 4em;">
<div style="width: 40%; background: yellow; float: left;">float:left</div>
<div style="width: 40%; background: lime; float: left;">float:left</div>
<div style="width: 40%; background: orange; float: right;">float:right</div>
<div style="clear: both; margin: 1em;"></div>
</div>
<p>The way the content overflows doesn’t look quite right.</p>
<h2 id="when-you-want-floats-to-overlap-other-blocks">When You Want Floats to Overlap other Blocks</h2>
<p>There are times when you want a floating element to overlap other blocks. The most common is getting text to flow around an image:</p>
<div class="html-output"><img decoding="async" style="float: left; margin-right: 1em; width: 125px;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg">Having text flow around an embedded image looks natural and is what most people would expect because this is a common layout style we find in books and magazines.<br />
So this is one case where it makes sense to allow a floating image block to overlap with paragraph blocks.</div>
<p>Another common case is when you want to insert a side note or comment as a visible part of your content.<br />
Consider the following (although you might want to justify the text to make it less ragged):</p>
<div class="html-output">Another common use for a float that overlaps HTML blocks in your content is when you want to insert some sort of side note for the reader.</p>
<div style="float: right; background: cornsilk; border: 1px solid black; margin-left: 1em; width: 35%; padding: 0.5em;">According to legend, Galileo Galilei dropped two canon balls of different mass from the top of the tower to show they fell at the same speed.</div>
<p>For example, you might be writing a document on the Tower of Pisa &#8211; which is more commonly known as the “Leaning Tower of Pisa”.<br />
In the course of the article you will likely mention a number of facts about the tower. You might also want to mention something that doesn’t really belong in the main text, but is still a fun fact.<br />
One way to do this would be to use a footnote or endnote. Another way, would be to insert it into the main text, but set it apart.</p>
</div>
<p>When you choose to deliberately overlap HTML blocks, you need to be careful about ensuring the floating element does not overlap blocks it shouldn’t.</p>
<h2 id="float-and-box-sizing"><span class="css-property">float</span> and <span class="css-property">box-sizing</span></h2>
<p>Earlier, we saw <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with#box-sizing">the <span class="css-property">box-sizing</span> property</a> which instructs the User Agent (browser) to size HTML elements by either content area (default) or border. Recall the CSS box model:<br />
<img decoding="async" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-css-box-model.png"><br />
Sizing using the <span class="css-value">content-box</span> does not include the padding, border, or margin when setting the size of the HTML element.<br />
Sizing using the <span class="css-value">border-box</span> includes the padding and border when setting the size of an HTML element. It does not include the margin in the size of the element.<br />
For <strong>normal flow</strong> objects, this doesn’t make much difference to the layout since objects just flow downwards.<br />
When we apply <span class="css-property">float</span> to objects, they flow horizontally and will overflow and wrap around when they reach the edge of the browser &#8211; so we have to be more careful when specifying dimensions for floating objects. It is usually best to use <span class="css-property">box-sizing: border-box</span> for floating HTML elements. Consider the following styling and code:</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb1-1" class="sourceLine" data-line-number="1"></a><span class="fu">.parent</span> {
<a id="cb1-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb1-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">width</span>: <span class="dv">300px</span>;
<a id="cb1-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb1-5" class="sourceLine" data-line-number="5"></a>}
<a id="cb1-6" class="sourceLine" data-line-number="6"></a>
<a id="cb1-7" class="sourceLine" data-line-number="7"></a><span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb1-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">clear</span>: <span class="dv">both</span>;
<a id="cb1-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">display</span>: <span class="dv">block</span>;
<a id="cb1-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">content</span>: <span class="st">""</span>;
<a id="cb1-11" class="sourceLine" data-line-number="11"></a>}
<a id="cb1-12" class="sourceLine" data-line-number="12"></a>
<a id="cb1-13" class="sourceLine" data-line-number="13"></a><span class="fu">.block</span> {
<a id="cb1-14" class="sourceLine" data-line-number="14"></a>  <span class="kw">width</span>: <span class="dv">100px</span>;
<a id="cb1-15" class="sourceLine" data-line-number="15"></a>  <span class="kw">height</span>: <span class="dv">50px</span>;
<a id="cb1-16" class="sourceLine" data-line-number="16"></a>  <span class="kw">background-color</span>: <span class="dv">red</span>;
<a id="cb1-17" class="sourceLine" data-line-number="17"></a>  <span class="kw">float</span>:<span class="dv">left</span>;
<a id="cb1-18" class="sourceLine" data-line-number="18"></a>}</code></pre>
</div>
<div id="cb2" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb2-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"parent clearfix"</span><span class="kw">&gt;</span>
<a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"block"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"block"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"block"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Which results in:</p>
<div class="html-output">
<div style="margin: auto; width: 300px; background-color: yellow;">
<div style="width: 100px; height: 50px; background-color: red; float: left;"></div>
<div style="width: 100px; height: 50px; background-color: red; float: left;"></div>
<div style="width: 100px; height: 50px; background-color: red; float: left;"></div>
<div style="clear: both;"></div>
</div>
</div>
<p>There is no obvious separation between one child block and another, since they all run together. The obvious solution is to insert a bit of space between them. We can do this by giving each child block a small margin (let’s say 10px all around):</p>
<div class="html-output">
<div style="margin: auto; width: 300px; background-color: yellow;">
<div style="width: 100px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="width: 100px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="width: 100px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="clear: both;"></div>
</div>
</div>
<p>Unfortunately, this causes the child blocks to overflow and wrap around. Remember:</p>
<ol type="1">
<li>the parent container is 300px wide,</li>
<li>each child is 100px wide,</li>
<li>each child has a 10px margin,</li>
<li>this makes each child block 100px + 10px + 10 px = 120px wide (there are 10px for the left margin and 10px for the right margin) and</li>
<li>50px + 10px + 10px = 70px high (there are 10px for the top margin and 10px for the bottom margin)</li>
</ol>
<p>The height of the child blocks is not the problem for us, it is the width, so we can adjust our CSS to account for the 10px margin on the left and right of the child block:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb3-1" class="sourceLine" data-line-number="1"></a><span class="fu">.block</span> {
<a id="cb3-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">10px</span>;
<a id="cb3-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">width</span>: <span class="dv">80px</span>;
<a id="cb3-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">height</span>: <span class="dv">50px</span>;
<a id="cb3-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">background-color</span>: <span class="dv">red</span>;
<a id="cb3-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">float</span>:<span class="dv">left</span>;
<a id="cb3-7" class="sourceLine" data-line-number="7"></a>}</code></pre>
</div>
<p>Which gives us the result we would expect:</p>
<div class="html-output">
<div style="margin: auto; width: 300px; background-color: yellow;">
<div style="width: 80px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="width: 80px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="width: 80px; height: 50px; background-color: red; float: left; margin: 10px;"></div>
<div style="clear: both;"></div>
</div>
</div>
<p>If we decide to add a border (even just a 1px border) or padding (even just 1px of padding), it will cause the elements to wrap (again).<br />
We can compensate by subtracting the added widths of our border and padding, or we can set the <span class="css-property">box-sizing</span> property to <span class="css-value">border-box</span>:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb4-1" class="sourceLine" data-line-number="1"></a>* {
<a id="cb4-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>Using the <strong>universal</strong> selector will cause all HTML elements to be sized according to their borders and not their content area. Personally, I think it is easier and more intuitive to work this way. When you layout the content on a page you imagine each block of content as being completely self contained &#8211; i.e., it includes the content, the padding around the content, and the border around the content. However, you do have to compensate for any margins you might use.</p>
<h2 id="calc"><span class="css-function">calc()</span></h2>
<p>We’ve seen that <strong>%</strong> is a more convenient way of dimensioning floating elements than using pixels. If you want 3 equally sized columns you can make them each <span class="css-value">33.33%</span> of the width of the parent container. You could also make 2 of them <span class="css-value">25%</span> and one <span class="css-value">50%</span>. Unfortunately, this makes compensating for margins a bit trickier.<br />
CSS has a function called <span class="css-function">calc()</span> that makes this a lot easier. You simply enter the dimensions &#8211; even if they are different units &#8211; and <span class="css-function">calc()</span> will perform the necessary calculation for you.<br />
Taking the example above, we can write the CSS code for the blocks as follows:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb5-1" class="sourceLine" data-line-number="1"></a><span class="fu">.block</span> {
<a id="cb5-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">10px</span>;
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">width</span>: calc(<span class="dv">33.33%</span> - <span class="dv">10px</span> - <span class="dv">10px</span>);
<a id="cb5-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">height</span>: <span class="dv">50px</span>;
<a id="cb5-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">background-color</span>: <span class="dv">red</span>;
<a id="cb5-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">float</span>:<span class="dv">left</span>;
<a id="cb5-7" class="sourceLine" data-line-number="7"></a>}</code></pre>
</div>
<p>The <span class="css-property">width</span> is set to <span class="css-value">33.33%</span> less <span class="css-value">10px</span> for the left margin and <span class="css-value">10px</span> for the right margin. It could have also been written as <span class="css-function">calc(33.33% &#8211; 20px)</span>, but I chose to <strong>explicitly</strong> subtract each margin independently for clarity.</p>
<h2 id="summary">Summary</h2>
<ol type="1">
<li>Divide the vertically stacking blocks</li>
<li>Try to contain horizontally stacking blocks (floating elements) in their own vertically stacking block.</li>
<li>As a general rules, you want all your floats to go in the same direction. In most cases this will be <span class="cwss-property">float: left</span>. If you are developing webpages for a language that is written right-to-left, you will prefer [float: right]{css-property}</li>
<li>Mixing <span class="cwss-property">float: left</span> and <span class="cwss-property">float: right</span> in the same containing block is, usually, a bad idea.</li>
<li>Sometimes, you do want floating elements to overlap other blocks (like images, or side notes). In this case, you need to ensure appropriate overlapping.</li>
<li>Setting your HTML elements to have <span class="css-property">box-sizing: border-box</span> makes it easier to layout horizontally flowing elements, since it takes into account any border and padding values you set.</li>
<li>Regardless of which <span class="css-property">box-sizing</span> model you choose, you must always compensate for any margin values you apply.</li>
<li>The CSS function <span class="css-function">calc()</span> makes it easier to compute box sizes. It even allows mixing units (like pixels and % together).</li>
</ol>
<h2 id="playing-around">Playing Around</h2>
<h3 id="dividing-up-a-page">Dividing Up a Page</h3>
<p>Learning how to divide up a page layout into HTML block elements is crucial to being able to code that page.</p>
<ol type="1">
<li>Explore a number of websites (news websites tend to be very good for this<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a>) and pay attention to how the pages are laid out.</li>
<li>How would you arrange the various HTML elements to create a similar layout?
<ol type="1">
<li>Which are the vertically flowing blocks?</li>
<li>How are vertical elements nested inside of blocks?</li>
</ol>
</li>
<li>Can you code a page with a similar layout?</li>
</ol>
<p>Many of these sites have very long pages. It is not necessary to replicate the entire page from top to bottom &#8211; just focus on the portion of the page you see in your browser window.<br />
Don’t try to mimic all the functionality or behaviour. You haven’t learned to embed videos yet (just substitute a picture). There are effects (like shadows, animations, or dropdowns) that you haven’t learned either. Just focus on getting the general layout and look, more or less, right.</p>
<h3 id="box-sizing-and-calc"><span class="css-property">box-sizing</span> and <span class="css-function">calc()</span></h3>
<ol type="1">
<li>Experiment with using <span class="css-property">box-sizing: border-box</span>. You can do this by setting all HTML elements to have this property.</li>
<li>Experiment using the <span class="css-function">calc()</span> function.</li>
</ol>
<p>You can use these with the page layouts you try out above.</p>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://www.w3.org/TR/CSS21/visuren.html#propdef-float"><span class="css-property">float</span> property</a></li>
<li><a href="https://www.w3.org/TR/CSS21/visuren.html#propdef-clear"><span class="css-property">clear</span> property</a></li>
<li><a href="https://drafts.csswg.org/css-ui-3/#box-sizing"><span class="css-property">box-sizing</span> property</a></li>
<li><a href="https://drafts.csswg.org/css-values-3/#calc-notation"><span class="css-function">calc()</span> function</a></li>
</ol>
<div class="prev"><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-simple-page-using-float">Prev</a></div>
<div class="next"><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-more-advanced-float-example-part-1/">Next</a></div>
<div class="clear"></div>
<section class="footnotes">
<hr>
<ol>
<li id="fn1">The most commonly used RTL languages are Arabic, Hebrew, Persian, and Urdu.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">Some sites that I find interesting for their layout include: <a href="https://www.cbc.ca/">CBC</a>, <a href="https://bbc.co.uk">BBC</a>, <a href="https://www.engadget.com/">Engadget</a>. Of course, you are free to try and copy the look and layout of other sites as well.<a class="footnote-back" href="#fnref2">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-how-and-when-to-use-float/">CSS &#8211; How and When to Use Float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CSS &#8211; A Simple Page Using Float</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-simple-page-using-float/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 30 May 2018 06:58:32 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3729</guid>

					<description><![CDATA[<p>A simple example putting theoretical knowledge of floats into practice.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-simple-page-using-float/">CSS &#8211; A Simple Page Using Float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
The previous <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2">exercise</a> asked to create a page with the following layout:</p>
<div style="width: 70%; background: yellow; text-align: center; height: 50px; margin: auto; padding-top: 16px;">Header section</div>
<div style="width: 70%; background: green; margin: auto;">
<div style="width: 80%; background: cyan; margin: auto; padding: 2em 0 2em 0; text-align: center;">Large image goes here.</div>
<div style="width: 80%; height: 50px; margin: auto; margin-top: 20px;">
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="width: 30%; height: 50px; margin: 1.66%; background: lime; text-align: center; float: left;">Smaller image</div>
<div style="clear: both;"></div>
</div>
<div style="clear: both;"></div>
</div>
<div style="width: 70%; background: fuchsia; text-align: center; margin: auto;">Footer section</div>
<p>The purpose being to try and use floating elements in a design.
</p></div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#an-example-using-float">An Example Using <span class="css-property">float</span></a></li>
<li><a href="#source-code">Source Code</a></li>
<li><a href="#notes">Notes</a></li>
<li><a href="#image-credits">Image Credits</a></li>
</ol>
<h2 id="an-example-using-float">An Example Using <span class="css-property">float</span></h2>
<p>You can see how the page I styled and structured using <span class="css-property">float</span> looks <a href="https://complete-concrete-concise.com/sample/28-float-example.html">here</a>.</p>
<h2 id="source-code">Source Code</h2>
<div id="cb1" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb1-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb1-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb1-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb1-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Floating on Dreams<span class="kw">&lt;/title&gt;</span>
<a id="cb1-5" class="sourceLine" data-line-number="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="cb1-6" class="sourceLine" data-line-number="6"></a>
<a id="cb1-7" class="sourceLine" data-line-number="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb1-8" class="sourceLine" data-line-number="8"></a>
<a id="cb1-9" class="sourceLine" data-line-number="9"></a>      <span class="pp">#title</span> {
<a id="cb1-10" class="sourceLine" data-line-number="10"></a>        <span class="kw">font-size</span>: <span class="dv">48px</span>;
<a id="cb1-11" class="sourceLine" data-line-number="11"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb1-12" class="sourceLine" data-line-number="12"></a>      }
<a id="cb1-13" class="sourceLine" data-line-number="13"></a>
<a id="cb1-14" class="sourceLine" data-line-number="14"></a>      <span class="pp">#subtitle</span> {
<a id="cb1-15" class="sourceLine" data-line-number="15"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb1-16" class="sourceLine" data-line-number="16"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb1-17" class="sourceLine" data-line-number="17"></a>      }
<a id="cb1-18" class="sourceLine" data-line-number="18"></a>
<a id="cb1-19" class="sourceLine" data-line-number="19"></a>      <span class="fu">.main</span> {
<a id="cb1-20" class="sourceLine" data-line-number="20"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;
<a id="cb1-21" class="sourceLine" data-line-number="21"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<a id="cb1-22" class="sourceLine" data-line-number="22"></a>        <span class="kw">width</span>: <span class="dv">960px</span>;
<a id="cb1-23" class="sourceLine" data-line-number="23"></a>        <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb1-24" class="sourceLine" data-line-number="24"></a>      }
<a id="cb1-25" class="sourceLine" data-line-number="25"></a>
<a id="cb1-26" class="sourceLine" data-line-number="26"></a>      <span class="fu">.header</span> {
<a id="cb1-27" class="sourceLine" data-line-number="27"></a>
<a id="cb1-28" class="sourceLine" data-line-number="28"></a>      }
<a id="cb1-29" class="sourceLine" data-line-number="29"></a>
<a id="cb1-30" class="sourceLine" data-line-number="30"></a>      <span class="fu">.images</span> {
<a id="cb1-31" class="sourceLine" data-line-number="31"></a>      }
<a id="cb1-32" class="sourceLine" data-line-number="32"></a>
<a id="cb1-33" class="sourceLine" data-line-number="33"></a>      <span class="fu">.large-image</span> {
<a id="cb1-34" class="sourceLine" data-line-number="34"></a>          <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb1-35" class="sourceLine" data-line-number="35"></a>      }
<a id="cb1-36" class="sourceLine" data-line-number="36"></a>
<a id="cb1-37" class="sourceLine" data-line-number="37"></a>      <span class="fu">.small-image-container</span> {
<a id="cb1-38" class="sourceLine" data-line-number="38"></a>
<a id="cb1-39" class="sourceLine" data-line-number="39"></a>      }
<a id="cb1-40" class="sourceLine" data-line-number="40"></a>
<a id="cb1-41" class="sourceLine" data-line-number="41"></a>      <span class="fu">.small-image</span> {
<a id="cb1-42" class="sourceLine" data-line-number="42"></a>          <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb1-43" class="sourceLine" data-line-number="43"></a>          <span class="kw">margin</span>: <span class="dv">50px</span> <span class="dv">10px</span> <span class="dv">0</span> <span class="dv">10px</span>;
<a id="cb1-44" class="sourceLine" data-line-number="44"></a>      }
<a id="cb1-45" class="sourceLine" data-line-number="45"></a>
<a id="cb1-46" class="sourceLine" data-line-number="46"></a>      <span class="fu">.footer</span> {
<a id="cb1-47" class="sourceLine" data-line-number="47"></a>          <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb1-48" class="sourceLine" data-line-number="48"></a>      }
<a id="cb1-49" class="sourceLine" data-line-number="49"></a>
<a id="cb1-50" class="sourceLine" data-line-number="50"></a>      <span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb1-51" class="sourceLine" data-line-number="51"></a>        <span class="kw">clear</span>: <span class="dv">both</span>;
<a id="cb1-52" class="sourceLine" data-line-number="52"></a>        <span class="kw">display</span>: <span class="dv">block</span>;
<a id="cb1-53" class="sourceLine" data-line-number="53"></a>        <span class="kw">content</span>: <span class="st">""</span>;
<a id="cb1-54" class="sourceLine" data-line-number="54"></a>      }
<a id="cb1-55" class="sourceLine" data-line-number="55"></a>
<a id="cb1-56" class="sourceLine" data-line-number="56"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb1-57" class="sourceLine" data-line-number="57"></a>
<a id="cb1-58" class="sourceLine" data-line-number="58"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb1-59" class="sourceLine" data-line-number="59"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb1-60" class="sourceLine" data-line-number="60"></a>
<a id="cb1-61" class="sourceLine" data-line-number="61"></a>    <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"main"</span><span class="kw">&gt;</span>
<a id="cb1-62" class="sourceLine" data-line-number="62"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"header"</span><span class="kw">&gt;</span>
<a id="cb1-63" class="sourceLine" data-line-number="63"></a>        <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>Floating on Dreams<span class="kw">&lt;/p&gt;</span>
<a id="cb1-64" class="sourceLine" data-line-number="64"></a>        <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"subtitle"</span><span class="kw">&gt;</span>A simple page using floats<span class="kw">&lt;/p&gt;</span>
<a id="cb1-65" class="sourceLine" data-line-number="65"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-66" class="sourceLine" data-line-number="66"></a>
<a id="cb1-67" class="sourceLine" data-line-number="67"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"images"</span><span class="kw">&gt;</span>
<a id="cb1-68" class="sourceLine" data-line-number="68"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"large-image"</span><span class="kw">&gt;</span>
<a id="cb1-69" class="sourceLine" data-line-number="69"></a>          <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"28-big-image.jpg"</span><span class="kw">&gt;</span>
<a id="cb1-70" class="sourceLine" data-line-number="70"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb1-71" class="sourceLine" data-line-number="71"></a>
<a id="cb1-72" class="sourceLine" data-line-number="72"></a>        <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"small-image-container clearfix"</span><span class="kw">&gt;</span>
<a id="cb1-73" class="sourceLine" data-line-number="73"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"small-image"</span><span class="kw">&gt;</span>
<a id="cb1-74" class="sourceLine" data-line-number="74"></a>            <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"28-small-1.jpg"</span><span class="kw">&gt;</span>
<a id="cb1-75" class="sourceLine" data-line-number="75"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-76" class="sourceLine" data-line-number="76"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"small-image"</span><span class="kw">&gt;</span>
<a id="cb1-77" class="sourceLine" data-line-number="77"></a>            <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"28-small-2.jpg"</span><span class="kw">&gt;</span>
<a id="cb1-78" class="sourceLine" data-line-number="78"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-79" class="sourceLine" data-line-number="79"></a>          <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"small-image"</span><span class="kw">&gt;</span>
<a id="cb1-80" class="sourceLine" data-line-number="80"></a>            <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"28-small-3.jpg"</span><span class="kw">&gt;</span>
<a id="cb1-81" class="sourceLine" data-line-number="81"></a>          <span class="kw">&lt;/div&gt;</span>
<a id="cb1-82" class="sourceLine" data-line-number="82"></a>        <span class="kw">&lt;/div&gt;</span>
<a id="cb1-83" class="sourceLine" data-line-number="83"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-84" class="sourceLine" data-line-number="84"></a>
<a id="cb1-85" class="sourceLine" data-line-number="85"></a>      <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"footer"</span><span class="kw">&gt;</span>
<a id="cb1-86" class="sourceLine" data-line-number="86"></a>        <span class="kw">&lt;p&gt;</span>Copyright 2018<span class="kw">&lt;/p&gt;</span>
<a id="cb1-87" class="sourceLine" data-line-number="87"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-88" class="sourceLine" data-line-number="88"></a>
<a id="cb1-89" class="sourceLine" data-line-number="89"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb1-90" class="sourceLine" data-line-number="90"></a>
<a id="cb1-91" class="sourceLine" data-line-number="91"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb1-92" class="sourceLine" data-line-number="92"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h2 id="notes">Notes</h2>
<ol type="1">
<li>The first thing that needs to be done is to divide the document into nesting and stacking HTML blocks.</li>
<li>This is one possible way to section the document: <a href="https://complete-concrete-concise.com/wp-content/uploads/2018/05/28-float.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3731" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/28-float.png" alt="" width="600" height="800" /></a></li>
<li>There is always a <strong>Main</strong> container which contains all the content. It was set to have a width of 960 pixels.</li>
<li>The <strong>Header</strong> and <strong>Footer</strong> blocks are nested inside the <strong>main</strong> container.</li>
<li>Between the <strong>header</strong> and <strong>footer</strong> there is some content. The content (in this case) is images and is contained within an <strong>Images</strong> container.</li>
<li>Nested inside the <strong>images</strong> container is a stacking of large and small images.</li>
<li>The large image has its own container</li>
<li>The small floating images are wrapped in their own container so they act like a single block. The small images block has <span class="css-class">.clearfix</span> applied to it.</li>
<li>Not all the sectioning <span class="html-tag">div</span>s have styling applied since their sole purpose is to provide structure.</li>
<li>While styling could have been applied directly to the <span class="html-tag">img</span> tags, I chose to wrap them in a <span class="html-tag">div</span> because it allows for greater flexibility in the future.
<ul>
<li>Imagine turning those small floating images into a “card”:
<div style="border: 2px solid black; width: 320px; background: gold;">
<img decoding="async" style="margin: 10px 0 0 10px;" src="https://complete-concrete-concise.com/sample/28-small-3.jpg" /></p>
<p style="font-size: 24px; text-align: center;">A Pensive Cat</p>
</div>
</li>
</ul>
</li>
</ol>
<h2 id="image-credits">Image Credits</h2>
<p>The images I used are courtesy of:</p>
<ol type="1">
<li><a href="https://pixabay.com/en/natural-landscape-azores-nature-1758541/">charloisporto</a> : Tranquil nature scene</li>
<li><a href="https://pixabay.com/en/fruit-fruits-fruit-salad-frisch-2305192/">silviarita</a> : Fruit salad</li>
<li><a href="https://pixabay.com/en/relaxation-yoga-the-concentration-of-1967892/">Ataner007</a> : Woman meditating</li>
<li><a href="https://pixabay.com/en/cat-young-animal-curious-wildcat-2083492/">susannp4</a> : Cat</li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-how-and-when-to-use-float">Next</a>
</div>
<div class="clear"></div>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-simple-page-using-float/">CSS &#8211; A Simple Page Using Float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
