 
    
<?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>html5 Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/html5/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/html5/</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>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>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>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 fetchpriority="high" 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="(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 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="(max-width: 600px) 100vw, 600px" /></p>
<p>we see that its general structure looks something like this:</p>
<p><img 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="(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>
		<item>
		<title>CSS &#8211; Understanding How Float Works &#8211; Part 2</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Thu, 24 May 2018 15:44:45 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></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=3709</guid>

					<description><![CDATA[<p>Delving deeper into how floating elements position themselves side-to-side instead of top-to-bottom.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/">CSS &#8211; Understanding How Float Works &#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">
We’ve seen that the <span class="css-property">float</span> can be used to place an HTML to the side of other content.<br />
How does it do this and why does it seem to overlap other HTML elements?
</div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#floated-elements-flow-sideways">Floated Elements Flow Sideways</a></li>
<li><a href="#floating-elements-wrap-if-there-is-not-enough-space">Floating Elements Wrap If There Is Not Enough Space</a></li>
<li><a href="#wrapping-is-dependent-on-which-way-the-element-floats">Wrapping is Dependent on Which Way the Element Floats</a></li>
<li><a href="#percentage-as-a-dimension">Percentage as a Dimension</a></li>
<li><a href="#marginauto-has-no-effect-on-floats"><span class="css-property">margin:auto</span> Has No Effect on Floats</a></li>
<li><a href="#expanding-a-floating-child-to-fit-its-parent">Expanding a Floating Child to Fit Its Parent</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="floated-elements-flow-sideways">Floated Elements Flow Sideways</h2>
<p>HTML elements flow from top to bottom in the order in which they appear in the HTML document. This is called <strong>normal flow</strong>.<br />
Floating elements are outside of <strong>normal flow</strong> and do not stack top to bottom. Instead, they stack from <em>left-to-right</em> for <span class="css-value">left</span> floated elements and <em>right-to-left</em> for <span class="css-value">right</span> floated elements.<br />
Consider the following code:<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></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">.box</span> {
<a id="cb1-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">width</span>: <span class="dv">50px</span>;
<a id="cb1-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">height</span>: <span class="dv">50px</span>;
<a id="cb1-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">border</span>: <span class="dv">1px</span> <span class="dv">solid</span> <span class="dv">black</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">.left</span> {
<a id="cb1-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb1-9" class="sourceLine" data-line-number="9"></a>}
<a id="cb1-10" class="sourceLine" data-line-number="10"></a>
<a id="cb1-11" class="sourceLine" data-line-number="11"></a><span class="fu">.right</span> {
<a id="cb1-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">float</span>: <span class="dv">right</span>;
<a id="cb1-13" class="sourceLine" data-line-number="13"></a>}
<a id="cb1-14" class="sourceLine" data-line-number="14"></a>
<a id="cb1-15" class="sourceLine" data-line-number="15"></a><span class="fu">.centre</span> {
<a id="cb1-16" class="sourceLine" data-line-number="16"></a>  <span class="kw">margin</span>: <span class="dv">auto</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">.yellow</span> {
<a id="cb1-20" class="sourceLine" data-line-number="20"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb1-21" class="sourceLine" data-line-number="21"></a>}
<a id="cb1-22" class="sourceLine" data-line-number="22"></a>
<a id="cb1-23" class="sourceLine" data-line-number="23"></a><span class="fu">.lime</span> {
<a id="cb1-24" class="sourceLine" data-line-number="24"></a>  <span class="kw">background-color</span>: <span class="dv">lime</span>;
<a id="cb1-25" class="sourceLine" data-line-number="25"></a>}
<a id="cb1-26" class="sourceLine" data-line-number="26"></a>
<a id="cb1-27" class="sourceLine" data-line-number="27"></a><span class="fu">.orange</span> {
<a id="cb1-28" class="sourceLine" data-line-number="28"></a>  <span class="kw">background-color</span>: orange;
<a id="cb1-29" class="sourceLine" data-line-number="29"></a>}
<a id="cb1-30" class="sourceLine" data-line-number="30"></a>
<a id="cb1-31" class="sourceLine" data-line-number="31"></a><span class="fu">.cyan</span> {
<a id="cb1-32" class="sourceLine" data-line-number="32"></a>  <span class="kw">background-color</span>: <span class="dv">cyan</span>;
<a id="cb1-33" class="sourceLine" data-line-number="33"></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">"box yellow left"</span><span class="kw">&gt;&lt;/div&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">"box lime left"</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">"box orange left"</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">"box cyan left"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-5" class="sourceLine" data-line-number="5"></a>
<a id="cb2-6" class="sourceLine" data-line-number="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box yellow right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box lime right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box orange right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-9" class="sourceLine" data-line-number="9"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box cyan right"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-10" class="sourceLine" data-line-number="10"></a>
<a id="cb2-11" class="sourceLine" data-line-number="11"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box yellow centre"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box lime centre"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-13" class="sourceLine" data-line-number="13"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box orange centre"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb2-14" class="sourceLine" data-line-number="14"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box cyan centre"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<p>Which gives the following output:</p>
<div class="html-output">
<style>.box {width: 50px; height: 50px; border: 1px solid black;} .left {  float: left;} .right {  float: right;} .centre {  margin: auto;} .yellow {  background-color: yellow;} .lime {  background-color: lime;} .orange {  background-color: orange;} .cyan {  background-color: cyan;}</style>
<div class="box yellow left"></div>
<div class="box lime left"></div>
<div class="box orange left"></div>
<div class="box cyan left"></div>
<div class="box yellow right"></div>
<div class="box lime right"></div>
<div class="box orange right"></div>
<div class="box cyan right"></div>
<div class="box yellow centre"></div>
<div class="box lime centre"></div>
<div class="box orange centre"></div>
<div class="box cyan centre"></div>
</div>
<p>You will notice that:</p>
<ol type="1">
<li>3 sets of coloured boxes are declared in the same order (<span class="css-class">.yellow</span>, <span class="css-class">.lime</span>, <span class="css-class">.orange</span>, and <span class="css-class">.cyan</span>)</li>
<li>each set of boxes is given a different alignment class (<span class="css-class">.left</span>, <span class="css-class">.right</span>, or <span class="css-class">.centre</span>)</li>
<li>the boxes on the left stack from <strong>left-to-right</strong> in the same order they were declared</li>
<li>the boxes on the right stack from <strong>right-to-left</strong> in the same order they were declared</li>
<li>the boxes in the middle stack from <strong>top to bottom</strong> in the same order they were declared</li>
<li>because the <span class="css-class">.left</span> boxes and <span class="css-class">.right</span> boxes are not in <strong>normal flow</strong>, the <span class="css-class">.centre</span> stacked boxes occupy their place in the <strong>normal flow</strong>.</li>
</ol>
<p>Recall that (relative to their parent):</p>
<ol type="1">
<li>floating elements float up as high as they can. They stop when they either encounter the top margin of their parent or the bottom margin of a non-floating element.</li>
<li>floating elements float as far to the side as they can. They stop when they either encounter the side margin of their parent or the side margin of another floating element.</li>
</ol>
<p>This is exactly what we observe in the example above:</p>
<ol type="1">
<li>the floated elements are declared at the top of the document, so they float up to the margin of the parent &#8211; they are not stopped by the bottom margin of other floating elements</li>
<li>the floated elements flow as far to the side as they can and are stopped either by the side margin of the parent (the yellow block) or the side margin of another floating element (the other blocks).</li>
</ol>
<h2 id="floating-elements-wrap-if-there-is-not-enough-space">Floating Elements Wrap If There Is Not Enough Space</h2>
<p>Elements in <strong>normal flow</strong> stack one atop the other and continue down the bottom of the page as far as needed.<br />
Floated elements do not stack sideways as far as they can go &#8211; they are constrained by the width of their parent (assuming you don’t make the child wider than its parent). Any floating elements for which there is not enough room to stack sideways will flow to the next line.<br />
Consider the following 4 <span class="css-value">left</span> floating blocks (they are scaled to each take up 25% of the available width):</p>
<div class="html-output">
<div style="width: 25%; height: 50px; background: yellow; float: left;"></div>
<div style="width: 25%; height: 50px; background: lime; float: left;"></div>
<div style="width: 25%; height: 50px; background: orange; float: left;"></div>
<div style="width: 25%; height: 50px; background: cyan; float: left;"></div>
<div style="clear: both;"></div>
</div>
<p>They all line up in a single line as expected.<br />
If we make them a little wider, say 26% of the width of the parent container:</p>
<div class="html-output">
<div style="width: 26%; height: 50px; background: yellow; float: left;"></div>
<div style="width: 26%; height: 50px; background: lime; float: left;"></div>
<div style="width: 26%; height: 50px; background: orange; float: left;"></div>
<div style="width: 26%; height: 50px; background: cyan; float: left;"></div>
<div style="clear: both;"></div>
</div>
<p>We see that the blue block, because it doesn’t fit, automatically wraps to the next line and moves as far left as it can.<br />
A similar thing happens for <span class="css-value">right</span> floated elements &#8211; except everything moves as far right as it can:</p>
<div class="html-output">
<div style="width: 26%; height: 50px; background: yellow; float: right;"></div>
<div style="width: 26%; height: 50px; background: lime; float: right;"></div>
<div style="width: 26%; height: 50px; background: orange; float: right;"></div>
<div style="width: 26%; height: 50px; background: cyan; float: right;"></div>
<div style="clear: both;"></div>
</div>
<h2 id="wrapping-is-dependent-on-which-way-the-element-floats">Wrapping is Dependent on Which Way the Element Floats</h2>
<p>Sometimes, you can get some unexpected float behaviour if you don’t remember that floating elements:</p>
<ol type="1">
<li>float up as high as they can</li>
<li>then float to the side</li>
<li>in the order they are declared in the document.</li>
</ol>
<p>Consider the following:</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">.parent</span> {
<a id="cb3-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">width</span>: <span class="dv">400px</span>;
<a id="cb3-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">background-color</span>: <span class="dv">red</span>;
<a id="cb3-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb3-5" class="sourceLine" data-line-number="5"></a>}
<a id="cb3-6" class="sourceLine" data-line-number="6"></a>
<a id="cb3-7" class="sourceLine" data-line-number="7"></a><span class="fu">.left-box</span> {
<a id="cb3-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">width</span>: <span class="dv">250px</span>;
<a id="cb3-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">height</span>: <span class="dv">100px</span>;
<a id="cb3-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb3-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb3-12" class="sourceLine" data-line-number="12"></a>}
<a id="cb3-13" class="sourceLine" data-line-number="13"></a>
<a id="cb3-14" class="sourceLine" data-line-number="14"></a><span class="fu">.right-box</span> {
<a id="cb3-15" class="sourceLine" data-line-number="15"></a>  <span class="kw">width</span>: <span class="dv">250px</span>;
<a id="cb3-16" class="sourceLine" data-line-number="16"></a>  <span class="kw">height</span>: <span class="dv">100px</span>;
<a id="cb3-17" class="sourceLine" data-line-number="17"></a>  <span class="kw">background-color</span>: <span class="dv">lime</span>;
<a id="cb3-18" class="sourceLine" data-line-number="18"></a>  <span class="kw">float</span>: <span class="dv">right</span>;
<a id="cb3-19" class="sourceLine" data-line-number="19"></a>}</code></pre>
</div>
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"parent"</span><span class="kw">&gt;</span>
<a id="cb4-2" class="sourceLine" data-line-number="2"></a>  Parent Box
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"right-box"</span><span class="kw">&gt;</span>Right Box<span class="kw">&lt;/div&gt;</span>
<a id="cb4-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"left-box"</span><span class="kw">&gt;</span>Left Box<span class="kw">&lt;/div&gt;</span>
<a id="cb4-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<div class="html-output">
<div style="width: 400px; background-color: red; margin: auto;">
Parent Box</p>
<div style="width: 250px; height: 100px; background-color: lime; float: right;">Right Box</div>
<div style="width: 250px; height: 100px; background-color: yellow; float: left;">Left Box</div>
<div style="clear: both;"></div>
</div>
</div>
<p>The sum of both floats is wider than the parent, so:</p>
<ol type="1">
<li>the floats can’t both fit on the same line (250px + 250px is greater than the 400px of the parent)</li>
<li>the floats wrap</li>
<li>they wrap in the order they were declared in the document (the <span class="css-value">right</span> element is placed first, then the <span class="css-value">left</span>).</li>
</ol>
<p>Of course, you can have elements float to the left and right on the same line. If we change the <span class="css-property">width</span> of the floats in the above example to <span class="css-value">100px</span>, we get:</p>
<div class="html-output">
<div style="width: 400px; background-color: red; margin: auto;">
Parent Box</p>
<div style="width: 100px; height: 100px; background-color: lime; float: right;">Right Box</div>
<div style="width: 100px; height: 100px; background-color: yellow; float: left;">Left Box</div>
<div style="clear: both;"></div>
</div>
</div>
<p>Remember that parts of the parent CSS Box is under both the left and right boxes, but the content in the parent box is never under a floating element.</p>
<h2 id="percentage-as-a-dimension">Percentage as a Dimension</h2>
<p>Up till now, we have always used pixels as a dimensioning unit. CSS has many ways of dimensioning things. It can be easier to work with float widths as a percentage of the parent container width. When using <strong>%</strong> as a dimension, it refers to the width of the container as a percentage of the parent width.<br />
Consider the following:</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">.box</span> {
<a id="cb5-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">height</span>: <span class="dv">50px</span>;
<a id="cb5-4" class="sourceLine" data-line-number="4"></a>}
<a id="cb5-5" class="sourceLine" data-line-number="5"></a>
<a id="cb5-6" class="sourceLine" data-line-number="6"></a><span class="fu">.w30</span> {
<a id="cb5-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">width</span>: <span class="dv">30%</span>;
<a id="cb5-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb5-9" class="sourceLine" data-line-number="9"></a>}
<a id="cb5-10" class="sourceLine" data-line-number="10"></a>
<a id="cb5-11" class="sourceLine" data-line-number="11"></a><span class="fu">.w50</span> {
<a id="cb5-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">width</span>: <span class="dv">50%</span>;
<a id="cb5-13" class="sourceLine" data-line-number="13"></a>  <span class="kw">background-color</span>: <span class="dv">lime</span>;
<a id="cb5-14" class="sourceLine" data-line-number="14"></a>}</code></pre>
</div>
<div id="cb6" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb6-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box w30"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb6-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"box w50"</span><span class="kw">&gt;&lt;/div&gt;</span></code></pre>
</div>
<div class="html-output">
<style> .xbox {  margin: auto;  height: 50px;} .w30 {  width: 30%;  background-color: yellow;} .w50 {  width: 50%;  background-color: lime;}</style>
<div class="xbox w30"></div>
<div class="xbox w50"></div>
</div>
<p>The yellow box is 30% of the width of its parent.<br />
The green box is 50% of the width of its parent.<br />
If the width of the parent changes, the widths of the child elements will adjust automatically. This can be useful if you want your web content to adapt its size to the browser window width.<br />
It is also useful if you want to quickly divide up the available real estate. Consider the following:</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb7-1" class="sourceLine" data-line-number="1"></a><span class="fu">.parent</span> {
<a id="cb7-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">width</span>: <span class="dv">400px</span>;
<a id="cb7-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">height</span>: <span class="dv">200px</span>;
<a id="cb7-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb7-5" class="sourceLine" data-line-number="5"></a>}
<a id="cb7-6" class="sourceLine" data-line-number="6"></a>
<a id="cb7-7" class="sourceLine" data-line-number="7"></a><span class="fu">.main</span> {
<a id="cb7-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">width</span>: <span class="dv">70%</span>;
<a id="cb7-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">height</span>: <span class="dv">100%</span>;
<a id="cb7-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">background-color</span>: <span class="dv">lime</span>;
<a id="cb7-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb7-12" class="sourceLine" data-line-number="12"></a>}
<a id="cb7-13" class="sourceLine" data-line-number="13"></a>
<a id="cb7-14" class="sourceLine" data-line-number="14"></a><span class="fu">.sidebar</span> {
<a id="cb7-15" class="sourceLine" data-line-number="15"></a>  <span class="kw">width</span>: <span class="dv">30%</span>;
<a id="cb7-16" class="sourceLine" data-line-number="16"></a>  <span class="kw">height</span>: <span class="dv">100%</span>;
<a id="cb7-17" class="sourceLine" data-line-number="17"></a>  <span class="kw">background-color</span>: <span class="dv">cyan</span>;
<a id="cb7-18" class="sourceLine" data-line-number="18"></a>  <span class="kw">float</span>:<span class="dv">left</span>;
<a id="cb7-19" class="sourceLine" data-line-number="19"></a>}</code></pre>
</div>
<div id="cb8" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb8-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"parent"</span><span class="kw">&gt;</span>
<a id="cb8-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"main"</span><span class="kw">&gt;</span>
<a id="cb8-3" class="sourceLine" data-line-number="3"></a>    Main content goes here.
<a id="cb8-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb8-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"sidebar"</span><span class="kw">&gt;</span>
<a id="cb8-6" class="sourceLine" data-line-number="6"></a>    Sidebar content goes here.
<a id="cb8-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb8-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<div class="html-output">
<div style="width: 400px; height: 200px; margin: auto;">
<div style="width: 70%; height: 100%; background-color: lime; float: left;">
Main content goes here.
</div>
<div style="width: 30%; height: 100%; background-color: cyan; float: left;">
Sidebar content goes here.
</div>
<div style="clear: both;"></div>
</div>
</div>
<p>Each floating box gets the specified percentage of the parent’s area. The parent size can be easily changed without having to update the individual sizes of the floating elements.</p>
<h2 id="expanding-a-floating-child-to-fit-its-parent">Expanding a Floating Child to Fit Its Parent</h2>
<p>A floating child element will <strong>only</strong> fill out the parent’s height only if the parent has a definite height specified (e.g. 200px). If no height is specified for the parent or a percentage height is specified for the parent, the floating child will not expand to fill the height of the parent &#8211; even if <span class="css-class">.clearfix</span> is used to expand the parent around the floating children.<br />
Using the same code as above, but</p>
<ol type="1">
<li>setting the parent <span class="css-property">height</span> to <span class="css-value">100%</span>,</li>
<li>setting its <span class="css-property">background-color</span> to yellow, and</li>
<li>clearing the floats after the last float (so the parent expands around the floating children):</li>
</ol>
<div class="html-output">
<div style="width: 400px; height: 100%; margin: auto; background: yellow;">
<div style="width: 70%; height: 100%; background-color: lime; float: left; vertical-align: bottom; display: table-cell;">
Main content goes here.
</div>
<div style="width: 30%; height: 100%; background-color: cyan; float: left;">
Sidebar content goes here.
</div>
<div style="clear: both;"></div>
</div>
</div>
<p>We see that the parent (yellow) has closed around its children. It has expanded to the height of the sidebar box, but the main content box (despite having its <span class="css-property">height</span> set to <span class="css-value">100%</span>) has not expanded to the bottom of the parent.<br />
If the parent does not have a fixed height, it is not possible to make a floating child expand to the height of its parent without either:</p>
<ul>
<li>using JavaScript,<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a> or</li>
<li>using a different positioning technique.<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></li>
</ul>
<p>The only time this (usually) becomes an issue is when children and parents have different background colours, borders, or other properties that makes it obvious the floating child and parent are not the same height.<br />
Floating children will always respect the <span class="css-property">width</span> of the parent &#8211; as long as you do not make the child wider than the parent.</p>
<h2 id="marginauto-has-no-effect-on-floats"><span class="css-property">margin:auto</span> Has No Effect on Floats</h2>
<p>Setting <span class="css-property">margin</span> to <span class="css-value">auto</span><a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a> on a floating element will have no effect. This is because floating elements automatically float as far as they can to the left or right.<br />
However, you can set a fixed margin on a floating element and it will respect it:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb9-1" class="sourceLine" data-line-number="1"></a><span class="fu">.floating-box</span> {
<a id="cb9-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">width</span>:<span class="dv">150px</span>;
<a id="cb9-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">height</span>:<span class="dv">50px</span>;
<a id="cb9-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb9-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">background-color</span>: <span class="dv">cyan</span>;
<a id="cb9-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">margin-left</span>: <span class="dv">50px</span>;
<a id="cb9-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">margin-top</span>: <span class="dv">50px</span>;
<a id="cb9-8" class="sourceLine" data-line-number="8"></a>}
<a id="cb9-9" class="sourceLine" data-line-number="9"></a>
<a id="cb9-10" class="sourceLine" data-line-number="10"></a><span class="fu">.parent-box</span> {
<a id="cb9-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">width</span>: <span class="dv">250px</span>;
<a id="cb9-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">height</span>: <span class="dv">150px</span>;
<a id="cb9-13" class="sourceLine" data-line-number="13"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb9-14" class="sourceLine" data-line-number="14"></a>  <span class="kw">margin</span>:<span class="dv">auto</span>;
<a id="cb9-15" class="sourceLine" data-line-number="15"></a>}</code></pre>
</div>
<div id="cb10" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb10-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"parent-box"</span><span class="kw">&gt;</span>
<a id="cb10-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floating-box"</span><span class="kw">&gt;</span>
<a id="cb10-3" class="sourceLine" data-line-number="3"></a>    This box is floating with margins.
<a id="cb10-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb10-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<div class="html-output">
<div style="width: 250px; height: 150px; background-color: yellow; margin: auto;">
<div style="width: 150px; height: 50px; float: left; background-color: cyan; margin-left: 50px; margin-top: 50px;">This box is floating with margins.</div>
</div>
</div>
<h2 id="summary">Summary</h2>
<ol type="1">
<li>Floating elements do not stack top to bottom.</li>
<li><span class="css-value">left</span> floated elements stack from left-to-right.</li>
<li><span class="css-value">right</span> floated elements stack from right-to-left.</li>
<li>Floating elements stack in the order they appear in the document.</li>
<li>If there is not enough room on a line to fit a floating element, the element moves down (wraps) to the next line and moves as far to the side as it can.</li>
<li>Instead of pixels, dimensions can be given as a percentage. The percentage is relative to the dimensions of the parent.</li>
<li>A floating child can be made to fit the full height of its parent by setting its <span class="css-property">height</span> to <span class="css-value">100%</span>. This only works if the parent has a defined height in pixels.</li>
<li><span class="css-property">margin:auto</span>, which is commonly used to centre HTML elements, is ignored when applied to floating elements.</li>
<li>Floating elements respect non-auto margin values.</li>
</ol>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.<br />
You have previously seen that you can use the <span class="html-tag">div</span> tag to section content in a document. Prior to seeing the <span class="css-property">float</span> property, the only possible flow of content was vertical &#8211; from top to bottom. With <span class="css-property">float</span> it is possible to get content to flow side-to-side.<br />
How would you section and style the following page layout using <span class="html-tag">div</span> and <span class="css-property">float</span>?</p>
<div>
<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>
</div>
<ol type="1">
<li>Make it look good in your browser on your computer. Don’t try to make it look good at all possible screen resolutions.</li>
<li>Think about how to section the document. Remember that <span class="html-tag">div</span>s can nest inside other <span class="html-tag">div</span>s.</li>
<li>The layout above is a rough template to give you direction on how to layout your document.</li>
<li>A general rule of thumb in web design is to make your layout 960px wide (which is then centred in the browser)<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a>.</li>
</ol>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://www.w3.org/TR/CSS2/visuren.html#propdef-float">float</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visuren.html#flow-control">clear</a></li>
<li><a href="https://960.gs/demo.html">960 Grid</a></li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-1">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-a-simple-page-using-float">Next</a>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">Feel free to use larger boxes, but in the article, I am somewhat constrained for space.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">Which will be covered in a future tutorial.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">CSS is incredibly flexible and there are lots of choices for positioning elements, but those are for future tutorials.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">Remember that <span class="css-value">auto</span> is how we get elements to centre inside a container. Effectively, we are asking the User Agent (browser) to apply equal margins to the left and right side.<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">This tends to work fine for desktop browsers, but not so well for mobile browsers. Nevertheless, it is a good rule of thumb for dividing up and laying out content on your page.<a class="footnote-back" href="#fnref5">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2/">CSS &#8211; Understanding How Float Works &#8211; 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; Understanding How Float Works &#8211; Part 1</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-1/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 11 May 2018 13:42:34 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></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=3689</guid>

					<description><![CDATA[<p>The behaviour of floats can be mysterious (or frustrating). This tutorial helps take away some of the mystery (and pain) of dealing with floats.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-1/">CSS &#8211; Understanding How Float Works &#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">
We’ve seen that the <span class="css-property">float</span> can be used to place an HTML element to the side of other content.<br />
How does it do this and why does it seem to overlap other HTML elements?
</div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#a-quick-review-of-normal-flow">A Quick Review of Normal Flow</a></li>
<li><a href="#float-takes-the-element-out-of-normal-flow"><span class="css-property">float</span> Takes the Element Out of Normal Flow</a></li>
<li><a href="#float-changes-the-elements-display-property"><span class="css-property">float</span> Changes the Element’s <span class="css-property">display</span> Property</a></li>
<li><a href="#how-floated-elements-position-themselves">How Floated Elements Position Themselves</a></li>
<li><a href="#how-parents-interact-with-floats">How Parents Interact with Floats</a></li>
<li><a href="#content-avoids-being-under-a-float">Content Avoids Being Under a Float</a></li>
<li><a href="#clearing-the-effect-of-float">Clearing the Effect of Float</a></li>
<li><a href="#how-to-make-a-parent-contain-a-float">How to Make a Parent Contain a Float</a></li>
<li><a href="#clearfix---the-better-way-to-clear-a-float">Clearfix &#8211; The Better Way to Clear a Float</a>
<ol type="1">
<li><a href="#breaking-down-clearfix">Breaking Down Clearfix</a></li>
</ol>
</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="a-quick-review-of-normal-flow">A Quick Review of Normal Flow</h2>
<p>All HTML elements have a box model:<br />
<img decoding="async" src="https://i0.wp.com/complete-concrete-concise.com/wp-content/uploads/2018/04/15-css-box-model.png?resize=600%2C338&amp;ssl=1" /><br />
All HTML elements are always represented as a rectangle.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a><br />
Elements can nest one inside the other:</p>
<div style="background: yellow; text-align: center; overflow: auto; font-weight: bold; width: 80%; margin: auto;">
HTML elements</p>
<div style="background: lime; margin: 1em; overflow: auto;">
nested inside</p>
<div style="background: orange; margin: 1em; overflow: auto;">
other</p>
<div style="background: cyan; margin: 1em; overflow: auto;">
elements.
</div>
</div>
</div>
</div>
<p>We call the outer element a <strong>parent</strong> and the inner element a <strong>child</strong>.<br />
In HTML, block elements flow from top to bottom, stacking like blocks:</p>
<p style="margin: auto; width: 150px; background: yellow; text-align: center; vertical-align: middle; line-height: 70px; border: 1px solid black;">HTML Blocks</p>
<p style="margin: auto; width: 150px; line-height: 70px; background: lime; text-align: center; border: 1px solid black;">stack one</p>
<p style="margin: auto; width: 150px; line-height: 70px; background: orange; text-align: center; border: 1px solid black;">atop the</p>
<p style="margin: auto; width: 150px; line-height: 70px; background: cyan; text-align: center; border: 1px solid black;">other</p>
<p>They stack or nest in the order they appear in the HTML document.<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a><br />
The CSS Box expands to fit whatever is inside it &#8211; whether it is <strong>content</strong> or another CSS Box (which, technically, is content).</p>
<h2 id="float-takes-the-element-out-of-normal-flow"><span class="css-property">float</span> Takes the Element Out of Normal Flow</h2>
<p>When you apply the <span class="css-property">float</span> property to an element, it takes the element out of normal flow.<br />
We have always considered the HTML document to be like a flat sheet of paper. When we <span class="css-property">float</span> an element, it is like adding another sheet of paper on top of the first:<br />
&nbsp;<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-1-min.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3692" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-1-min.png" alt="" width="321" height="381" /></a><br />
And the floated element “floats” to that new layer:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-2.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3693" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-2.png" alt="" width="321" height="381" /></a><br />
&nbsp;<br />
Since it is no longer part of the original layer (normal flow), the block elements below move up as if the floated element never existed:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-3-min.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3694" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-float-3-min.png" alt="" width="321" height="381" /></a><br />
&nbsp;<br />
It is important to understand that the floated element is <strong>no longer <em>fully</em> contained</strong> inside the CSS Box it was declared. It literally <strong>floats</strong> on top of the other HTML elements.<br />
Consider the following styling<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a> 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">.box</span> {
<a id="cb1-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">width</span>:<span class="dv">300px</span>;
<a id="cb1-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">height</span>: <span class="dv">150px</span>;
<a id="cb1-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">background-color</span>: <span class="dv">blue</span>;
<a id="cb1-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb1-6" class="sourceLine" data-line-number="6"></a>}
<a id="cb1-7" class="sourceLine" data-line-number="7"></a>
<a id="cb1-8" class="sourceLine" data-line-number="8"></a><span class="fu">.floated-box</span> {
<a id="cb1-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">width</span>: <span class="dv">150px</span>;
<a id="cb1-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">height</span>: <span class="dv">300px</span>;
<a id="cb1-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">background-color</span>: <span class="fu">rgba</span>(<span class="dv">255</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0.5</span>);
<a id="cb1-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
<a id="cb1-13" class="sourceLine" data-line-number="13"></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">"box"</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">"floated-box"</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&gt;</span></code></pre>
</div>
<p>Which results in:</p>
<div id="example" style="background: white; border: 1px solid black; padding: 1em;">
<div style="width: 300px; height: 150px; background-color: blue; margin: auto;">
<div style="width: 150px; height: 200px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
<p>If we switch the <span class="css-property">float</span> from <span class="css-value">left</span> to <span class="css-value">right</span> we get:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="width: 300px; height: 150px; background-color: blue; margin: auto;">
<div style="width: 150px; height: 200px; background-color: rgba(255, 0, 0, 0.5); float: right;"></div>
</div>
<div style="clear: both;"></div>
</div>
<p>In both cases, it should be obvious that the red element is floating above the blue element.</p>
<h2 id="float-changes-the-elements-display-property"><span class="css-property">float</span> Changes the Element’s <span class="css-property">display</span> Property</h2>
<p>All floated elements have a <span class="css-property">display</span> of <span class="css-value">block</span>.<br />
This happens automatically.<br />
You can set it to <span class="css-value">none</span> to hide the floated element, but you cannot set it to <span class="css-value">inline</span> or <span class="css-value">inline-block</span>.<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></p>
<h2 id="how-floated-elements-position-themselves">How Floated Elements Position Themselves</h2>
<p>A floating element’s position is bounded by its parent’s top and side edge, according to the following rules:</p>
<ol type="1">
<li>It moves up as high as it can:
<ul>
<li>it stops when it reaches the top of its parent (illustrated in the <a href="#example">examples above</a>) or</li>
<li>it stops when it encounters an HTML element that is not floated:
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="width: 300px; height: 150px; background-color: blue; margin: auto;">
<div style="border: 1px solid black; background: lime;">Not floating.</div>
<div style="width: 150px; height: 200px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
</li>
</ul>
</li>
<li>It moves as far to the left (or right &#8211; depending on the value of the <span class="css-property">float</span> property) as it can:
<ul>
<li>it stops when it encounters the corresponding side of its parent (illustrated in the <a href="#example">examples above</a>) or</li>
<li>it stops when it encounters the side of another floated element
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="width: 300px; height: 150px; background-color: blue; margin: auto;">
<div style="border: 1px solid black; background: lime; float: left;">Floating</div>
<div style="width: 150px; height: 200px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
</li>
</ul>
</li>
<li>Since it is removed from <strong>normal flow</strong> the parent knows nothing about the child, so the parent cannot automatically size to contain the floating child. Remember, the child is floating above the parent</li>
<li>It is possible for a floating child’s CSS Box to be larger than its parent’s CSS Box:</li>
</ol>
<div id="example" style="background: white; border: 1px solid black; padding: 1em;">
<div style="width: 200px; height: 150px; background-color: blue; margin: auto;">
<div style="width: 250px; height: 200px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
<h2 id="how-parents-interact-with-floats">How Parents Interact with Floats</h2>
<p>Because floated elements are removed from <strong>normal flow</strong> they do not affect the parent.<br />
Normally, a parent expands to contain all the content within it (assuming you haven’t set the <span class="css-property">width</span> or <span class="css-property">height</span>), but since a floated element is not contained by the parent, the parent cannot expand to contain it.<br />
We see the parent and child in the examples above because I set the <span class="css-property">width</span> and <span class="css-property">height</span> or the parent element.<br />
Consider the following in which the parent only has the <span class="css-property">background-color</span> set:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb3-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"blue-bg"</span><span class="kw">&gt;</span>
<a id="cb3-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb3-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Which results in:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: rgba(0, 0, 255, 0.5); margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
<p>Since the parent has no content (remember the floating child is outside <strong>normal flow</strong>), it has full width and a height of&nbsp; zero pixels (since there is nothing for it to expand around). You can convince yourself of this by adding a border to the parent element &#8211; which will appear as a horizontal line since the height it is zero pixels.<br />
Adding some content to the previous example:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"blue-bg"</span><span class="kw">&gt;</span>
<a id="cb4-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb4-4" class="sourceLine" data-line-number="4"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>We get:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: rgba(0, 0, 255, 1.0); margin: auto; color: white;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.
</p></div>
<div style="clear: both;"></div>
</div>
<p>The parent container expanded to contain the content that was added, but it did not expand to contain the floating element.<br />
Had I added the content before the float, the float would have stopped at the first non-float element and we wouldn’t have the dramatic effect of the float overflowing its parent and the parent <strong>not</strong> adjusting its size to contain the float.<br />
This brings up another interesting property of floats: <strong>content avoids being under a float</strong>.</p>
<h2 id="content-avoids-being-under-a-float">Content Avoids Being Under a FLoat</h2>
<p>Consider the following code:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"yellow-bg"</span><span class="kw">&gt;</span>
<a id="cb5-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-4" class="sourceLine" data-line-number="4"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb5-5" class="sourceLine" data-line-number="5"></a>
<a id="cb5-6" class="sourceLine" data-line-number="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"lime-bg"</span><span class="kw">&gt;</span>
<a id="cb5-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;p&gt;</span>This is some text in a lime box.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb5-9" class="sourceLine" data-line-number="9"></a>
<a id="cb5-10" class="sourceLine" data-line-number="10"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"orange-bg"</span><span class="kw">&gt;</span>
<a id="cb5-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">&lt;p&gt;</span>This is some text in an orange box.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Which gives the following result:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.
</p></div>
<div style="background-color: lime; margin: auto; color: black;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
<div style="clear: both;"></div>
</div>
<p>This shows that a float may overlap many CSS Boxes, but the content in those boxes are not covered by the floating element. In other words, content will never appear under a floating element.<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a><br />
Floating elements <strong>never</strong> cover up content like this:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); position: absolute;"></div>
<p>This is some text.
</p></div>
<div style="background-color: lime; margin: auto; color: black;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
<div style="clear: both;"></div>
</div>
<p>This behaviour makes floats extra confusing because the behaviour of things under a float is not consistent:</p>
<ul>
<li>CSS Boxes can be overlapped by floating elements</li>
<li><strong>Content</strong> in CSS Boxes cannot be overlapped by floating elements</li>
</ul>
<h2 id="clearing-the-effect-of-float">Clearing the Effect of Float</h2>
<p>The <span class="css-property">clear</span> property is used to “restore” <strong>normal flow</strong> around a floated element. This is not technically correct, what really happens is the element is positioned under the bottom margin of the floating element. In other words, <span class="css-property">clear</span> means something like: <strong>position yourself clear of the overlapping effect of any float</strong>.<br />
There are 4 possible values:</p>
<ul>
<li><span class="css-value">none</span> : this is the default value and does not cause the element to get clear of any floats</li>
<li><span class="css-value">left</span> : this causes the HTML element to position itself so it is clear of any <span class="css-property">float:left</span> elements, i.e.&nbsp;no <span class="css-value">left</span> floating element overlaps its CSS Box</li>
<li><span class="css-value">right</span> : this causes the HTML element to position itself so it is clear of any <span class="css-property">float:right</span> elements, i.e.&nbsp;no <span class="css-value">right</span> floating element overlaps its CSS Box</li>
<li><span class="css-value">both</span> : this causes the HTML element to position itself so it is clear of all floating elements, i.e.&nbsp;no floating element overlaps its CSS Box. This is the most commonly used value</li>
</ul>
<p>The <span class="css-property">clear</span> property is applied to the element you want to position <strong>immediately below</strong> the bottom margin of the floating element. Remember that HTML elements flow from top to bottom.<br />
If <span class="css-property">clear</span> is applied to an element that is not covered by a float, then it has no effect on its positioning.<br />
Consider the previous example:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.
</p></div>
<div style="background-color: lime; margin: auto; color: black;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
<div style="clear: both;"></div>
</div>
<p>The red floating box overlaps the yellow, green, and orange HTML elements. Also notice that the <strong>content</strong> does not appear under the floating box.<br />
The red box is a child of the yellow element. It was declared inside the yellow element and is bound to the top and left of the yellow element. But the yellow parent does not enclose its red child because the child is outside of <strong>normal flow</strong>, so the parent isn’t aware of it.<br />
If we want the green element to appear after the floating red box (i.e., we want it to get <span class="css-value">clear</span> of any overlapping by a float), we apply the following style to it:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb6-1" class="sourceLine" data-line-number="1"></a><span class="fu">.clear</span> {
<a id="cb6-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">clear</span>: <span class="dv">both</span>;
<a id="cb6-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>And apply the class to our code:</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb7-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"yellow-bg"</span><span class="kw">&gt;</span>
<a id="cb7-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb7-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb7-4" class="sourceLine" data-line-number="4"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb7-5" class="sourceLine" data-line-number="5"></a>
<a id="cb7-6" class="sourceLine" data-line-number="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"lime-bg clear"</span><span class="kw">&gt;</span>
<a id="cb7-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;p&gt;</span>This is some text in a lime box.<span class="kw">&lt;/p&gt;</span>
<a id="cb7-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb7-9" class="sourceLine" data-line-number="9"></a>
<a id="cb7-10" class="sourceLine" data-line-number="10"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"orange-bg"</span><span class="kw">&gt;</span>
<a id="cb7-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">&lt;p&gt;</span>This is some text in an orange box.<span class="kw">&lt;/p&gt;</span>
<a id="cb7-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Which gives the following result:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.
</p></div>
<div style="background-color: lime; margin: auto; color: black; clear: both;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
</div>
<p><span class="css-property">clear:both</span> has caused the green element to be positioned just beneath the bottom margin of the floated element. In other words, it got clear of the float. In this example, <span class="css-property">clear:left</span> would have been good enough. Had we used <span class="css-property">clear:right</span>, the green box would not have moved clear of the red box.<br />
Had we also applied <span class="css-class">.clear</span> to the orange box, it would have no effect because the orange box is no longer under the influence of the float.</p>
<h2 id="how-to-make-a-parent-contain-a-float">How to Make a Parent Contain a Float</h2>
<p>We saw that applying <span class="css-property">clear</span> to an HTML element caused it to be positioned below the bottom margin of a floating element.<br />
We can use the same technique to push down the bottom of a parent so it “contains” its floating child. Technically speaking, it doesn’t contain the child &#8211; it only looks like it contains the child.<br />
It is useful to remember:</p>
<ol type="1">
<li>floated elements are not part of <strong>normal flow</strong>.</li>
<li>floated elements float on top of any <strong>normal flow</strong> CSS Boxes below them.</li>
<li>floated elements move as far up as they can in their parent HTML element (this could be a <span class="html-tag">div</span> or even the <span class="html-tag">body</span>). They stop if they encounter a non-floating element.</li>
<li>floated elements move as far to the side (<span class="css-value">left</span> or <span class="css-value">right</span>) as they can. They stop when they either encounter the side <span class="css-property">margin</span> of the parent or of another <span class="css-property">float</span>.</li>
<li><strong>Content</strong> never appears under a floating element. It will always shift to a position where it is not covered by a floating element.</li>
<li>HTML elements expand (assuming no <span class="css-property">width</span> or <span class="css-property">height</span> has been set) to fit their content.</li>
<li>we can set the <span class="css-property">clear</span> property on an HTML element to tell it to position itself so it is clear of (not covered by) a floating element</li>
</ol>
<p>Based on the behaviours outlined above, all that is needed to get a parent to “contain” a floating child is to:</p>
<ul>
<li>place an HTML element inside the parent,</li>
<li>place it after the floating element,</li>
<li>set the <span class="css-property">clear</span> property on it.</li>
</ul>
<p>This will cause the element to position itself after the floating element. Since this element is contained by the parent, the parent will expand to contain it:</p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb8-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"yellow-bg"</span><span class="kw">&gt;</span>
<a id="cb8-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb8-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"clear"</span><span class="kw">&gt;</span>Clearing element under
<a id="cb8-5" class="sourceLine" data-line-number="5"></a>    the float that expands the parent
<a id="cb8-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb8-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb8-8" class="sourceLine" data-line-number="8"></a>
<a id="cb8-9" class="sourceLine" data-line-number="9"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"lime-bg"</span><span class="kw">&gt;</span>
<a id="cb8-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">&lt;p&gt;</span>This is some text in a lime box.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-11" class="sourceLine" data-line-number="11"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb8-12" class="sourceLine" data-line-number="12"></a>
<a id="cb8-13" class="sourceLine" data-line-number="13"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"orange-bg"</span><span class="kw">&gt;</span>
<a id="cb8-14" class="sourceLine" data-line-number="14"></a>  <span class="kw">&lt;p&gt;</span>This is some text in an orange box.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-15" class="sourceLine" data-line-number="15"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Which gives the following result:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.</p>
<p style="clear: both;">Clearing element under the float that expands the parent</p>
</div>
<div style="background-color: lime; margin: auto; color: black; clear: both;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
</div>
<p>It works, except that we may not want to have text at the bottom of our parent. The trick is to insert a zero pixel high element &#8211; an empty <span class="html-tag">div</span> element works perfectly for this:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb9-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"yellow-bg"</span><span class="kw">&gt;</span>
<a id="cb9-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb9-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"clear"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb9-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb9-6" class="sourceLine" data-line-number="6"></a>
<a id="cb9-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"lime-bg"</span><span class="kw">&gt;</span>
<a id="cb9-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">&lt;p&gt;</span>This is some text in a lime box.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-9" class="sourceLine" data-line-number="9"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb9-10" class="sourceLine" data-line-number="10"></a>
<a id="cb9-11" class="sourceLine" data-line-number="11"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"orange-bg"</span><span class="kw">&gt;</span>
<a id="cb9-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">&lt;p&gt;</span>This is some text in an orange box.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-13" class="sourceLine" data-line-number="13"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>Resulting in:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.</p>
<div style="clear: both;"></div>
</div>
<div style="background-color: lime; margin: auto; color: black; clear: both;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
</div>
<p>Which is exactly what we would like &#8211; almost.<br />
The problem is that we have to insert some styled HTML code that does nothing but clear the effect of the float. Effectively, it is “noise” in our code.<br />
Fortunately, there is a better way.</p>
<h2 id="clearfix---the-better-way-to-clear-a-float">Clearfix &#8211; The Better Way to Clear a Float</h2>
<p>The problem with the previous solution is that it adds extra code to get a parent to “wrap around” a floating child. It would be better if we didn’t have to add extra code.<br />
There is a way to do this and it is known as <span class="css-class">.clearfix</span>.<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a><br />
The code looks like this (the class name is arbitrary, you are free to call it whatever you like):</p>
<div id="cb10" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb10-1" class="sourceLine" data-line-number="1"></a><span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb10-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">clear</span>: <span class="dv">both</span>;
<a id="cb10-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">display</span>: <span class="dv">block</span>;
<a id="cb10-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">content</span>: <span class="st">""</span>;
<a id="cb10-5" class="sourceLine" data-line-number="5"></a>}</code></pre>
</div>
<p>It is applied to the <strong>parent</strong> containing the floating element:</p>
<div id="cb11" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb11-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"yellow-bg clearfix"</span><span class="kw">&gt;</span>
<a id="cb11-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"floated-box"</span><span class="kw">&gt;&lt;/div&gt;</span>
<a id="cb11-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;p&gt;</span>This is some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb11-4" class="sourceLine" data-line-number="4"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb11-5" class="sourceLine" data-line-number="5"></a>
<a id="cb11-6" class="sourceLine" data-line-number="6"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"lime-bg"</span><span class="kw">&gt;</span>
<a id="cb11-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;p&gt;</span>This is some text in a lime box.<span class="kw">&lt;/p&gt;</span>
<a id="cb11-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/div&gt;</span>
<a id="cb11-9" class="sourceLine" data-line-number="9"></a>
<a id="cb11-10" class="sourceLine" data-line-number="10"></a><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"orange-bg"</span><span class="kw">&gt;</span>
<a id="cb11-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">&lt;p&gt;</span>This is some text in an orange box.<span class="kw">&lt;/p&gt;</span>
<a id="cb11-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>And gives us the result we want:</p>
<div style="background: white; border: 1px solid black; padding: 1em;">
<div style="background-color: yellow; margin: auto;">
<div style="width: 150px; height: 95px; background-color: rgba(255, 0, 0, 0.5); float: left;"></div>
<p>This is some text.</p>
<div style="clear: both;"></div>
</div>
<div style="background-color: lime; margin: auto; color: black; clear: both;">
This is some text in a lime box.
</div>
<div style="background-color: orange; margin: auto; color: black;">
This is some text in a orange box.
</div>
</div>
<h3 id="breaking-down-clearfix">Breaking Down Clearfix</h3>
<p>Unfortunately, <span class="css-class">.clearfix</span> contains CSS elements I am not going to cover in this <a href="https://complete-concrete-concise.com/category/tutorials/webdev/front-end-basics">Front-End Basics</a> tutorial series, but, understanding what is going on with <span class="css-class">.clearfix</span> is important, so I need to give you a little background on what is happening:</p>
<div id="cb12" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb12-1" class="sourceLine" data-line-number="1"></a><span class="fu">.clearfix</span><span class="in">::after</span> {
<a id="cb12-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">clear</span>: <span class="dv">both</span>;
<a id="cb12-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">display</span>: <span class="dv">block</span>;
<a id="cb12-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">content</span>: <span class="st">""</span>;
<a id="cb12-5" class="sourceLine" data-line-number="5"></a>}</code></pre>
</div>
<ul>
<li><span class="css-pseudo-element">::after</span> &#8211; this creates a pseudo-element that is inserted as the last child. In other words, it creates a “fake” HTML element that becomes the last child of the parent. In effect, it automatically inserts the needed last HTML element for us.<a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a></li>
<li><span class="css-property">clear:both</span> &#8211; this instructs the pseudo-element (which is also the last element) to get clear of any floats. This means the pseudo-element will appear below any floats, thus extending the parent CSS Box around it (because it is contained by the parent).</li>
<li><span class="css-property">display:block</span> &#8211; the pseudo-element display type is set to <span class="css-value">block</span> style because <strong>normal flow</strong> (pretty much) relies on HTML elements being blocks.</li>
<li><span class="css-property">content</span> &#8211; the <span class="css-property">content</span> property allows inserting <strong>content</strong> into the <span class="css-pseudo-element">::after</span> pseudo-element. In fact, there is no other way to insert <strong>content</strong>.<a id="fnref8" class="footnote-ref" href="#fn8"><sup>8</sup></a> In this case, we insert an empty string &#8211; it occupies no space, so the element has a height of zero pixels. If you omit the <span class="css-property">content</span> property. then the <span class="css-class">.clearfix</span> won’t work. Instead of an empty string, you could also use a single space <span class="css-value">&#8221; “</span>.<a id="fnref9" class="footnote-ref" href="#fn9"><sup>9</sup></a></li>
</ul>
<h2 id="summary">Summary</h2>
<ol type="1">
<li>Floated elements are not part of <strong>normal flow</strong>.</li>
<li><span class="css-value">block</span> elements move up to fill the space left by the floated element.</li>
<li>Floated elements automatically have their <span class="css-property">display</span> value set to <span class="css-value">block</span></li>
<li>Floated elements “float up” to a display layer above the document layer.</li>
<li>Floated elements cover any <strong>normal flow</strong> CSS Box elements below them.</li>
<li>Floated elements first move up as far as they can in their parent HTML element. They stop when they reach the top margin of their parent or the bottom margin of a non-floating element.</li>
<li>Floated elements then move as far to the side (<span class="css-value">left</span> or <span class="css-value">right</span>) as they can in their parent HTML element. They stop when they reach the side margin of the parent or of another floating element.</li>
<li>Floated elements are not contained inside their parents, so the parent element does not expand to contain the floating element. (But they are bounded by the top and one side of the parent.)</li>
<li>The CSS Box of a floating child element can be larger than the CSS Box of its parent.
<ul>
<li>the bottom of a floating element can extend below the bottom of its parent.</li>
<li><span class="css-value">left</span> floated elements can have their right margin extend past the right margin of their parent.</li>
<li><span class="css-value">right</span> floated elements can have their left margin extend past the left margin of their parent.</li>
</ul>
</li>
<li><strong>Content</strong> never appears under a floating element. It will always shift to a position where it is not covered by a floating element.</li>
<li>The <span class="css-property">clear</span> property does not stop or end the effect of a floating element.</li>
<li>Setting <span class="css-property">clear:left</span> on an HTML element instructs the element to position itself immediately below any <span class="css-property">float:left</span> elements it may be affected by. If the element is not under the influence of any <span class="css-property">float:left</span> element, this setting has no effect.</li>
<li>Setting <span class="css-property">clear:right</span> on an HTML element instructs the element to position itself immediately below any <span class="css-property">float:right</span> elements it may be affected by. If the element is not under the influence of any <span class="css-property">float:right</span> element, this setting has no effect.</li>
<li>Setting <span class="css-property">clear:both</span> on an HTML element instructs the element to position itself immediately below any floating elements it may be affected by. If the element is not under the influence of any floating elements, this setting has no effect.</li>
<li>Inserting a “dummy” HTML block as the last element in a parent with the <span class="css-property">clear</span> property set will cause the parent to expand and “contain” any floating children.</li>
<li><span class="css-class">.clearfix</span> is the preferred method for getting a parent to “contain” floating child elements.</li>
</ol>
<p>We covered quite a lot of material and information on <span class="css-property">float</span>, but don’t worry, there is still plenty more in the next tutorial.</p>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.<br />
Floats can be confusing because they are removed from <strong>normal flow</strong> and can overlap other CSS Boxes, but the <strong>content</strong> in those boxes will not be overlapped &#8211; it will be positioned so it is not under a floating element.<br />
For these exercises, I suggest making things simple by:</p>
<ul>
<li>using fixed sized boxes with different coloured backgrounds.</li>
<li>make the background of floating elements semi-transparent using the RGBA() function so you can see when it floats over other HTML elements.</li>
</ul>
<ol type="1">
<li>Observing the effect of floats being removed from <strong>normal flow</strong>:
<ul>
<li>Create two stacked (not nested) boxes and observe what happens when you:
<ul>
<li>float the bottom box to the right?</li>
<li>float the bottom box to the left?</li>
<li>float the top box to the right?</li>
<li>float the top box to the left?</li>
</ul>
</li>
<li>Create four stacked (not nested) boxes and what happens when you:
<ul>
<li>float the second from the top to the right?</li>
<li>float the second from the top to the left?</li>
</ul>
</li>
</ul>
</li>
<li>Observing the effect of <span class="css-property">clear</span> on floats:
<ul>
<li>Create three stacked (not nested) boxes. Make the second box twice as tall as the first box. Make the third box very wide. Float the first box <span class="css-value">left</span> and the second box <span class="css-value">right</span> and observe what happens when:
<ul>
<li><span class="css-property">clear:left</span> is applied to the third box?</li>
<li><span class="css-property">clear:right</span> is applied to the third box?</li>
<li><span class="css-property">clear:both</span> is applied to the third box?</li>
</ul>
</li>
</ul>
</li>
<li>Observing that parents do not contain their floating children:
<ul>
<li>Create a parent container with <strong><u>no</u></strong> specified <span class="css-property">width</span> and <span class="css-property">height</span>, but let it have a <span class="css-property">background-color</span>
<ul>
<li>create a floating child box inside that is smaller than the parent. Do you observe the parent <span class="css-property">background-color</span>?</li>
<li>add a border to the parent. Do you observe the border, but not the <span class="css-property">background-color</span>?</li>
<li>what do you observe when you add non-floating elements to the parent? Try adding them before and after the floating child.</li>
</ul>
</li>
</ul>
</li>
<li>Observing the effect of floats on <strong>content</strong>:
<ul>
<li>Create a parent box with a specified <span class="css-property">width</span> and <span class="css-property">height</span>. Inside, create a floating box. The floating box should have a <span class="css-property">width</span> and <span class="css-property">height</span> greater than its parent. Beneath the floating box, add some text content (it is a good idea to put a border around the <strong>content</strong>) and observe what happens when:
<ul>
<li><span class="css-property">float</span> is set to <span class="css-value">none</span>?</li>
<li><span class="css-property">float</span> is set to <span class="css-value">left</span> or <span class="css-value">right</span>?</li>
</ul>
</li>
</ul>
</li>
<li>Observing the positioning of multiple floats:
<ul>
<li>Create a stack of three floating boxes. What happens when:
<ul>
<li>they all have <span class="css-property">float</span> set to <span class="css-value">left</span>?</li>
<li>they all have <span class="css-property">float</span> set to <span class="css-value">right</span>?</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://www.w3.org/TR/CSS2/visuren.html#propdef-float">float</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visuren.html#flow-control">clear</a></li>
<li><a href="https://www.w3.org/TR/CSS2/generate.html#before-after-content">::after</a></li>
<li><a href="https://www.w3.org/TR/CSS2/generate.html#propdef-content">content</a></li>
<li><a href="https://drafts.csswg.org/css-color-3/#rgba-color">RGBA()</a></li>
<li><a href="https://drafts.csswg.org/css-color/#hex-notation">#RRGGBBAA</a></li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-introducing-float">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-2">Next</a>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">If the width and height are the same, then it will be a square &#8211; a special case of a rectangle &#8211; but it will never be a circle or triangle or any other shape.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">In future tutorials you will see that it is possible to rearrange the content using either JavaScript or certain features of CSS3.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">I’m using RGBA, which allows you to specify the color and its <strong>opacity</strong>. Opacity is a fancy way of saying how <em>see-through</em> a colour is. For RGBA, it is a value between 0.0 (fully transparent) and 1.0 (fully opaque &#8211; solid).There is a <strong>hexadecimal</strong> version: #RRGGBBAA. The AA value goes between 00 (full transparency) to FF (full opacity). It is a recent addition to the CSS specification and may not be supported by all browsers (especially older ones), so RGBA is a safer bet. You can also use the shorthand form #RGBA if the two digits of each colour are the same &#8211; #3F7A is the same as #33FF77AAThe A stands for <strong>alpha channel</strong>, which is the standard name for opacity or transparency.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">There are more display modes than <span class="css-value">inline</span>, <span class="css-value">inline-block</span>, <span class="css-value">block</span> or <span class="css-value">none</span> &#8211; we haven’t seen yet. You can change the <span class="css-property">display</span> value to some of those, but the upshot is: <em>whatever you change it to, it must behave in a block like manner</em>.<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">If you force a float to completely overlap a CSS Box, the content will be pushed outside the boundaries of the float.<a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">Probably, the <a href="http://lists.w3.org/Archives/Public/www-style/2002Aug/0134.html">earliest reference</a> to this fix is from Aug 15, 2002. Unfortunately, the fix, as described doesn’t work because it is applied to the floating element.<a class="footnote-back" href="#fnref6">↩</a></li>
<li id="fn7">Before CSS3, it was written <span class="css-pseudo-element">:after</span> (a single colon), but in CSS3, the correct way to write it is <span class="css-pseudo-element">::after</span> (with two colons).<a class="footnote-back" href="#fnref7">↩</a></li>
<li id="fn8">You can use JavaScript to insert content.<a class="footnote-back" href="#fnref8">↩</a></li>
<li id="fn9">Some older browsers had a bug that would not correctly display the empty string, but would if it was a single space. Another alternative is to set the <span class="css-property">font-size</span> and <span class="css-property">height</span> to <span class="css-value">0</span>.<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-understanding-how-float-works-part-1/">CSS &#8211; Understanding How Float Works &#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; Introducing float</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-introducing-float/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 11 May 2018 12:46:18 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[float]]></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=3668</guid>

					<description><![CDATA[<p>HTML elements can do more than stack one atop the other or nest one inside the other, they can also float above other elements.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-introducing-float/">CSS &#8211; Introducing float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
Up to now, the only sort of content flow you have seen is top to bottom.<br />
Every <strong>block</strong> element you have used either nests inside another <strong>block</strong> element or stacks top to bottom in the order it appears in the document. There was no way to place blocks side by side.
</div>
<p>The <span class="css-property">float</span> property was originally introduced to allow text to flow around image elements &#8211; thus eliminating a lot of white space and making for more esthetically pleasing documents.</p>
<h2>Contents</h2>
<ol type="1">
<li><a href="#float"><span class="css-property">float</span></a></li>
<li><a href="#practical-considerations">Practical Considerations</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="float"><span class="css-property">float</span></h2>
<p>The <span class="css-property">float</span> property can take the values of <span class="css-value">left</span>, <span class="css-value">right</span> or <span class="css-value">none</span>. By default, all HTML elements have <span class="css-property">float</span> set to <span class="css-value">none</span>.<br />
Consider the following code snippet which places an image on the left side of some text:</p>
<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="kw">&lt;p&gt;&lt;img</span><span class="ot"> src=</span><span class="st">"26-dog.jpg"</span><span class="kw">&gt;</span>Without floating the image,
  <a id="cb1-2" class="sourceLine" data-line-number="2"></a>  there is a lot of vertical white space along the
  <a id="cb1-3" class="sourceLine" data-line-number="3"></a>  side of the image. It is not esthetically pleasing.
  <a id="cb1-4" class="sourceLine" data-line-number="4"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<div style="background: white; border: 1px solid black;">
<img decoding="async" style="margin: none; display: inline;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg" />Without floating the image, you have a lot of vertical white space along the side of the image. It is not esthetically pleasing.
</div>
<p>Consider the same image to which <span class="css-property">float:left</span> has been applied:</p>
<div style="background: white; border: 1px solid black;">
<img decoding="async" style="float: left; margin: none;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg" />When you apply <span class="css-property">float</span> to the image, the text flows around the image. You no longer get a lot of ungainly white space.<br />
Of course, some additional <span class="css-property">padding</span> or <span class="css-property">margin</span> should be applied to the image or text so the text doesn’t hug the image so closely.<br />
Overall, it looks nicer.</p>
<div style="clear: both;"></div>
</div>
<p>A similar effect is obtained when <span class="css-property">float:right</span> is applied to the image:</p>
<div style="background: white; border: 1px solid black;">
<img decoding="async" style="float: right; margin: none;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg" /><br />
When you apply <span class="css-property">float</span> to the image, the text flows around the image. You no longer get a lot of ungainly white space.<br />
Of course, some additional <span class="css-property">padding</span> or <span class="css-property">margin</span> should be applied to the image or text so the text doesn’t hug the image so closely.<br />
Overall, it looks nicer.</p>
<div style="clear: both;"></div>
</div>
<h2 id="practical-considerations">Practical Considerations</h2>
<p>While it seems to work well, it has problems that become evident for anything but the simplest of layouts.<br />
Consider the following styling:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb2-1" class="sourceLine" data-line-number="1"></a><span class="fu">.border</span> {
  <a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">border</span>: <span class="dv">solid</span> <span class="dv">2px</span> <span class="dv">black</span>;
  <a id="cb2-3" class="sourceLine" data-line-number="3"></a>}
  <a id="cb2-4" class="sourceLine" data-line-number="4"></a>
  <a id="cb2-5" class="sourceLine" data-line-number="5"></a><span class="fu">.yellow-bg</span> {
  <a id="cb2-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">background-color</span>: <span class="dv">yellow</span>;
  <a id="cb2-7" class="sourceLine" data-line-number="7"></a>
  <a id="cb2-8" class="sourceLine" data-line-number="8"></a>}
  <a id="cb2-9" class="sourceLine" data-line-number="9"></a>
  <a id="cb2-10" class="sourceLine" data-line-number="10"></a><span class="fu">.lime-bg</span> {
  <a id="cb2-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">background-color</span>: <span class="dv">lime</span>;
  <a id="cb2-12" class="sourceLine" data-line-number="12"></a>
  <a id="cb2-13" class="sourceLine" data-line-number="13"></a>}
  <a id="cb2-14" class="sourceLine" data-line-number="14"></a>
  <a id="cb2-15" class="sourceLine" data-line-number="15"></a><span class="fu">.orange-bg</span> {
  <a id="cb2-16" class="sourceLine" data-line-number="16"></a>  <span class="kw">background-color</span>: <span class="dv">orange</span>;
  <a id="cb2-17" class="sourceLine" data-line-number="17"></a>
  <a id="cb2-18" class="sourceLine" data-line-number="18"></a>}
  <a id="cb2-19" class="sourceLine" data-line-number="19"></a>
  <a id="cb2-20" class="sourceLine" data-line-number="20"></a><span class="fu">.cyan-bg</span> {
  <a id="cb2-21" class="sourceLine" data-line-number="21"></a>  <span class="kw">background-color</span>: <span class="dv">cyan</span>;
  <a id="cb2-22" class="sourceLine" data-line-number="22"></a>
  <a id="cb2-23" class="sourceLine" data-line-number="23"></a>}
  <a id="cb2-24" class="sourceLine" data-line-number="24"></a>
  <a id="cb2-25" class="sourceLine" data-line-number="25"></a><span class="fu">.float-left</span> {
  <a id="cb2-26" class="sourceLine" data-line-number="26"></a>  <span class="kw">float</span>: <span class="dv">left</span>;
  <a id="cb2-27" class="sourceLine" data-line-number="27"></a>}</code></pre>
</div>
<p>Applied to the following HTML code:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb3-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"paragraph1"</span><span class="ot"> class=</span><span class="st">"border yellow-bg"</span><span class="kw">&gt;</span>
  <a id="cb3-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"26-dog.jpg"</span><span class="ot"> class=</span><span class="st">"float-left"</span><span class="kw">&gt;</span>
  <a id="cb3-3" class="sourceLine" data-line-number="3"></a>  To make the problem stand out, each paragraph is
  <a id="cb3-4" class="sourceLine" data-line-number="4"></a>  uniquely identified and has a border and background
  <a id="cb3-5" class="sourceLine" data-line-number="5"></a>  colour styling applied.<span class="kw">&lt;/p&gt;</span>
  <a id="cb3-6" class="sourceLine" data-line-number="6"></a>
  <a id="cb3-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"paragraph2"</span><span class="ot"> class=</span><span class="st">"border lime-bg"</span><span class="kw">&gt;</span>
  <a id="cb3-8" class="sourceLine" data-line-number="8"></a>  It should be immediately obvious that the image is
  <a id="cb3-9" class="sourceLine" data-line-number="9"></a>  no longer contained within the paragraph it was
  <a id="cb3-10" class="sourceLine" data-line-number="10"></a>  embedded.<span class="kw">&lt;/p&gt;</span>
  <a id="cb3-11" class="sourceLine" data-line-number="11"></a>
  <a id="cb3-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"paragraph3"</span><span class="ot"> class=</span><span class="st">"border orange-bg"</span><span class="kw">&gt;</span>
  <a id="cb3-13" class="sourceLine" data-line-number="13"></a>  In fact, it is spilling over several paragraph
  <a id="cb3-14" class="sourceLine" data-line-number="14"></a>  blocks, as if it were laid on top of them.<span class="kw">&lt;/p&gt;</span>
  <a id="cb3-15" class="sourceLine" data-line-number="15"></a>
  <a id="cb3-16" class="sourceLine" data-line-number="16"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"paragraph4"</span><span class="ot"> class=</span><span class="st">"border cyan-bg"</span><span class="kw">&gt;</span>
  <a id="cb3-17" class="sourceLine" data-line-number="17"></a>  But it doesn't cover up the words or content.
  <a id="cb3-18" class="sourceLine" data-line-number="18"></a> <span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Gives the following results:</p>
<div style="background-color: white; border: 1px solid black; padding: 0.5em;">
<p id="paragraph1" style="border: 2px solid black; background: yellow;"><img decoding="async" style="float: left; margin: none;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/05/26-dog-compressor.jpg" /> To make the problem stand out, each paragraph is uniquely identified and has a border and background colour styling applied.</p>
<p id="paragraph1" style="border: 2px solid black; background: lime;">It should be immediately obvious that the image is no longer contained within the paragraph it was embedded.</p>
<p id="paragraph1" style="border: 2px solid black; background: orange;">In fact, it is spilling over several paragraph blocks as if it were laid on top of them.</p>
<p id="paragraph1" style="border: 2px solid black; background: cyan;">But it doesn’t cover up the words or content.</p>
<div style="clear: both;"></div>
</div>
<p>In the next tutorial, we will learn why this happens and what we can do about it.</p>
<h2 id="summary">Summary</h2>
<ol type="1">
<li>The <span class="css-property">float</span> can be used to position an element to the left or right side of a page.</li>
<li>Content (usually text) will flow around the floated element.</li>
</ol>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.<br />
Try using <span class="css-property">float</span>. The easiest and most visual way is to use small images, although you can also create coloured boxes and use those.<br />
Apply it to a single HTML element, to multiple HTML elements. What happens when you nest floated elements?<br />
The idea is to get a feel for how <span class="css-property">float</span> behaves when you use it.</p>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://www.w3.org/TR/CSS2/visuren.html#float-position">float</a></li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-understanding-how-float-works-part-1">Next</a>
</div>
<div class="clear"></div>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-introducing-float/">CSS &#8211; Introducing float</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ten More HTML Tags to Play With</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/ten-more-html-tags-to-play-with/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Thu, 22 Mar 2018 19:42:36 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></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=3468</guid>

					<description><![CDATA[<p>Expand your HTML vocabulary with ten new tags.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/ten-more-html-tags-to-play-with/">Ten More HTML Tags to Play With</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
So far, we have created a <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/your-first-webpage-hello-world">simple HTML5 page</a> that displayed the text <strong>Hello World!</strong> &#8211; which was done with a single line of code:</p>
<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="kw">&lt;p&gt;</span>Hello World!<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>The rest of the HTML was boilerplate code that we <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-very-basic-html5-template">extracted into a template</a> for future use.<br />
Thus tutorial expands your HTML vocabulary with ten new tags.
</div>
<p>So far, the only tag you have used for displaying text on the screen is the <span class="kbd">&lt;p&gt;</span> tag. This is also known as the <strong>paragraph</strong> tag because it marks a paragraph of text.<br />
<strong>HTML5</strong> tags are case-insensitive, so it doesn’t matter if you write them in UPPERCASE, lowercase, or MiXeDcAsE.<br />
Most developers write <strong>HTML</strong> tags in lowercase, however, there are some who prefer UPPERCASE because it makes the tags stand out more.</p>
<h2 id="contents">Contents</h2>
<ol type="1">
<li><a href="#h1---h6">h1 &#8211; h6</a></li>
<li><a href="#strong">strong</a></li>
<li><a href="#em">em</a></li>
<li><a href="#i">i</a></li>
<li><a href="#mark">mark</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="h1---h6">h1 &#8211; h6</h2>
<p>The first six tags are known as <strong>heading</strong> tags. They are used to mark a <strong>heading</strong> for a block of text (think of it as the start of a section or subsection). They indicate the hierarchical structure of your document.<br />
<span class="kbd">&lt;h1&gt;</span> has the highest rank and <span class="kbd">&lt;h6&gt;</span> has the lowest.<br />
Each <span class="kbd">&lt;tag&gt;</span> must have a corresponding closing <span class="kbd">&lt;/tag&gt;</span> tag.<br />
Consider the following code:</p>
<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="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb2-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb2-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb2-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Testing Header Tags<span class="kw">&lt;/title&gt;</span>
<a id="cb2-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="cb2-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb2-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb2-8" class="sourceLine" data-line-number="8"></a>
<a id="cb2-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;h1&gt;</span>Header 1<span class="kw">&lt;/h1&gt;</span>
<a id="cb2-10" class="sourceLine" data-line-number="10"></a>      <span class="kw">&lt;p&gt;</span>Some h1 Text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-11" class="sourceLine" data-line-number="11"></a>    <span class="kw">&lt;h2&gt;</span>Header 2<span class="kw">&lt;/h2&gt;</span>
<a id="cb2-12" class="sourceLine" data-line-number="12"></a>      <span class="kw">&lt;p&gt;</span>Some h2 text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-13" class="sourceLine" data-line-number="13"></a>    <span class="kw">&lt;h3&gt;</span>Header 1<span class="kw">&lt;/h3&gt;</span>
<a id="cb2-14" class="sourceLine" data-line-number="14"></a>      <span class="kw">&lt;p&gt;</span>Some h3 Text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-15" class="sourceLine" data-line-number="15"></a>    <span class="kw">&lt;h4&gt;</span>Header 2<span class="kw">&lt;/h4&gt;</span>
<a id="cb2-16" class="sourceLine" data-line-number="16"></a>      <span class="kw">&lt;p&gt;</span>Some h4 text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-17" class="sourceLine" data-line-number="17"></a>    <span class="kw">&lt;h5&gt;</span>Header 1<span class="kw">&lt;/h5&gt;</span>
<a id="cb2-18" class="sourceLine" data-line-number="18"></a>      <span class="kw">&lt;p&gt;</span>Some h5 Text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-19" class="sourceLine" data-line-number="19"></a>    <span class="kw">&lt;h6&gt;</span>Header 2<span class="kw">&lt;/h6&gt;</span>
<a id="cb2-20" class="sourceLine" data-line-number="20"></a>      <span class="kw">&lt;p&gt;</span>Some h6 text.<span class="kw">&lt;/p&gt;</span>
<a id="cb2-21" class="sourceLine" data-line-number="21"></a>
<a id="cb2-22" class="sourceLine" data-line-number="22"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb2-23" class="sourceLine" data-line-number="23"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>If you create a webpage using the code above, you will notice the headers are displayed in different font sizes and weights according to their importance, while the text all remains the same.<br />
Since the <span class="kbd">&lt;h1&gt;</span> to <span class="kbd">&lt;h6</span> tags provide hierarchical structure to the content on the page, the general guidance for their use are:</p>
<ul>
<li><span class="kbd">&lt;h1&gt;</span> should be used for the title on the page.</li>
<li><span class="kbd">&lt;h2&gt;</span> should be used for individual sections on the page.</li>
<li><span class="kbd">&lt;h3&gt;</span>&#8211; <span class="kbd">&lt;h6&gt;</span> should for increasing subsections under <span class="kbd">&lt;h2&gt;</span>.</li>
</ul>
<p>Tools can use these tags to extract an outline of the content of your document &#8211; for example, to generate a table of contents.<br />
The code above has the following structure:</p>
<ol type="1">
<li>Header 1
<ol type="1">
<li>Header 2
<ol type="1">
<li>Header 3
<ol type="1">
<li>Header 4
<ol type="1">
<li>Header 5
<ol type="1">
<li>Header 6</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>The tutorial <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/what-do-you-need-to-start-front-end-web-development">What Do You Need to Start Front-End Web Development?</a> has the following heading structure:</p>
<ol type="1">
<li>What Do You Need to Start Front-End Web Development? <span class="kbd">&lt;h1&gt;</span>
<ol type="1">
<li>Contents <span class="kbd">&lt;h2&gt;</span></li>
<li>Skills <span class="kbd">&lt;h2&gt;</span></li>
<li>Tools <span class="kbd">&lt;h2&gt;</span>
<ol type="1">
<li>Web Browser <span class="kbd">&lt;h3&gt;</span></li>
<li>Text Editor <span class="kbd">&lt;h3&gt;</span></li>
</ol>
</li>
</ol>
</li>
</ol>
<p>You can have more than one <span class="kbd">&lt;h1&gt;</span> tag on your page, but that might suggest that each <span class="kbd">&lt;h1&gt;</span> should have its own page.<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></p>
<h2 id="strong">strong</h2>
<p>The <span class="kbd">&lt;strong&gt;</span> tag is used to indicate content that is important, serious, or urgent.<br />
Each <span class="kbd">&lt;strong&gt;</span> tag must have a corresponding closing <span class="kbd">&lt;/strong&gt;</span> tag.<br />
The general guidance for use of this tag are:</p>
<ul>
<li><strong>Important</strong>: parts of the document that matter more than other parts</li>
<li><strong>Serious</strong>: parts of a document that show a warning or caution notice</li>
<li><strong>Urgent</strong>: parts of the document that the user should notice sooner than other parts of the document</li>
</ul>
<p>Consider the code:</p>
<div id="cb3" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb3-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb3-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb3-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb3-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Testing The Strong Tag<span class="kw">&lt;/title&gt;</span>
<a id="cb3-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="cb3-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb3-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb3-8" class="sourceLine" data-line-number="8"></a>
<a id="cb3-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;p&gt;&lt;strong&gt;</span>Lorem ipsum dolor sit amet<span class="kw">&lt;/strong&gt;</span>,
<a id="cb3-10" class="sourceLine" data-line-number="10"></a>      consectetur adipiscing elit, sed do eiusmod tempor
<a id="cb3-11" class="sourceLine" data-line-number="11"></a>      incididunt ut labore et dolore magna aliqua.<span class="kw">&lt;/p&gt;</span>
<a id="cb3-12" class="sourceLine" data-line-number="12"></a>
<a id="cb3-13" class="sourceLine" data-line-number="13"></a>    <span class="kw">&lt;p&gt;&lt;strong&gt;</span>Odio ut enim blandit volutpat maecenas.
<a id="cb3-14" class="sourceLine" data-line-number="14"></a>    <span class="kw">&lt;/strong&gt;</span> Accumsan lacus vel facilisis volutpat est
<a id="cb3-15" class="sourceLine" data-line-number="15"></a>    velit egestas dui. Eleifend quam adipiscing vitae
<a id="cb3-16" class="sourceLine" data-line-number="16"></a>    proin sagittis. <span class="kw">&lt;/p&gt;</span>
<a id="cb3-17" class="sourceLine" data-line-number="17"></a>
<a id="cb3-18" class="sourceLine" data-line-number="18"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb3-19" class="sourceLine" data-line-number="19"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>If you create a webpage using the code above, you will notice the first part of both paragraphs is rendered in <strong>bold</strong> text.<br />
There is an <strong>HTML</strong> tag <span class="kbd">&lt;b&gt;</span> that is for <strong>bold</strong> text. In general, you should avoid using this tag because it has no <em>semantic</em> meaning. In other words, using it doesn’t add any information to the document<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a> &#8211; it simply indicates the text should be displayed differently, but is not significant in any other way.</p>
<h2 id="em">em</h2>
<p>The <span class="kbd">&lt;em&gt;</span> tag is used to indicate <em>emphasis</em> on part of a document, but not <strong>importance</strong> (for which you should use the <span class="kbd">&lt;strong&gt;</span> tag).<br />
Each <span class="kbd">&lt;em&gt;</span> tag must have a corresponding closing <span class="kbd">&lt;/em&gt;</span> tag.<br />
Consider the code:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb4-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb4-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Testing The Emphasis Tag<span class="kw">&lt;/title&gt;</span>
<a id="cb4-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="cb4-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb4-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb4-8" class="sourceLine" data-line-number="8"></a>
<a id="cb4-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;p&gt;&lt;em&gt;</span>Lorem ipsum dolor sit amet<span class="kw">&lt;/em&gt;</span>, consectetur
<a id="cb4-10" class="sourceLine" data-line-number="10"></a>      adipiscing elit, sed do eiusmod tempor incididunt
<a id="cb4-11" class="sourceLine" data-line-number="11"></a>      ut labore et dolore magna aliqua.<span class="kw">&lt;/p&gt;</span>
<a id="cb4-12" class="sourceLine" data-line-number="12"></a>
<a id="cb4-13" class="sourceLine" data-line-number="13"></a>    <span class="kw">&lt;p&gt;&lt;em&gt;</span>Odio ut enim blandit volutpat maecenas.<span class="kw">&lt;/em&gt;</span>
<a id="cb4-14" class="sourceLine" data-line-number="14"></a>      Accumsan lacus vel facilisis volutpat est velit
<a id="cb4-15" class="sourceLine" data-line-number="15"></a>      egestas dui. Eleifend quam adipiscing vitae proin
<a id="cb4-16" class="sourceLine" data-line-number="16"></a>      sagittis. <span class="kw">&lt;/p&gt;</span>
<a id="cb4-17" class="sourceLine" data-line-number="17"></a>
<a id="cb4-18" class="sourceLine" data-line-number="18"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb4-19" class="sourceLine" data-line-number="19"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>If you create a webpage using the code above, you will notice the first part of both paragraphs is rendered in <em>italic</em> text.<br />
The <strong>HTML</strong> tag <span class="kbd">&lt;i&gt;</span> is for <em>italic</em> text and has a slightly different meaning from <span class="kbd">&lt;em&gt;</span>.<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></p>
<h2 id="i">i</h2>
<p>The <span class="kbd">&lt;i&gt;</span> tag is used to indicate text that is different from the normal flow of the text &#8211; for example, a foreign word.<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a><br />
Each <span class="kbd">&lt;i&gt;</span> tag must have a corresponding closing <span class="kbd">&lt;/i&gt;</span> tag.<br />
The general guidance for use of this tag are:</p>
<ul>
<li><strong>technical terms</strong>: It might surprise you to learn that <em>HTML</em> is more complicated and nuanced than you imagined.</li>
<li><strong>foreign language words or phrases</strong>: The phrase <i>Veni, vidi, vici</i> comes from Julius Caesar.</li>
<li><strong>internal thoughts</strong>: The student looked at the course syllabus and smiled. <i>This is going to be easy.</i></li>
</ul>
<p>Consider the code:</p>
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb5-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb5-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Testing The Emphasis Tag<span class="kw">&lt;/title&gt;</span>
<a id="cb5-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="cb5-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb5-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb5-8" class="sourceLine" data-line-number="8"></a>
<a id="cb5-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;p&gt;</span>Webpage developers often use <span class="kw">&lt;i&gt;</span>Lorem ipsum<span class="kw">&lt;/i&gt;</span>
<a id="cb5-10" class="sourceLine" data-line-number="10"></a>      to flesh out the page with content<span class="kw">&lt;/p&gt;</span>
<a id="cb5-11" class="sourceLine" data-line-number="11"></a>
<a id="cb5-12" class="sourceLine" data-line-number="12"></a>    <span class="kw">&lt;p&gt;&lt;i&gt;</span>Odio ut enim blandit volutpat maecenas.
<a id="cb5-13" class="sourceLine" data-line-number="13"></a>      Accumsan lacus vel facilisis volutpat est velit
<a id="cb5-14" class="sourceLine" data-line-number="14"></a>      egestas dui. Eleifend quam adipiscing vitae
<a id="cb5-15" class="sourceLine" data-line-number="15"></a>      proin sagittis.<span class="kw">&lt;/i&gt;&lt;/p&gt;</span>
<a id="cb5-16" class="sourceLine" data-line-number="16"></a>
<a id="cb5-17" class="sourceLine" data-line-number="17"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb5-18" class="sourceLine" data-line-number="18"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>If you create a webpage using the code above, you will notice <em>Loem ipsum</em> and the second paragraph are rendered in <em>italic</em> text.<br />
The <strong>HTML</strong> tag <span class="kbd">&lt;em&gt;</span> is for <em>emphasized</em> text and has a slightly different meaning from <span class="kbd">&lt;i&gt;</span>.<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a></p>
<h2 id="mark">mark</h2>
<p>The <span class="kbd">&lt;mark&gt;</span> tag is used to <em>mark</em> or <em>highlight</em> something for <strong>reference</strong> purposes. In other words, it is used to draw attention to something.<br />
Each <span class="kbd">&lt;mark&gt;</span> tag must have a corresponding closing <span class="kbd">&lt;/mark&gt;</span> tag.<br />
The general guidance for use of this tag are:</p>
<ul>
<li><strong>Bring attention to something</strong>: like a <mark>splling</mark> mistake</li>
<li><strong>Indicate a search string match</strong>: searching for text in a document is a comm<mark>on task</mark> on the computer, highlighting the matching text is good</li>
<li><strong>Bring attention to something relevant</strong>: It is important to know the purpose of <strong>HTML</strong> tags because <mark>different <strong>HTML</strong> tags are used for different purposes.</mark> Otherwise you end up using them willy-nilly.</li>
</ul>
<p>Consider the code:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb6-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb6-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb6-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb6-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Testing The Strong Tag<span class="kw">&lt;/title&gt;</span>
<a id="cb6-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="cb6-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb6-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb6-8" class="sourceLine" data-line-number="8"></a>
<a id="cb6-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;p&gt;</span>“That’s rather a broad idea,” I remarked.<span class="kw">&lt;/p&gt;</span>
<a id="cb6-10" class="sourceLine" data-line-number="10"></a>
<a id="cb6-11" class="sourceLine" data-line-number="11"></a>    <span class="kw">&lt;p&gt;</span>“One’s ideas must be as broad as Nature if they
<a id="cb6-12" class="sourceLine" data-line-number="12"></a>      are to interpret Nature,” he answered. “What’s
<a id="cb6-13" class="sourceLine" data-line-number="13"></a>      the matter? You’re not looking quite yourself.
<a id="cb6-14" class="sourceLine" data-line-number="14"></a>      This Brixton Road affair has upset you.”<span class="kw">&lt;/p&gt;</span>
<a id="cb6-15" class="sourceLine" data-line-number="15"></a>
<a id="cb6-16" class="sourceLine" data-line-number="16"></a>    <span class="kw">&lt;p&gt;</span>“To tell the truth, it has,” I said. “I ought to
<a id="cb6-17" class="sourceLine" data-line-number="17"></a>      be more case-hardened after my Afghan experiences.
<a id="cb6-18" class="sourceLine" data-line-number="18"></a>      I saw my own comrades hacked to pieces at Maiwand
<a id="cb6-19" class="sourceLine" data-line-number="19"></a>      without losing my nerve.”<span class="kw">&lt;/p&gt;</span>
<a id="cb6-20" class="sourceLine" data-line-number="20"></a>
<a id="cb6-21" class="sourceLine" data-line-number="21"></a>    <span class="kw">&lt;p&gt;</span>“I can understand. There is a mystery about this
<a id="cb6-22" class="sourceLine" data-line-number="22"></a>      which stimulates the imagination; <span class="kw">&lt;mark&gt;</span>where
<a id="cb6-23" class="sourceLine" data-line-number="23"></a>        there is no imagination there is no horror.
<a id="cb6-24" class="sourceLine" data-line-number="24"></a>      <span class="kw">&lt;/mark&gt;</span> Have you seen the evening paper?”<span class="kw">&lt;/p&gt;</span>
<a id="cb6-25" class="sourceLine" data-line-number="25"></a>
<a id="cb6-26" class="sourceLine" data-line-number="26"></a>    <span class="kw">&lt;p&gt;</span>“No.”<span class="kw">&lt;/p&gt;</span>
<a id="cb6-27" class="sourceLine" data-line-number="27"></a>
<a id="cb6-28" class="sourceLine" data-line-number="28"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb6-29" class="sourceLine" data-line-number="29"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<p>If you create a webpage using the code above, you will notice that a portion of the text<a id="fnref6" class="footnote-ref" href="#fn6"><sup>6</sup></a> is highlighted.</p>
<h2 id="summary">Summary</h2>
<p>Even though the tags introduced in this tutorial affect the way text is rendered (displayed) in a browser, they are used to provide structure and meaning to the content, not appearance. Appearance (styling) should be done using CSS (which will be covered in later tutorials).</p>
<ol type="1">
<li>Use heading tags to hierarchically structure the contents of your document.</li>
<li>Use <span class="kbd">&lt;strong&gt;</span> tags to mark <strong>important</strong> content.</li>
<li>Use <span class="kbd">&lt;em&gt;</span> tags to <em>emphasize</em> content.</li>
<li>Use <span class="kbd">&lt;i&gt;</span> tags to mark content that has a different <em>flow</em> or <em>aspect</em> from the surrounding content.</li>
<li>Use <span class="kbd">&lt;mark&gt;</span> tags to content you want to <mark>highlight</mark>.</li>
</ol>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.<br />
Use the tags introduced in this section &#8211; along with the <span class="kbd">&lt;p&gt;</span> tag &#8211; to create some basic webpages with content. They will be very plain pages because there is no styling.<a id="fnref7" class="footnote-ref" href="#fn7"><sup>7</sup></a><br />
Some webpage ideas are:</p>
<ul>
<li>your resume (or <em>curriculum vitae</em>)</li>
<li>a recipe</li>
<li>a collection of recipes (each recipe would be in its own section, so each recipe title would probably start with a <span class="kbd">&lt;h1&gt;</span> tag)</li>
<li>study notes for this series of tutorials.</li>
</ul>
<p>Only use the tags you learned so far. As this series progresses, we will cover all the tags and their uses. The point, right now, is to reinforce what you have learned.<br />
If you are really stuck. You can go to <a href="http://www.gutenberg.org/ebooks/search/?sort_order=release_date">Project Gutenberg</a>:</p>
<ul>
<li>find a book</li>
<li>copy &amp; paste some text from it into your webpage</li>
<li>format the paragraphs using <span class="kbd">&lt;p&gt;</span> tags</li>
<li>add a short header before each paragraph (the header should introduce the main point of the paragraph)</li>
<li>use the tags to mark up the text. Decide what is important, what needs emphasis, what flows differently from the text around it, and what needs to be highlighted</li>
</ul>
<p>There are no right or wrong webpages. The point is to practice what you have learned and become comfortable with:</p>
<ul>
<li>writing <strong>HTML5</strong> code</li>
<li>using the tags you know</li>
</ul>
<p>As well, try mixing and matching the tags. Can you use combine them? It should be obvious that the <span class="kbd">&lt;strong&gt;</span>, <span class="kbd">&lt;em&gt;</span>, <span class="kbd">&lt;i&gt;</span>, <span class="kbd">&lt;mark&gt;</span> tags can be used on content inside of <span class="kbd">&lt;p&gt;</span> tags:</p>
<ul>
<li>can they be used on content inside heading tags?</li>
<li>can they be combined?</li>
<li>can you have paragraph or heading tags around content inside those tags?</li>
</ul>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements">Heading Tags</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-strong-element"><span class="kbd">&lt;strong&gt;</span> tag</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-em-element"><span class="kbd">&lt;em&gt;</span> tag</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-i-element"><span class="kbd">&lt;i&gt;</span> tag</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-mark-element"><span class="kbd">&lt;mark&gt;</span> tag</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element"><span class="kbd">&lt;p&gt;</span> tag</a></li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-very-basic-html5-template">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-recipe-example">Next</a>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">The exception to this would be if you are using the <span class="kbd">&lt;section&gt;</span> and / or <span class="kbd">&lt;article&gt;</span> tags. These will be covered in a later tutorial.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">HTML documents might be accessed by (1) people reading the content, (2) visually impaired people listening to the content being read by text-to-speech software, (3) computers trying to extract information. Visual flourishes, should be done using CSS.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">HTML documents might be accessed by (1) people reading the content, (2) visually impaired people listening to the content being read by text-to-speech software, (3) computers trying to extract information. Visual flourishes, should be done using CSS.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">In earlier versions of HTML, the <span class="kbd">&lt;i&gt;</span> tag was used to set the text to <em>italics</em>. In HTML5, the meaning (semantics) has been changed. In HTML5, all styling should be done using CSS. HTML should be used only to provide <strong>structure</strong> and <strong>semantics</strong> (meaning) to the content of the document.<a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">HTML documents might be accessed by (1) people reading the content, (2) visually impaired people listening to the content being read by text-to-speech software, (3) computers trying to extract information. Visual flourishes, should be done using CSS.<a class="footnote-back" href="#fnref5">↩</a></li>
<li id="fn6">The text is taken from the Sherlock Holmes story, “A Study in Scarlett”.<a class="footnote-back" href="#fnref6">↩</a></li>
<li id="fn7">Styling is done using CSS and will be covered in later tutorials.<a class="footnote-back" href="#fnref7">↩</a></li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/ten-more-html-tags-to-play-with/">Ten More HTML Tags to Play With</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
