 
    
<?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>webdev Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/webdev/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Sat, 18 Mar 2023 19:50:54 +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 &#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; 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>A Page &#060;div&#062;ided</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 30 Apr 2018 04:45:00 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[span]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3653</guid>

					<description><![CDATA[<p>A worked example using &#60;div&#62; for sectioning content and 'margin:auto' for centering.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided/">A Page &#060;div&#062;ided</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/example-page-where-the-content-is-not-flush-with-the-left-side">exercise</a> was an attempt to structure and (roughly) centre webpage content.<br />
In this example we use <span class="html-tag">div</span> for sectioning the content on the page and <span class="css-property">margin:</span><span class="css-value">auto</span> to centre it.
</div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#an-example-using-divs">An Example Using <span class="html-tag">div</span>s</a></li>
<li><a href="#div-source-code"><span class="html-tag">div</span> Source Code</a></li>
<li><a href="#notes">Notes</a></li>
<li><a href="#span-challenges"><span class="html-tag">span</span> Challenges</a></li>
</ol>
<h2 id="an-example-using-divs">An Example Using <span class="html-tag">div</span>s</h2>
<p>You can see how the page I styled and structured using <span class="html-tag">div</span>s looks <a href="https://complete-concrete-concise.com/sample/25-div.html">here</a>.</p>
<h2 id="div-source-code"><span class="html-tag">div</span> 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>A  Page <span class="dv">&amp;lt;</span>Div<span class="dv">&amp;gt;</span>ided<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="fu">.main</span> {
<a id="cb1-10" class="sourceLine" data-line-number="10"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;
<a id="cb1-11" class="sourceLine" data-line-number="11"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<a id="cb1-12" class="sourceLine" data-line-number="12"></a>        <span class="kw">width</span>: <span class="dv">600px</span>;
<a id="cb1-13" class="sourceLine" data-line-number="13"></a>        <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb1-14" class="sourceLine" data-line-number="14"></a>      }
<a id="cb1-15" class="sourceLine" data-line-number="15"></a>
<a id="cb1-16" class="sourceLine" data-line-number="16"></a>      <span class="fu">.header</span>, <span class="fu">.footer</span> {
<a id="cb1-17" class="sourceLine" data-line-number="17"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb1-18" class="sourceLine" data-line-number="18"></a>        <span class="kw">padding</span>: <span class="dv">16px</span> <span class="dv">0</span>;
<a id="cb1-19" class="sourceLine" data-line-number="19"></a>      }
<a id="cb1-20" class="sourceLine" data-line-number="20"></a>
<a id="cb1-21" class="sourceLine" data-line-number="21"></a>      <span class="fu">.header</span> {
<a id="cb1-22" class="sourceLine" data-line-number="22"></a>        <span class="kw">background-color</span>: <span class="dv">blue</span>;
<a id="cb1-23" class="sourceLine" data-line-number="23"></a>        <span class="kw">color</span>: <span class="dv">white</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="pp">#title</span> {
<a id="cb1-27" class="sourceLine" data-line-number="27"></a>        <span class="kw">font-size</span>: <span class="dv">32px</span>;
<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="pp">#subtitle</span> {
<a id="cb1-31" class="sourceLine" data-line-number="31"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb1-32" class="sourceLine" data-line-number="32"></a>      }
<a id="cb1-33" class="sourceLine" data-line-number="33"></a>
<a id="cb1-34" class="sourceLine" data-line-number="34"></a>      <span class="fu">.content</span> {
<a id="cb1-35" class="sourceLine" data-line-number="35"></a>        <span class="kw">font-size</span>: <span class="dv">16px</span>;
<a id="cb1-36" class="sourceLine" data-line-number="36"></a>        <span class="kw">text-align</span>: <span class="dv">justify</span>;
<a id="cb1-37" class="sourceLine" data-line-number="37"></a>      }
<a id="cb1-38" class="sourceLine" data-line-number="38"></a>
<a id="cb1-39" class="sourceLine" data-line-number="39"></a>      <span class="fu">.footer</span> {
<a id="cb1-40" class="sourceLine" data-line-number="40"></a>        <span class="kw">color</span>: <span class="dv">blue</span>;
<a id="cb1-41" class="sourceLine" data-line-number="41"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb1-42" class="sourceLine" data-line-number="42"></a>        <span class="kw">background-color</span>: <span class="dv">yellow</span>;
<a id="cb1-43" class="sourceLine" data-line-number="43"></a>      }
<a id="cb1-44" class="sourceLine" data-line-number="44"></a>
<a id="cb1-45" class="sourceLine" data-line-number="45"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb1-46" class="sourceLine" data-line-number="46"></a>
<a id="cb1-47" class="sourceLine" data-line-number="47"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb1-48" class="sourceLine" data-line-number="48"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb1-49" class="sourceLine" data-line-number="49"></a>
<a id="cb1-50" class="sourceLine" data-line-number="50"></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-51" class="sourceLine" data-line-number="51"></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-52" class="sourceLine" data-line-number="52"></a>        <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"title"</span><span class="kw">&gt;</span>A Page <span class="dv">&amp;lt;</span>Div<span class="dv">&amp;gt;</span>ided<span class="kw">&lt;/p&gt;</span>
<a id="cb1-53" class="sourceLine" data-line-number="53"></a>        <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"subtitle"</span><span class="kw">&gt;</span>
<a id="cb1-54" class="sourceLine" data-line-number="54"></a>          Handling HTML one <span class="dv">&amp;lt;</span>div<span class="dv">&amp;gt;</span> at a time
<a id="cb1-55" class="sourceLine" data-line-number="55"></a>        <span class="kw">&lt;/p&gt;</span>
<a id="cb1-56" class="sourceLine" data-line-number="56"></a>      <span class="kw">&lt;/div&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;div</span><span class="ot"> class=</span><span class="st">"content"</span><span class="kw">&gt;</span>
<a id="cb1-59" class="sourceLine" data-line-number="59"></a>        <span class="kw">&lt;p&gt;</span>
<a id="cb1-60" class="sourceLine" data-line-number="60"></a>          Quam stultum est aetatem disponere ne crastini
<a id="cb1-61" class="sourceLine" data-line-number="61"></a>          quidem dominum! o quanta dementia est spes
<a id="cb1-62" class="sourceLine" data-line-number="62"></a>          longas inchoantium: emam, aedificabo, credam,
<a id="cb1-63" class="sourceLine" data-line-number="63"></a>          exigam, honores geram, tum deinde lassam et
<a id="cb1-64" class="sourceLine" data-line-number="64"></a>          plenam senectutem in otium referam.
<a id="cb1-65" class="sourceLine" data-line-number="65"></a>        <span class="kw">&lt;/p&gt;</span>
<a id="cb1-66" class="sourceLine" data-line-number="66"></a>        <span class="kw">&lt;p&gt;</span>Omnia, mihi crede, etiam
<a id="cb1-67" class="sourceLine" data-line-number="67"></a>          felicibus dubia sunt; nihil sibi quisquam de
<a id="cb1-68" class="sourceLine" data-line-number="68"></a>          futuro debet promittere; id quoque quod
<a id="cb1-69" class="sourceLine" data-line-number="69"></a>          tenetur per manus exit et ipsam quam premimus
<a id="cb1-70" class="sourceLine" data-line-number="70"></a>          horam casus incidit. Volvitur tempus rata
<a id="cb1-71" class="sourceLine" data-line-number="71"></a>          quidem lege, sed per obscurum: quid autem ad
<a id="cb1-72" class="sourceLine" data-line-number="72"></a>          me an naturae certum sit quod mihi incertumest?
<a id="cb1-73" class="sourceLine" data-line-number="73"></a>        <span class="kw">&lt;/p&gt;</span>
<a id="cb1-74" class="sourceLine" data-line-number="74"></a>        <span class="kw">&lt;ol&gt;</span>
<a id="cb1-75" class="sourceLine" data-line-number="75"></a>          <span class="kw">&lt;li&gt;</span>Stat quidem terminusnobis ubi illum
<a id="cb1-76" class="sourceLine" data-line-number="76"></a>            inexorabilis fatorum necessitas fixit, sed
<a id="cb1-77" class="sourceLine" data-line-number="77"></a>            nemo scit nostrumquam prope versetur a
<a id="cb1-78" class="sourceLine" data-line-number="78"></a>            termino; sic itaque formemus animum tamquam
<a id="cb1-79" class="sourceLine" data-line-number="79"></a>            ad extremaventum sit.
<a id="cb1-80" class="sourceLine" data-line-number="80"></a>          <span class="kw">&lt;/li&gt;</span>
<a id="cb1-81" class="sourceLine" data-line-number="81"></a>          <span class="kw">&lt;li&gt;</span>Nihil differamus; cotidie cum vita paria
<a id="cb1-82" class="sourceLine" data-line-number="82"></a>            faciamus.
<a id="cb1-83" class="sourceLine" data-line-number="83"></a>          <span class="kw">&lt;/li&gt;</span>
<a id="cb1-84" class="sourceLine" data-line-number="84"></a>          <span class="kw">&lt;li&gt;</span>Maximum vitae vitium est quod inperfecta
<a id="cb1-85" class="sourceLine" data-line-number="85"></a>            semper est, quod [in] aliquid ex illa
<a id="cb1-86" class="sourceLine" data-line-number="86"></a>            differtur.
<a id="cb1-87" class="sourceLine" data-line-number="87"></a>          <span class="kw">&lt;/li&gt;</span>
<a id="cb1-88" class="sourceLine" data-line-number="88"></a>          <span class="kw">&lt;/li&gt;</span>Qui cotidie vitae suae summam manum
<a id="cb1-89" class="sourceLine" data-line-number="89"></a>            inposuit non indiget tempore;ex hac autem
<a id="cb1-90" class="sourceLine" data-line-number="90"></a>            indigentia timor nascitur et cupiditas futuri
<a id="cb1-91" class="sourceLine" data-line-number="91"></a>            exedens animum. Nihil est miserius dubitatione
<a id="cb1-92" class="sourceLine" data-line-number="92"></a>            venientium quorsus evadant; quantum sit illud
<a id="cb1-93" class="sourceLine" data-line-number="93"></a>            quod restat aut quale sollicita mens
<a id="cb1-94" class="sourceLine" data-line-number="94"></a>            inexplicabili formidine agitatur.
<a id="cb1-95" class="sourceLine" data-line-number="95"></a>          <span class="kw">&lt;/li&gt;</span>
<a id="cb1-96" class="sourceLine" data-line-number="96"></a>        <span class="kw">&lt;/ol&gt;</span>
<a id="cb1-97" class="sourceLine" data-line-number="97"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-98" class="sourceLine" data-line-number="98"></a>
<a id="cb1-99" class="sourceLine" data-line-number="99"></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-100" class="sourceLine" data-line-number="100"></a>        <span class="kw">&lt;p&gt;</span>Copyright 2018<span class="kw">&lt;/p&gt;</span>
<a id="cb1-101" class="sourceLine" data-line-number="101"></a>      <span class="kw">&lt;/div&gt;</span>
<a id="cb1-102" class="sourceLine" data-line-number="102"></a>
<a id="cb1-103" class="sourceLine" data-line-number="103"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb1-104" class="sourceLine" data-line-number="104"></a>
<a id="cb1-105" class="sourceLine" data-line-number="105"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb1-106" class="sourceLine" data-line-number="106"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h2 id="notes">Notes</h2>
<ol type="1">
<li>Most of the content is the same as the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/example-page-where-the-content-is-not-flush-with-the-left-side">previous example</a>.</li>
<li>The webpage is sectioned into 4 parts:
<ol type="1">
<li>a <strong>main</strong> <span class="html-tag">div</span>] which is used to contain and centre everything else on the page.</li>
<li>A <strong>header</strong> <span class="html-tag">div</span> which contains heading content that is common across all pages.</li>
<li>A <strong>content</strong> <span class="html-tag">div</span> which contains the page content.</li>
<li>A <strong>footer</strong> <span class="html-tag">div</span> which contains common content that would be common across all pages.</li>
</ol>
</li>
<li>While <strong>classes</strong> were used for the <strong>main</strong>. <strong>header</strong>, <strong>content</strong>, and <strong>footer</strong> sections, <strong>ID</strong>s would have been a better option. Since there should only be one of each on the page.</li>
<li>The <strong>content</strong> is justified.</li>
<li>Common styling for the <span class="css-class">.header</span> and <span class="css-class">.footer</span> were gathered together. Individual <span class="css-class">.header</span> and <span class="css-class">.footer</span> styling were applied later. This could also have been done using addition classes. There are always many ways to do things, but the general guideline should be to try and minimize:
<ol type="1">
<li>the number of duplications &#8211; if you find yourself creating lots of classes with the same styling information, perhaps you should consider gathering the styling information together. You could extract it into a common class, or into a common wrapper.</li>
<li>the number of specific styling classes you apply to each HTML element. While you can have a long chain of styling classes for an HTML element you should ensure that it is necessary.</li>
</ol>
<p>The general goal is to make your pages easier to create and easy to maintain. Always ask yourself, “How much code would I have to change if all the styling is changed?” It is always a balance and something that comes with experience.</li>
</ol>
<h2 id="span-challenges"><span class="html-tag">span</span> Challenges</h2>
<p>You were also asked how would you create the following <span class="html-tag">span</span> styles:</p>
<div style="background: white; border: 1px solid black; padding: 0.5em;">
Underline a <span style="border-bottom: 2px solid red;">mistake</span> in red?<br />
Create a space for people to in?
</div>
<p>It could be done with these classes:</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">.red-underline</span> {
<a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">border-bottom</span>: <span class="dv">2px</span> <span class="dv">solid</span> <span class="dv">red</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">.four-char-space</span> {
<a id="cb2-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">border-bottom</span>: <span class="dv">2px</span> <span class="dv">solid</span> <span class="dv">black</span>;
<a id="cb2-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">width</span>: <span class="dv">64px</span>;
<a id="cb2-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">display</span>: <span class="dv">inline-block</span>;
<a id="cb2-9" class="sourceLine" data-line-number="9"></a>
<a id="cb2-10" class="sourceLine" data-line-number="10"></a>}</code></pre>
</div>
<p>The red underline should be obvious &#8211; simply apply a red border to the bottom of the <span class="html-tag">span</span>.<br />
The space for 4 characters is probably not so obvious:</p>
<ol type="1">
<li>The <span class="css-property">width</span> is set to 64px based on the assumption that the font size is 16px (I could have set it explicitly just to be sure). Perhaps it should have been made 96px to have additional padding on either side.</li>
<li>The <span class="css-property">display</span> is set to <span class="css-value">inline-block</span> because <strong>inline</strong> elements ignore any applied <span class="css-property">width</span> or <span class="css-property">height</span> values.</li>
<li>The <span class="css-property">width</span> has to be set because you can’t insert a bunch of spaces. Remember that HTML automatically collapses all white space into a single whitespace character.</li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/css-introducing-float">Next</a>
</div>
<div class="clear"></div>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided/">A Page &#060;div&#062;ided</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Sectioning Using HTML and Auto Centering Content</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Sat, 28 Apr 2018 04:52:11 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[margin: auto]]></category>
		<category><![CDATA[span]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3643</guid>

					<description><![CDATA[<p>We saw that you can style the &#60;body&#62; tag to contain your content. In this tutorial, we'll see a better way.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content/">Sectioning Using HTML and Auto Centering Content</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
In the previous exercise, you saw that it is possible to structure the width and position of content using the <span class="html-tag">body</span> element.<br />
The <span class="html-tag">body</span> is rarely styled, except for possibly a background. HTML has a number of invisible HTML elements that are used for structuring your content.
</div>
<p>The HTML elements you have seen can be best described as <strong>content</strong> elements because they either marked up specific content &#8211; like paragraphs, lists, headings, or hyperlinks &#8211; or they add semantic meaning to the content &#8211; <span class="html-tag">strong</span>, <span class="html-tag">em</span>, <span class="html-tag">i</span>, or <span class="html-tag">mark</span>. But they don’t group together related items &#8211; all elements are pretty much independent of each other.<br />
HTML provides a number of elements that allow styling without semantic meaning or grouping together related items.</p>
<h2>Contents</h2>
<ol type="1">
<li><a href="#span"><span class="html-tag">span</span></a></li>
<li><a href="#div"><span class="html-tag">div</span></a></li>
<li><a href="#centering-blocks-using-margin-auto">Centering Blocks Using <span class="css-property">margin: auto;</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="span"><span class="html-tag">span</span></h2>
<p>The <span class="html-tag">span</span> element behaves very much like <span class="html-tag">strong</span>, <span class="html-tag">em</span>, <span class="html-tag">i</span>, or<span class="html-tag">mark</span>: it is <strong>inline</strong> and it can be applied to a bunch of 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;</span>This is some <span class="kw">&lt;strong&gt;</span>strong text<span class="kw">&lt;/strong&gt;&lt;/p&gt;</span>
<a id="cb1-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;p&gt;</span>This is some <span class="kw">&lt;i&gt;</span>italic text<span class="kw">&lt;/i&gt;&lt;/p&gt;</span>
<a id="cb1-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;p&gt;</span>This is some <span class="kw">&lt;span&gt;</span>span text<span class="kw">&lt;/span&gt;&lt;/p&gt;</span></code></pre>
</div>
<p>Since the <span class="html-tag">span</span> element has no styling applied, the text it encloses will use whatever style is applied to the <span class="html-tag">p</span> tag.<br />
More importantly, the <span class="html-tag">span</span> element has <strong>no semantic meaning</strong>. Any styles you apply to a <span class="html-tag">span</span> are decorative &#8211; User Agents (browsers) will not infer anything special about that text.<br />
All the colour coding used in these pages is done using <span class="html-tag">span</span>.<br />
Consider:</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">.html-tag</span> {
<a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">background-color</span>: <span class="dv">#FCFCFC</span>;
<a id="cb2-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">border</span>: <span class="dv">1px</span> <span class="dv">solid</span> <span class="dv">black</span>;
<a id="cb2-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">border-radius</span>: <span class="dv">5px</span>;
<a id="cb2-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">padding</span>: <span class="dv">0</span> <span class="dv">3px</span>;
<a id="cb2-6" class="sourceLine" data-line-number="6"></a>}
<a id="cb2-7" class="sourceLine" data-line-number="7"></a>
<a id="cb2-8" class="sourceLine" data-line-number="8"></a><span class="fu">.css-property</span> {
<a id="cb2-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">font-size</span>: <span class="dv">18px</span>;
<a id="cb2-10" class="sourceLine" data-line-number="10"></a>  <span class="kw">font-weight</span>: <span class="dv">bold</span>;
<a id="cb2-11" class="sourceLine" data-line-number="11"></a>  <span class="kw">font-family</span>: <span class="dv">monospace</span>;
<a id="cb2-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">color</span>: <span class="dv">blue</span>;
<a id="cb2-13" class="sourceLine" data-line-number="13"></a>  <span class="kw">margin</span>: <span class="dv">0</span> <span class="dv">3px</span>;
<a id="cb2-14" class="sourceLine" data-line-number="14"></a>}</code></pre>
</div>
<p>When applied to the following text:<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></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&gt;</span>The paragraph is a common HTML element, it is
<a id="cb3-2" class="sourceLine" data-line-number="2"></a>  written <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">"html-tag"</span><span class="kw">&gt;</span><span class="dv">&amp;lt;</span>p<span class="dv">&amp;gt;</span><span class="kw">&lt;/span&gt;</span>.
<a id="cb3-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/p&gt;</span>
<a id="cb3-4" class="sourceLine" data-line-number="4"></a>
<a id="cb3-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;p&gt;</span>The eagle eyed will notice I use the CSS property
<a id="cb3-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">"css-property"</span><span class="kw">&gt;</span>border-radius<span class="kw">&lt;/span&gt;</span>
<a id="cb3-7" class="sourceLine" data-line-number="7"></a>  without having introduced it before.
<a id="cb3-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Results in the following output:</p>
<div style="background: white; padding: 0.5em; border: 1px solid black;">
The paragraph is a common HTML element, it is written <span style="background: #FCFCFC; border: 1px solid black; border-radius: 5px; padding: 0 3px;">&lt;p&gt;</span>.<br />
The eagle eyed will notice I use the CSS property <span style="font-size: 18px; font-weight: bold; font-family: monospace; color: blue; margin: 0 3px;">border-radius</span> without having introduced it before.
</div>
<p>By default it is an <strong>inline</strong> element, although you can change this with the <span class="css-property">display</span> property. You might change it to <strong>inline-block</strong> if you need to set its <span class="css-property">width</span> or <span class="css-property">height</span>. There is no need to change it to <strong>block</strong> because that is what <span class="html-tag">div</span> is for.</p>
<h2 id="div"><span class="html-tag">div</span></h2>
<p>The <span class="html-tag">div</span> element is similar the <span class="html-tag">span</span> element, except that it is a <strong>block</strong> display element. Like the <span class="html-tag">span</span> element, it has no semantic meaning. It is widely used for grouping things together.<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a><br />
Consider the HTML code used to display the output results above:</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">"output"</span><span class="kw">&gt;</span>
<a id="cb4-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;p&gt;</span>The paragraph is a common HTML element, it is
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>    written <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">"html-tag"</span><span class="kw">&gt;</span><span class="dv">&amp;lt;</span>p<span class="dv">&amp;gt;</span><span class="kw">&lt;/span&gt;</span>.
<a id="cb4-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb4-5" class="sourceLine" data-line-number="5"></a>
<a id="cb4-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;p&gt;</span>The eagle eyed will notice I use the CSS property
<a id="cb4-7" class="sourceLine" data-line-number="7"></a>    <span class="kw">&lt;span</span><span class="ot"> class=</span><span class="st">"css-property"</span><span class="kw">&gt;</span>border-radius<span class="kw">&lt;/span&gt;</span>
<a id="cb4-8" class="sourceLine" data-line-number="8"></a>    without having introduced it before.
<a id="cb4-9" class="sourceLine" data-line-number="9"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb4-10" class="sourceLine" data-line-number="10"></a><span class="kw">&lt;/div&gt;</span></code></pre>
</div>
<p>The styled paragraphs are contained inside a <span class="html-tag">div</span> block styled with the <span class="css-class">.output</span> class.<br />
Having a <span class="html-tag">div</span> as the first element inside the <span class="html-tag">body</span> is a very common programming pattern:</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;body&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">"main"</span><span class="kw">&gt;</span>
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>    A whole bunch of html
<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><span class="kw">&lt;/body&gt;</span></code></pre>
</div>
<p>It should be obvious how this can be applied to the previous coding exercise &#8211; instead of styling the <span class="html-tag">body</span> element, you would style the <span class="css-class">.main</span> class.<br />
Before HTML5, many websites had the following basic structure (actually, many websites still use this basic structure):</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="kw">&lt;body&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">"main"</span><span class="kw">&gt;</span>
<a id="cb6-3" class="sourceLine" data-line-number="3"></a>
<a id="cb6-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"header"</span><span class="kw">&gt;</span>
<a id="cb6-5" class="sourceLine" data-line-number="5"></a>      This section contains the common information
<a id="cb6-6" class="sourceLine" data-line-number="6"></a>      found at the top of the every webpage.
<a id="cb6-7" class="sourceLine" data-line-number="7"></a>
<a id="cb6-8" class="sourceLine" data-line-number="8"></a>      Stuff like the site name and logo.
<a id="cb6-9" class="sourceLine" data-line-number="9"></a>    <span class="kw">&lt;/div&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;div</span><span class="ot"> class=</span><span class="st">"navigation"</span><span class="kw">&gt;</span>
<a id="cb6-12" class="sourceLine" data-line-number="12"></a>      This is the navigation bar. Sometimes is may
<a id="cb6-13" class="sourceLine" data-line-number="13"></a>      be included in the "header", other times it
<a id="cb6-14" class="sourceLine" data-line-number="14"></a>      is on its own.
<a id="cb6-15" class="sourceLine" data-line-number="15"></a>
<a id="cb6-16" class="sourceLine" data-line-number="16"></a>      If the navigation is common to all pages, then
<a id="cb6-17" class="sourceLine" data-line-number="17"></a>      it should go inside the "header".
<a id="cb6-18" class="sourceLine" data-line-number="18"></a>    <span class="kw">&lt;/div&gt;</span>
<a id="cb6-19" class="sourceLine" data-line-number="19"></a>
<a id="cb6-20" class="sourceLine" data-line-number="20"></a>    <span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">"content"</span><span class="kw">&gt;</span>
<a id="cb6-21" class="sourceLine" data-line-number="21"></a>      There are, typically, a lot of <span class="kw">&lt;div&gt;</span>s in this
<a id="cb6-22" class="sourceLine" data-line-number="22"></a>      section and quite a lot of complicated structuring
<a id="cb6-23" class="sourceLine" data-line-number="23"></a>      code.
<a id="cb6-24" class="sourceLine" data-line-number="24"></a>    <span class="kw">&lt;/div&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;div</span><span class="ot"> class=</span><span class="st">"footer"</span><span class="kw">&gt;</span>
<a id="cb6-27" class="sourceLine" data-line-number="27"></a>      This section contains the common information
<a id="cb6-28" class="sourceLine" data-line-number="28"></a>      found at the bottom of the every webpage.
<a id="cb6-29" class="sourceLine" data-line-number="29"></a>
<a id="cb6-30" class="sourceLine" data-line-number="30"></a>      Stuff like the copyright, privacy, contact,
<a id="cb6-31" class="sourceLine" data-line-number="31"></a>      legal terms, small print, etc.
<a id="cb6-32" class="sourceLine" data-line-number="32"></a>  <span class="kw">&lt;/div&gt;</span>
<a id="cb6-33" class="sourceLine" data-line-number="33"></a><span class="kw">&lt;/body&gt;</span></code></pre>
</div>
<p>Using colourful visual styling, it looks something like this:</p>
<div style="background: turquoise; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;body&gt;</span></p>
<div style="background: yellow; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;div class=“main;”&gt;</span><br />
This acts as the outer container for all of the content.</p>
<div style="background: lightblue; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;div class=“header;”&gt;</span><br />
This section contains the common information found at the top of the every webpage.<br />
Stuff like the site name and logo.<br />
<span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<div style="background: orange; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;div class=“navigation;”&gt;</span><br />
This is the navigation bar. Sometimes is may be included in the “header”, other times it is on its own.<br />
If the navigation is common to all pages, then it should go inside the “header”.<br />
<span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<div style="background: lightgreen; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;div class=“content;”&gt;</span><br />
There are, typically, a lot of &lt;div&gt;s in this section and quite a lot of complicated structuring code.<br />
<span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<div style="background: pink; padding: 1em 1em;">
<span style="font-weight: bold;">&lt;div class=“footer;”&gt;</span><br />
This section contains the common information found at the bottom of the every webpage.<br />
Stuff like the copyright, privacy, contact, legal terms, small print, etc.<br />
<span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<p><span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<p><span style="font-weight: bold;">&lt;/div&gt;</span>
</div>
<p>By default it is a <strong>block</strong> element, although you can change this with the <span class="css-property">display</span> property. With dynamic pages (using JavaScript), you might toggle the property between <strong>none</strong> and <strong>block</strong> to hide / reveal content. There is no need to change it to <strong>inline</strong> or <strong>inline-block</strong> because that is what <span class="html-tag">span</span> is for.</p>
<h2 id="centering-blocks-using-margin-auto">Centering Blocks Using <span class="css-property">margin: auto;</span></h2>
<p>The easiest way to centre a block element is:</p>
<ul>
<li>give it a width and</li>
<li>set the <span class="css-property">margin</span> to <strong>auto</strong>.</li>
</ul>
<p>This will cause the User Agent (browser) to calculate appropriate margins for the HTML element.<br />
In general, the rules governing <strong>auto</strong> work like this:</p>
<ol type="1">
<li>For inline items, the calculated <strong>auto</strong> margin is always 0px.</li>
<li>For block items, the calculated top and bottom <strong>auto</strong> margin is always 0px.</li>
<li>For block items with a <span class="css-property">box-sizing</span> value of <span class="css-value">content-box</span> with a specified <span class="css-property">width</span>: if the total width of the <em>content + padding + border</em> is less than the width of the container it is in, then equal left and right margins will be applied. Otherwise the margins will be 0px.</li>
<li>For block items with a <span class="css-property">box-sizing</span> value of <span class="css-value">border-box</span> with a specified <span class="css-property">width</span>: if the total width of the element is less than the width of the container it is in, then equal left and right margins will be applied. Otherwise the margins will be 0px.</li>
</ol>
<p>It is most commonly written as:</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">.centre</span> {
<a id="cb7-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">auto</span>;
<a id="cb7-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>Some consider it better to use the 2 parameter version (the order is top and bottom, left and right):</p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb8-1" class="sourceLine" data-line-number="1"></a><span class="fu">.centre</span> {
<a id="cb8-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">0</span> <span class="dv">auto</span>;
<a id="cb8-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>You can also use it in the 4 parameter version (the order is top, right, bottom, left):</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">.centre</span> {
<a id="cb9-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">0</span> <span class="dv">auto</span> <span class="dv">0</span> <span class="dv">auto</span>;
<a id="cb9-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>You can always apply top and bottom margins &#8211; if you like.<br />
If a margin value is 0, it does not need the px suffix. This is true for all measurement units because: <strong>zero means zero.</strong><br />
Applying any of the above styles to a 200px by 200px <span class="html-tag">div</span> element (also styled with a green background), results in:</p>
<div style="background: green; width: 200px; height: 200px; margin: auto;"></div>
<p>Vertical centering is more difficult because HTML elements automatically expand vertically to accommodate content. So, technically, there is no vertical centre of a block element. In future tutorials, we will look at vertically centering content.</p>
<h2 id="summary">Summary</h2>
<ol type="1">
<li><span class="html-tag">span</span> is an <strong>inline</strong> HTML element you can use to style content without giving the content any semantic meaning.</li>
<li><span class="html-tag">div</span> is a <strong>block</strong> HTML element that is used to group together other elements. It has no semantic meaning.</li>
<li>When laying out your HTML document, you should use a <strong><span class="html-tag">div</span>ide and conquer</strong> approach.</li>
<li>Many HTML documents are <span class="html-tag">div</span>ided into <strong>header</strong>, <strong>navigation</strong>, <strong>content</strong>, and <strong>footer</strong> sections.</li>
<li>Applying the <span class="css-property">margin: auto</span> style to a block element will cause it to be horizontally centred inside whatever container it is located &#8211; provided it is smaller than the container.</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 />
Take the webpage you wrote in the previous exercise and revise it so it uses <span class="html-tag">div</span> elements to structure and contain the content. Also apply the <span class="css-property">margin: auto</span> style to the main container to centre the content. You should notice that when you resize the browser window, the document content remains centred (of course, if you make your browser window smaller than the content width it won’t remain centred).<br />
Knowing about the <span class="html-tag">span</span> element, create a few custom styles and apply it to parts of your document. Experiment with different font size, weights, style, colours, borders, etc.<br />
How would you create the following styles:</p>
<div style="background: white; border: 1px solid black; padding: 0.5em;">
Underline a <span style="border-bottom: 2px solid red;">mistake</span> in red?</p>
<p>Create a space for people to <span style="border-bottom:2px solid black;width:64px;display:inline-block;"> </span> in?</p>
</div>
<h2 id="references">References</h2>
<ul>
<li><a href="https://www.w3.org/TR/html50/text-level-semantics.html#the-span-element">span</a></li>
<li><a href="https://www.w3.org/TR/html50/grouping-content.html#the-div-element">div</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visudet.html#Computing_widths_and_margins">margin: auto</a></li>
</ul>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/example-page-where-the-content-is-not-flush-with-the-left-side">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-page-divided">Next</a>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">You may have noticed I wrote <strong>&amp;lt;p&amp;gt;</strong> as the content inside the <span class="html-tag">span</span>. This is because in HTML, the angle brackets &lt;&gt; are used to identify HTML tags. This means that any time one appears, it is considered to be part of an HTML tag. It can never appear as text or content. To get around this limitation, there are a number of special HTML codes that can be used replace them.All HTML codes begin with an ampersand (<strong>&amp;</strong>) and end with a semicolon (<strong>;</strong>). In between them is a short mnemonic. In this case <strong>lt</strong> and <strong>gt</strong> standing for <strong>less than</strong> and <strong>greater than</strong>.There are lots of codes, although most people only use a handful with <strong>&amp;lt;</strong> and <strong>&amp;gt;</strong> being the most common since they are they only way you can get the angle brackets to display in your content.You can see the whole list <a href="http://w3c.github.io/html/syntax.html#named-character-references">here</a>. Note, the font used for the table is absurdly small.Another common code is &amp; for ampersand (<strong>&amp;</strong>).<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">Don’t be shy about using the <span class="html-tag">div</span> element. As you will see, it is essential to <strong><span class="html-tag">div</span>ide and conquer!</strong><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/sectioning-using-html-and-auto-centering-content/">Sectioning Using HTML and Auto Centering Content</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Example Page Where the Content is not Flush with the Left Side</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/example-page-where-the-content-is-not-flush-with-the-left-side/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Fri, 27 Apr 2018 05:05:28 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3640</guid>

					<description><![CDATA[<p>Take your first step toward styling a page where the content is centred (sort of).</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/example-page-where-the-content-is-not-flush-with-the-left-side/">Example Page Where the Content is not Flush with the Left Side</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
There is no single right way to do the previous example webpage, so I will show you 3 different ways it could be done.
</div>
<p>At the end of the previous tutorial, you were asked to code a page using HTML5 and CSS3 to create a page that looks something like this:</p>
<div style="background: white; padding: 1em;">
<p style="margin: auto; width: 60%; padding: 1em; background: cornsilk; text-align: center;">Header / Title</p>
<p style="margin: auto; width: 60%; padding: 1em; background: aliceblue; text-align: left;">A whole bunch of content. You don’t need to go overboard. The goal is to practice and reinforce your knowledge, not get bored.</p>
<p style="margin: auto; width: 60%; padding: 1em; background: #FFF0F8; text-align: center;">Copyright / Footer</p>
</div>
<h2>Contents</h2>
<ol type="1">
<li><a href="#design-assumptions">Design Assumptions</a></li>
<li><a href="#method-1">Method 1</a>
<ol type="1">
<li><a href="#notes-1">Notes 1</a></li>
</ol>
</li>
<li><a href="#method-2">Method 2</a>
<ol type="1">
<li><a href="#notes-2">Notes 2</a></li>
</ol>
</li>
<li><a href="#method-3">Method 3</a>
<ol type="1">
<li><a href="#notes-3">Notes 3</a></li>
</ol>
</li>
</ol>
<h2 id="design-assumptions">Design Assumptions</h2>
<p>This page is not responsive<a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a> and is coded for a specific resolution:</p>
<ol type="1">
<li>The examples are coded for a screen resolution of 1366&#215;768 pixels.<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a>
<ul>
<li>If your browser window resolution is lower, the example content will appear right of centre. It may even be off the display and require scrolling to the right.</li>
<li>If your browser window resolution is higher, the example content will appear left of centre.</li>
<li>If your browser window resolution is 1366&#215;768, then the example content will appear centred.</li>
</ul>
</li>
<li>The content width is 566 pixels.<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a>
<ul>
<li>This leaves 800 pixels to be split between the left and right margin or 400px for the left and 400px for the right.</li>
</ul>
</li>
<li>The <span class="css-property">font-size</span> is set to 16px</li>
<li>The <span class="css-property">font-family</span> is <em>sans-serif</em>.</li>
</ol>
<h2 id="method-1">Method 1</h2>
<p>You can see this code in action <a href="https://complete-concrete-concise.com/sample/23-ex1.html">here</a>.</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="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>Web Page 1<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">32px</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">.centre</span> {
<a id="cb1-14" class="sourceLine" data-line-number="14"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb1-15" class="sourceLine" data-line-number="15"></a>      }
<a id="cb1-16" class="sourceLine" data-line-number="16"></a>
<a id="cb1-17" class="sourceLine" data-line-number="17"></a>      <span class="fu">.content</span> {
<a id="cb1-18" class="sourceLine" data-line-number="18"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;
<a id="cb1-19" class="sourceLine" data-line-number="19"></a>        <span class="kw">font-size</span>: <span class="dv">16px</span>;
<a id="cb1-20" class="sourceLine" data-line-number="20"></a>        <span class="kw">width</span>: <span class="dv">566px</span>;
<a id="cb1-21" class="sourceLine" data-line-number="21"></a>        <span class="kw">margin-left</span>: <span class="dv">400px</span>;
<a id="cb1-22" class="sourceLine" data-line-number="22"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<a id="cb1-23" class="sourceLine" data-line-number="23"></a>      }
<a id="cb1-24" class="sourceLine" data-line-number="24"></a>
<a id="cb1-25" class="sourceLine" data-line-number="25"></a>      <span class="pp">#footer</span> {
<a id="cb1-26" class="sourceLine" data-line-number="26"></a>        <span class="kw">color</span>: <span class="dv">blue</span>;
<a id="cb1-27" class="sourceLine" data-line-number="27"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb1-28" class="sourceLine" data-line-number="28"></a>        <span class="kw">padding</span>: <span class="dv">0px</span> <span class="dv">16px</span>;
<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="kw">&lt;/style&gt;</span>
<a id="cb1-32" class="sourceLine" data-line-number="32"></a>
<a id="cb1-33" class="sourceLine" data-line-number="33"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb1-34" class="sourceLine" data-line-number="34"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb1-35" class="sourceLine" data-line-number="35"></a>
<a id="cb1-36" class="sourceLine" data-line-number="36"></a>    <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"title"</span><span class="ot"> class=</span><span class="st">"centre content"</span><span class="kw">&gt;</span>Web Page Sample #1<span class="kw">&lt;/p&gt;</span>
<a id="cb1-37" class="sourceLine" data-line-number="37"></a>
<a id="cb1-38" class="sourceLine" data-line-number="38"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"content"</span><span class="kw">&gt;</span>
<a id="cb1-39" class="sourceLine" data-line-number="39"></a>      Quam stultum est aetatem disponere ne crastini
<a id="cb1-40" class="sourceLine" data-line-number="40"></a>      quidem dominum! o quanta dementia est spes
<a id="cb1-41" class="sourceLine" data-line-number="41"></a>      longas inchoantium: emam, aedificabo, credam,
<a id="cb1-42" class="sourceLine" data-line-number="42"></a>      exigam, honores geram, tum deinde lassam et
<a id="cb1-43" class="sourceLine" data-line-number="43"></a>      plenam senectutem in otium referam.
<a id="cb1-44" class="sourceLine" data-line-number="44"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb1-45" class="sourceLine" data-line-number="45"></a>    <span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">"content"</span><span class="kw">&gt;</span>Omnia, mihi crede, etiam
<a id="cb1-46" class="sourceLine" data-line-number="46"></a>      felicibus dubia sunt; nihil sibi quisquam de
<a id="cb1-47" class="sourceLine" data-line-number="47"></a>      futuro debet promittere; id quoque quod
<a id="cb1-48" class="sourceLine" data-line-number="48"></a>      tenetur per manus exit et ipsam quam premimus
<a id="cb1-49" class="sourceLine" data-line-number="49"></a>      horam casus incidit. Volvitur tempus rata
<a id="cb1-50" class="sourceLine" data-line-number="50"></a>      quidem lege, sed per obscurum: quid autem ad
<a id="cb1-51" class="sourceLine" data-line-number="51"></a>      me an naturae certum sit quod mihi incertumest?
<a id="cb1-52" class="sourceLine" data-line-number="52"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb1-53" class="sourceLine" data-line-number="53"></a>    <span class="kw">&lt;ol</span><span class="ot"> class=</span><span class="st">"content"</span><span class="kw">&gt;</span>
<a id="cb1-54" class="sourceLine" data-line-number="54"></a>      <span class="kw">&lt;li&gt;</span>Stat quidem terminusnobis ubi illum
<a id="cb1-55" class="sourceLine" data-line-number="55"></a>        inexorabilis fatorum necessitas fixit, sed
<a id="cb1-56" class="sourceLine" data-line-number="56"></a>        nemo scit nostrumquam prope versetur a
<a id="cb1-57" class="sourceLine" data-line-number="57"></a>        termino; sic itaque formemus animum tamquam
<a id="cb1-58" class="sourceLine" data-line-number="58"></a>        ad extremaventum sit.
<a id="cb1-59" class="sourceLine" data-line-number="59"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb1-60" class="sourceLine" data-line-number="60"></a>      <span class="kw">&lt;li&gt;</span>Nihil differamus; cotidie cum vita paria
<a id="cb1-61" class="sourceLine" data-line-number="61"></a>        faciamus.
<a id="cb1-62" class="sourceLine" data-line-number="62"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb1-63" class="sourceLine" data-line-number="63"></a>      <span class="kw">&lt;li&gt;</span>Maximum vitae vitium est quod inperfecta
<a id="cb1-64" class="sourceLine" data-line-number="64"></a>        semper est, quod [in] aliquid ex illa
<a id="cb1-65" class="sourceLine" data-line-number="65"></a>        differtur.
<a id="cb1-66" class="sourceLine" data-line-number="66"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb1-67" class="sourceLine" data-line-number="67"></a>      <span class="kw">&lt;/li&gt;</span>Qui cotidie vitae suae summam manum
<a id="cb1-68" class="sourceLine" data-line-number="68"></a>        inposuit non indiget tempore;ex hac autem
<a id="cb1-69" class="sourceLine" data-line-number="69"></a>        indigentia timor nascitur et cupiditas futuri
<a id="cb1-70" class="sourceLine" data-line-number="70"></a>        exedens animum. Nihil est miserius dubitatione
<a id="cb1-71" class="sourceLine" data-line-number="71"></a>        venientium quorsus evadant; quantum sit illud
<a id="cb1-72" class="sourceLine" data-line-number="72"></a>        quod restat aut quale sollicita mens
<a id="cb1-73" class="sourceLine" data-line-number="73"></a>        inexplicabili formidine agitatur.
<a id="cb1-74" class="sourceLine" data-line-number="74"></a>    <span class="kw">&lt;/li&gt;</span>
<a id="cb1-75" class="sourceLine" data-line-number="75"></a>  <span class="kw">&lt;/ol&gt;</span>
<a id="cb1-76" class="sourceLine" data-line-number="76"></a>  <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="ot"> class=</span><span class="st">"content centre "</span><span class="kw">&gt;</span>
<a id="cb1-77" class="sourceLine" data-line-number="77"></a>    Copyright 2018
<a id="cb1-78" class="sourceLine" data-line-number="78"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb1-79" class="sourceLine" data-line-number="79"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb1-80" class="sourceLine" data-line-number="80"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h3 id="notes-1">Notes 1</h3>
<ul>
<li>A <span class="css-class">.content</span> class was created to apply the necessary left margin and content width to each HTML element that needs to be in the “content zone” on the page.</li>
<li>While this works, it is a bit clunky because the class has to be applied to every single HTML element that goes in that content zone.</li>
<li>A <span class="css-class">.centre</span> class is applied to those elements needing centering. Centering is a special behaviour and should be handled on a case by case basis.</li>
<li>The header and footer were each given an ID. This makes sense, since there should only be one header and one footer per page.</li>
<li>The <span class="css-id">#header</span> and <span class="css-id">#footer</span> were given some individual styling.</li>
<li>Only a left margin was applied since the content normally aligns on the left side. Applying a margin of 400px shifted the content to the center.</li>
<li>The <span class="css-property">box-sizing</span> property was set to <strong>border-box</strong> because ordered lists have padding on the left side (this is where the numbers go), which would make the width of the <span class="html-tag">ol</span> element as wide as <em>width of the content + the width of any padding + the width of any border</em> &#8211; which means it would be wider than the specified 566px. Of course, the <span class="html-tag">ol</span> element could be styled to have a narrower content width to compensate for the internal padding.<a id="fnref4" class="footnote-ref" href="#fn4"><sup>4</sup></a></li>
</ul>
<h2 id="method-2">Method 2</h2>
<p>You can see this code in action <a href="https://complete-concrete-concise.com/sample/23-ex2.html">here</a>.</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>Web Page 2<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>
<a id="cb2-7" class="sourceLine" data-line-number="7"></a>    <span class="kw">&lt;style&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="pp">#title</span> {
<a id="cb2-10" class="sourceLine" data-line-number="10"></a>        <span class="kw">font-size</span>: <span class="dv">32px</span>;
<a id="cb2-11" class="sourceLine" data-line-number="11"></a>      }
<a id="cb2-12" class="sourceLine" data-line-number="12"></a>
<a id="cb2-13" class="sourceLine" data-line-number="13"></a>      <span class="fu">.centre</span> {
<a id="cb2-14" class="sourceLine" data-line-number="14"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb2-15" class="sourceLine" data-line-number="15"></a>      }
<a id="cb2-16" class="sourceLine" data-line-number="16"></a>
<a id="cb2-17" class="sourceLine" data-line-number="17"></a>      h1, p, ol {
<a id="cb2-18" class="sourceLine" data-line-number="18"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;
<a id="cb2-19" class="sourceLine" data-line-number="19"></a>        <span class="kw">font-size</span>: <span class="dv">16px</span>;
<a id="cb2-20" class="sourceLine" data-line-number="20"></a>        <span class="kw">width</span>: <span class="dv">566px</span>;
<a id="cb2-21" class="sourceLine" data-line-number="21"></a>        <span class="kw">margin-left</span>: <span class="dv">400px</span>;
<a id="cb2-22" class="sourceLine" data-line-number="22"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<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="pp">#footer</span> {
<a id="cb2-26" class="sourceLine" data-line-number="26"></a>        <span class="kw">color</span>: <span class="dv">blue</span>;
<a id="cb2-27" class="sourceLine" data-line-number="27"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb2-28" class="sourceLine" data-line-number="28"></a>        <span class="kw">padding</span>: <span class="dv">0px</span> <span class="dv">16px</span>;
<a id="cb2-29" class="sourceLine" data-line-number="29"></a>      }
<a id="cb2-30" class="sourceLine" data-line-number="30"></a>
<a id="cb2-31" class="sourceLine" data-line-number="31"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb2-32" class="sourceLine" data-line-number="32"></a>
<a id="cb2-33" class="sourceLine" data-line-number="33"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb2-34" class="sourceLine" data-line-number="34"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb2-35" class="sourceLine" data-line-number="35"></a>
<a id="cb2-36" class="sourceLine" data-line-number="36"></a>    <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"title"</span><span class="ot"> class=</span><span class="st">"centre "</span><span class="kw">&gt;</span>Web Page Sample #2<span class="kw">&lt;/p&gt;</span>
<a id="cb2-37" class="sourceLine" data-line-number="37"></a>
<a id="cb2-38" class="sourceLine" data-line-number="38"></a>    <span class="kw">&lt;p&gt;</span>
<a id="cb2-39" class="sourceLine" data-line-number="39"></a>      Quam stultum est aetatem disponere ne crastini
<a id="cb2-40" class="sourceLine" data-line-number="40"></a>      quidem dominum! o quanta dementia est spes
<a id="cb2-41" class="sourceLine" data-line-number="41"></a>      longas inchoantium: emam, aedificabo, credam,
<a id="cb2-42" class="sourceLine" data-line-number="42"></a>      exigam, honores geram, tum deinde lassam et
<a id="cb2-43" class="sourceLine" data-line-number="43"></a>      plenam senectutem in otium referam.
<a id="cb2-44" class="sourceLine" data-line-number="44"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb2-45" class="sourceLine" data-line-number="45"></a>    <span class="kw">&lt;p&gt;</span>Omnia, mihi crede, etiam
<a id="cb2-46" class="sourceLine" data-line-number="46"></a>      felicibus dubia sunt; nihil sibi quisquam de
<a id="cb2-47" class="sourceLine" data-line-number="47"></a>      futuro debet promittere; id quoque quod
<a id="cb2-48" class="sourceLine" data-line-number="48"></a>      tenetur per manus exit et ipsam quam premimus
<a id="cb2-49" class="sourceLine" data-line-number="49"></a>      horam casus incidit. Volvitur tempus rata
<a id="cb2-50" class="sourceLine" data-line-number="50"></a>      quidem lege, sed per obscurum: quid autem ad
<a id="cb2-51" class="sourceLine" data-line-number="51"></a>      me an naturae certum sit quod mihi incertumest?
<a id="cb2-52" class="sourceLine" data-line-number="52"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb2-53" class="sourceLine" data-line-number="53"></a>    <span class="kw">&lt;ol&gt;</span>
<a id="cb2-54" class="sourceLine" data-line-number="54"></a>      <span class="kw">&lt;li&gt;</span>Stat quidem terminusnobis ubi illum
<a id="cb2-55" class="sourceLine" data-line-number="55"></a>        inexorabilis fatorum necessitas fixit, sed
<a id="cb2-56" class="sourceLine" data-line-number="56"></a>        nemo scit nostrumquam prope versetur a
<a id="cb2-57" class="sourceLine" data-line-number="57"></a>        termino; sic itaque formemus animum tamquam
<a id="cb2-58" class="sourceLine" data-line-number="58"></a>        ad extremaventum sit.
<a id="cb2-59" class="sourceLine" data-line-number="59"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb2-60" class="sourceLine" data-line-number="60"></a>      <span class="kw">&lt;li&gt;</span>Nihil differamus; cotidie cum vita paria
<a id="cb2-61" class="sourceLine" data-line-number="61"></a>        faciamus.
<a id="cb2-62" class="sourceLine" data-line-number="62"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb2-63" class="sourceLine" data-line-number="63"></a>      <span class="kw">&lt;li&gt;</span>Maximum vitae vitium est quod inperfecta
<a id="cb2-64" class="sourceLine" data-line-number="64"></a>        semper est, quod [in] aliquid ex illa
<a id="cb2-65" class="sourceLine" data-line-number="65"></a>        differtur.
<a id="cb2-66" class="sourceLine" data-line-number="66"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb2-67" class="sourceLine" data-line-number="67"></a>      <span class="kw">&lt;/li&gt;</span>Qui cotidie vitae suae summam manum
<a id="cb2-68" class="sourceLine" data-line-number="68"></a>        inposuit non indiget tempore;ex hac autem
<a id="cb2-69" class="sourceLine" data-line-number="69"></a>        indigentia timor nascitur et cupiditas futuri
<a id="cb2-70" class="sourceLine" data-line-number="70"></a>        exedens animum. Nihil est miserius dubitatione
<a id="cb2-71" class="sourceLine" data-line-number="71"></a>        venientium quorsus evadant; quantum sit illud
<a id="cb2-72" class="sourceLine" data-line-number="72"></a>        quod restat aut quale sollicita mens
<a id="cb2-73" class="sourceLine" data-line-number="73"></a>        inexplicabili formidine agitatur.
<a id="cb2-74" class="sourceLine" data-line-number="74"></a>    <span class="kw">&lt;/li&gt;</span>
<a id="cb2-75" class="sourceLine" data-line-number="75"></a>  <span class="kw">&lt;/ol&gt;</span>
<a id="cb2-76" class="sourceLine" data-line-number="76"></a>  <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="ot"> class=</span><span class="st">"centre "</span><span class="kw">&gt;</span>
<a id="cb2-77" class="sourceLine" data-line-number="77"></a>    Copyright 2018
<a id="cb2-78" class="sourceLine" data-line-number="78"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb2-79" class="sourceLine" data-line-number="79"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb2-80" class="sourceLine" data-line-number="80"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h3 id="notes-2">Notes 2</h3>
<ul>
<li>This method avoids using a <span class="css-class">.content</span> class and directly styles the HTML styles elements so they have the necessary offset (<span class="css-property">margin-left</span>) and content width.</li>
<li>This saves applying a <span class="css-class">.content</span> class to every element.</li>
<li>It has the disadvantage that if you try to nest one of the styled elements inside another (for example, a <span class="html-tag">p</span> inside the <span class="html-tag">ol</span>), you would need to apply a class to clear the <span class="css-property">margin-left</span> property.</li>
<li>A <span class="css-class">.centre</span> class is applied to those elements needing centering. Centering is a special behaviour and should be handled on a case by case basis.</li>
<li>The header and footer were each given an ID. This makes sense, since there should only be one header and one footer per page.</li>
<li>The <span class="css-id">#header</span> and <span class="css-id">#footer</span> were given some individual styling.</li>
<li>Only a left margin was applied since the content normally aligns on the left side. Applying a margin of 400px shifted the content to the center.</li>
<li>The <span class="css-property">box-sizing</span> property was set to <strong>border-box</strong> because ordered lists have padding on the left side (this is where the numbers go), which would make the width of the <span class="html-tag">ol</span> element as wide as <em>width of the content + the width of any padding + the width of any border</em> &#8211; which means it would be wider than the specified 566px. Of course, the <span class="html-tag">ol</span> element could be styled to have a narrower content width to compensate for the internal padding.</li>
</ul>
<h2 id="method-3">Method 3</h2>
<p>You can see this code in action <a href="https://complete-concrete-concise.com/sample/23-ex3.html">here</a>.</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>Web Page 3<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>
<a id="cb3-7" class="sourceLine" data-line-number="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb3-8" class="sourceLine" data-line-number="8"></a>
<a id="cb3-9" class="sourceLine" data-line-number="9"></a>      body {
<a id="cb3-10" class="sourceLine" data-line-number="10"></a>        <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;
<a id="cb3-11" class="sourceLine" data-line-number="11"></a>        <span class="kw">font-size</span>: <span class="dv">16px</span>;
<a id="cb3-12" class="sourceLine" data-line-number="12"></a>        <span class="kw">width</span>: <span class="dv">566px</span>;
<a id="cb3-13" class="sourceLine" data-line-number="13"></a>        <span class="kw">margin-left</span>: <span class="dv">400px</span>;
<a id="cb3-14" class="sourceLine" data-line-number="14"></a>        <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;
<a id="cb3-15" class="sourceLine" data-line-number="15"></a>      }
<a id="cb3-16" class="sourceLine" data-line-number="16"></a>
<a id="cb3-17" class="sourceLine" data-line-number="17"></a>      <span class="pp">#title</span> {
<a id="cb3-18" class="sourceLine" data-line-number="18"></a>        <span class="kw">font-size</span>: <span class="dv">32px</span>;
<a id="cb3-19" class="sourceLine" data-line-number="19"></a>      }
<a id="cb3-20" class="sourceLine" data-line-number="20"></a>
<a id="cb3-21" class="sourceLine" data-line-number="21"></a>      <span class="fu">.centre</span> {
<a id="cb3-22" class="sourceLine" data-line-number="22"></a>        <span class="kw">text-align</span>: <span class="dv">center</span>;
<a id="cb3-23" class="sourceLine" data-line-number="23"></a>      }
<a id="cb3-24" class="sourceLine" data-line-number="24"></a>
<a id="cb3-25" class="sourceLine" data-line-number="25"></a>      <span class="pp">#footer</span> {
<a id="cb3-26" class="sourceLine" data-line-number="26"></a>        <span class="kw">color</span>: <span class="dv">blue</span>;
<a id="cb3-27" class="sourceLine" data-line-number="27"></a>        <span class="kw">font-size</span>: <span class="dv">24px</span>;
<a id="cb3-28" class="sourceLine" data-line-number="28"></a>        <span class="kw">padding</span>: <span class="dv">0px</span> <span class="dv">16px</span>;
<a id="cb3-29" class="sourceLine" data-line-number="29"></a>      }
<a id="cb3-30" class="sourceLine" data-line-number="30"></a>
<a id="cb3-31" class="sourceLine" data-line-number="31"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb3-32" class="sourceLine" data-line-number="32"></a>
<a id="cb3-33" class="sourceLine" data-line-number="33"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb3-34" class="sourceLine" data-line-number="34"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb3-35" class="sourceLine" data-line-number="35"></a>
<a id="cb3-36" class="sourceLine" data-line-number="36"></a>    <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"title"</span><span class="ot"> class=</span><span class="st">"centre "</span><span class="kw">&gt;</span>Web Page Sample #3<span class="kw">&lt;/p&gt;</span>
<a id="cb3-37" class="sourceLine" data-line-number="37"></a>
<a id="cb3-38" class="sourceLine" data-line-number="38"></a>    <span class="kw">&lt;p&gt;</span>
<a id="cb3-39" class="sourceLine" data-line-number="39"></a>      Quam stultum est aetatem disponere ne crastini
<a id="cb3-40" class="sourceLine" data-line-number="40"></a>      quidem dominum! o quanta dementia est spes
<a id="cb3-41" class="sourceLine" data-line-number="41"></a>      longas inchoantium: emam, aedificabo, credam,
<a id="cb3-42" class="sourceLine" data-line-number="42"></a>      exigam, honores geram, tum deinde lassam et
<a id="cb3-43" class="sourceLine" data-line-number="43"></a>      plenam senectutem in otium referam.
<a id="cb3-44" class="sourceLine" data-line-number="44"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb3-45" class="sourceLine" data-line-number="45"></a>    <span class="kw">&lt;p&gt;</span>Omnia, mihi crede, etiam
<a id="cb3-46" class="sourceLine" data-line-number="46"></a>      felicibus dubia sunt; nihil sibi quisquam de
<a id="cb3-47" class="sourceLine" data-line-number="47"></a>      futuro debet promittere; id quoque quod
<a id="cb3-48" class="sourceLine" data-line-number="48"></a>      tenetur per manus exit et ipsam quam premimus
<a id="cb3-49" class="sourceLine" data-line-number="49"></a>      horam casus incidit. Volvitur tempus rata
<a id="cb3-50" class="sourceLine" data-line-number="50"></a>      quidem lege, sed per obscurum: quid autem ad
<a id="cb3-51" class="sourceLine" data-line-number="51"></a>      me an naturae certum sit quod mihi incertumest?
<a id="cb3-52" class="sourceLine" data-line-number="52"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb3-53" class="sourceLine" data-line-number="53"></a>    <span class="kw">&lt;ol&gt;</span>
<a id="cb3-54" class="sourceLine" data-line-number="54"></a>      <span class="kw">&lt;li&gt;</span>Stat quidem terminusnobis ubi illum
<a id="cb3-55" class="sourceLine" data-line-number="55"></a>        inexorabilis fatorum necessitas fixit, sed
<a id="cb3-56" class="sourceLine" data-line-number="56"></a>        nemo scit nostrumquam prope versetur a
<a id="cb3-57" class="sourceLine" data-line-number="57"></a>        termino; sic itaque formemus animum tamquam
<a id="cb3-58" class="sourceLine" data-line-number="58"></a>        ad extremaventum sit.
<a id="cb3-59" class="sourceLine" data-line-number="59"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb3-60" class="sourceLine" data-line-number="60"></a>      <span class="kw">&lt;li&gt;</span>Nihil differamus; cotidie cum vita paria
<a id="cb3-61" class="sourceLine" data-line-number="61"></a>        faciamus.
<a id="cb3-62" class="sourceLine" data-line-number="62"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb3-63" class="sourceLine" data-line-number="63"></a>      <span class="kw">&lt;li&gt;</span>Maximum vitae vitium est quod inperfecta
<a id="cb3-64" class="sourceLine" data-line-number="64"></a>        semper est, quod [in] aliquid ex illa
<a id="cb3-65" class="sourceLine" data-line-number="65"></a>        differtur.
<a id="cb3-66" class="sourceLine" data-line-number="66"></a>      <span class="kw">&lt;/li&gt;</span>
<a id="cb3-67" class="sourceLine" data-line-number="67"></a>      <span class="kw">&lt;/li&gt;</span>Qui cotidie vitae suae summam manum
<a id="cb3-68" class="sourceLine" data-line-number="68"></a>        inposuit non indiget tempore;ex hac autem
<a id="cb3-69" class="sourceLine" data-line-number="69"></a>        indigentia timor nascitur et cupiditas futuri
<a id="cb3-70" class="sourceLine" data-line-number="70"></a>        exedens animum. Nihil est miserius dubitatione
<a id="cb3-71" class="sourceLine" data-line-number="71"></a>        venientium quorsus evadant; quantum sit illud
<a id="cb3-72" class="sourceLine" data-line-number="72"></a>        quod restat aut quale sollicita mens
<a id="cb3-73" class="sourceLine" data-line-number="73"></a>        inexplicabili formidine agitatur.
<a id="cb3-74" class="sourceLine" data-line-number="74"></a>    <span class="kw">&lt;/li&gt;</span>
<a id="cb3-75" class="sourceLine" data-line-number="75"></a>  <span class="kw">&lt;/ol&gt;</span>
<a id="cb3-76" class="sourceLine" data-line-number="76"></a>  <span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"footer"</span><span class="ot"> class=</span><span class="st">"centre "</span><span class="kw">&gt;</span>
<a id="cb3-77" class="sourceLine" data-line-number="77"></a>    Copyright 2018
<a id="cb3-78" class="sourceLine" data-line-number="78"></a>  <span class="kw">&lt;/p&gt;</span>
<a id="cb3-79" class="sourceLine" data-line-number="79"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb3-80" class="sourceLine" data-line-number="80"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h3 id="notes-3">Notes 3</h3>
<ul>
<li>This method styles the <span class="html-tag">body</span> element to have the appropriate left margin and necessary width.</li>
<li>Since the <span class="html-tag">body</span> element acts as a container for all the other elements, it is not necessary to style their width or left margin.</li>
<li>It avoids a lot of problems of the first two methods.</li>
<li>It is the preferred method of styling.<a id="fnref5" class="footnote-ref" href="#fn5"><sup>5</sup></a></li>
<li>A <span class="css-class">.centre</span> class is applied to those elements needing centering. Centering is a special behaviour and should be handled on a case by case basis.</li>
<li>The header and footer were each given an ID. This makes sense, since there should only be one header and one footer per page.</li>
<li>The <span class="css-id">#header</span> and <span class="css-id">#footer</span> were given some individual styling.</li>
<li>Only a left margin was applied since the content normally aligns on the left side. Applying a margin of 400px shifted the content to the center.</li>
<li>The <span class="css-property">box-sizing</span> property was set to <strong>border-box</strong> because I prefer to work with HTML element sizes rather than content sizes. Nevertheless, it wasn’t necessary. Unlike the previous two examples, the <span class="html-tag">ol</span> element would be constrained to the size of the <span class="html-tag">body</span> containing it.</li>
</ul>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/sectioning-using-html-and-auto-centering-content">Next</a>
</div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">A responsive page is one that adapts to different web browser sizes and resolutions. Thsi will be covered in future tutorials.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">As of April 2018, this is the most common screen resolution of visitors to this site (~30%). A future tutorial will show how to get the reported screen resolution and browser window size. Be warned, User-Agents (browsers) may lie, so it is bad programming to trust what the browser tells you.<a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">There is a lot fo debate as to what the optimal line length is. Guidelines recommend between 45 and 75 characters per line.<a class="footnote-back" href="#fnref3">↩</a></li>
<li id="fn4">Consider the following example, in which the <span class="html-tag">ol</span> tag is given a background colour of orange and the <span class="html-tag">li</span> tags are given a background colour of yellow. You can see the orange padding to the left of the list items. in the <strong>content-box</strong> model, the padding is not part of the width of the element. The padding is there so the numbers have a space to go:
<ol style="background: orange;">
<li style="background: yellow;">Item 1</li>
<li style="background: yellow;">Another item</li>
</ol>
<p><a class="footnote-back" href="#fnref4">↩</a></li>
<li id="fn5">While the <span class="html-tag">body</span> can be styled, usually it is not. The next tutorial will look at various HTML container elements that are used for layout.<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/example-page-where-the-content-is-not-flush-with-the-left-side/">Example Page Where the Content is not Flush with the Left Side</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Nine More CSS Properties to Play With</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Wed, 25 Apr 2018 10:56:13 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[box-sizing]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[font-family]]></category>
		<category><![CDATA[font-size]]></category>
		<category><![CDATA[font-style]]></category>
		<category><![CDATA[font-weight]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[line-height]]></category>
		<category><![CDATA[magin-top]]></category>
		<category><![CDATA[margin]]></category>
		<category><![CDATA[margin-bottom]]></category>
		<category><![CDATA[margin-left]]></category>
		<category><![CDATA[margin-right]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[padding-bottom]]></category>
		<category><![CDATA[padding-left]]></category>
		<category><![CDATA[padding-right]]></category>
		<category><![CDATA[padding-top]]></category>
		<category><![CDATA[text-align]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[width]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3627</guid>

					<description><![CDATA[<p>Expand your CSS styling vocabulary with 9 more properties and expand your knowledge of margin and padding.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/">Nine More CSS Properties 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">
<p>So far, we have restricted ourselves to a handful of CSS Properties as we familiarize ourselves with how CSS and the Box Model.</p>
<p>This tutorial expands your vocabulary with 9 new properties.</p>
</div>
<p>We’ve seen these 6 CSS properties:</p>
<ol type="1">
<li><span class="css-property">color</span></li>
<li><span class="css-property">background-color</span></li>
<li><span class="css-property">padding</span></li>
<li><span class="css-property">border</span></li>
<li><span class="css-property">margin</span></li>
<li><span class="css-property">display</span></li>
</ol>
<p>They allow you to play around with the text and background colours and the space around your content.</p>
<p>We’ll expand our knowledge of the <span class="css-property">margin</span> and <span class="css-property">padding</span> properties and add learn another 9 CSS properties to allow you to give a bit more style to your document.</p>
<p>As with the previous 6 properties, we won’t cover them all in full detail &#8211; just enough to so you can use them and become familiar with them. They will be covered in more detail in future tutorials.</p>
<h2>
Contents<br />
</h2>
<ol type="1">
<li><a href="#margin">margin</a>
<ol type="1">
<li><a href="#specific-margin-styling">Specific Margin Styling</a></li>
<li><a href="#styling-with-4-margin-values">Styling with 4 Margin Values</a></li>
<li><a href="#styling-with-2-margin-values">Styling with 2 Margin Values</a></li>
</ol>
</li>
<li><a href="#padding">padding</a>
<ol type="1">
<li><a href="#specific-padding-styling">Specific Padding Styling</a></li>
<li><a href="#styling-with-4-padding-values">Styling with 4 Padding Values</a></li>
<li><a href="#styling-with-2-padding-values">Styling with 2 Padding Values</a></li>
</ol>
</li>
<li><a href="#width">width</a>
<ol type="1">
<li><a href="#width-and-the-img-tag">width and the &lt;img&gt; tag</a></li>
</ol>
</li>
<li><a href="#height">height</a></li>
<li><a href="#box-sizing">box-sizing</a></li>
<li><a href="#font-size">font-size</a>
</li>
<li><a href="#font-family">font-family</a></li>
<li><a href="#font-weight">font-weight</a></li>
<li><a href="#font-style">font-style</a></li>
<li><a href="#line-height">line-height</a></li>
<li><a href="#text-align">text-align</a></li>
<li><a href="#conclusion">Conclusion</a></li>
<li><a href="#playing-around">Playing Around</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="margin">margin</h2>
<p>You have seen how to set all margins around an HTML <strong>element</strong> to the same value:</p>
<div class="sourceCode" id="cb1">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb1-1" data-line-number="1">p {</a>
<a class="sourceLine" id="cb1-2" data-line-number="2">  <span class="kw">margin</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb1-3" data-line-number="3">}</a></code></pre>
</div>
<p>The above code fragment will set all margins around the paragraph <strong>element</strong> to 16px.</p>
<p><strong>Remember</strong>: top and bottom margins are ignored for HTML elements with the <span class="css-property">display</span> property set to <strong>inline</strong>.</p>
<h3 id="specific-margin-styling">Specific Margin Styling</h3>
<p>You can choose which margin to style:</p>
<div class="sourceCode" id="cb2">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="fu">.left-margin</span> {</a>
<a class="sourceLine" id="cb2-2" data-line-number="2">  <span class="kw">margin-left</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb2-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb2-4" data-line-number="4"></a>
<a class="sourceLine" id="cb2-5" data-line-number="5"><span class="fu">.right-margin</span> {</a>
<a class="sourceLine" id="cb2-6" data-line-number="6">  <span class="kw">margin-right</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb2-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb2-8" data-line-number="8"></a>
<a class="sourceLine" id="cb2-9" data-line-number="9"><span class="fu">.top-margin</span> {</a>
<a class="sourceLine" id="cb2-10" data-line-number="10">  <span class="kw">margin-top</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb2-11" data-line-number="11">}</a>
<a class="sourceLine" id="cb2-12" data-line-number="12"></a>
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="fu">.bottom-margin</span> {</a>
<a class="sourceLine" id="cb2-14" data-line-number="14">  <span class="kw">margin-bottom</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb2-15" data-line-number="15">}</a></code></pre>
</div>
<p>Each class in the code fragment above applies a margin value to a specific side.</p>
<h3 id="styling-with-4-margin-values">Styling with 4 Margin Values</h3>
<p>You can individually style all four margin in a single line:</p>
<div class="sourceCode" id="cb3">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="fu">.custom-margins</span> {</a>
<a class="sourceLine" id="cb3-2" data-line-number="2">  <span class="kw">margin</span>: <span class="dv">8px</span> <span class="dv">10px</span> <span class="dv">4px</span> <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb3-3" data-line-number="3">}</a></code></pre>
</div>
<p>The margin values start at the top and are given in clockwise order:</p>
<ol type="1">
<li>top</li>
<li>right</li>
<li>bottom</li>
<li>left</li>
</ol>
<h3 id="styling-with-2-margin-values">Styling with 2 Margin Values</h3>
<p>If the top and bottom margins are the same and the left and right margins are the same, then you can style them in a single line:</p>
<div class="sourceCode" id="cb4">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="fu">.custom-margins</span> {</a>
<a class="sourceLine" id="cb4-2" data-line-number="2">  <span class="kw">margin</span>: <span class="dv">0px</span> <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb4-3" data-line-number="3">}</a></code></pre>
</div>
<p>The first value is the top and bottom margin value. The second value is the left and right margin value.</p>
<h2 id="padding">padding</h2>
<p>You have seen how to set all the padding around HTML <strong>content</strong> to the same value:</p>
<div class="sourceCode" id="cb5">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb5-1" data-line-number="1">p {</a>
<a class="sourceLine" id="cb5-2" data-line-number="2">  <span class="kw">padding</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb5-3" data-line-number="3">}</a></code></pre>
</div>
<p>The above code fragment will set all the padding around the paragraph <strong>content</strong> to 16px.</p>
<h3 id="specific-padding-styling">Specific Padding Styling</h3>
<p>You can choose which side to apply padding to:</p>
<div class="sourceCode" id="cb6">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="fu">.left-margin</span> {</a>
<a class="sourceLine" id="cb6-2" data-line-number="2">  <span class="kw">padding-left</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb6-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb6-4" data-line-number="4"></a>
<a class="sourceLine" id="cb6-5" data-line-number="5"><span class="fu">.right-margin</span> {</a>
<a class="sourceLine" id="cb6-6" data-line-number="6">  <span class="kw">padding-right</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb6-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb6-8" data-line-number="8"></a>
<a class="sourceLine" id="cb6-9" data-line-number="9"><span class="fu">.top-padding</span> {</a>
<a class="sourceLine" id="cb6-10" data-line-number="10">  <span class="kw">padding-top</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb6-11" data-line-number="11">}</a>
<a class="sourceLine" id="cb6-12" data-line-number="12"></a>
<a class="sourceLine" id="cb6-13" data-line-number="13"><span class="fu">.bottom-padding</span> {</a>
<a class="sourceLine" id="cb6-14" data-line-number="14">  <span class="kw">padding-bottom</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb6-15" data-line-number="15">}</a></code></pre>
</div>
<p>Each class in the code fragment above applies a padding value to a specific side.</p>
<h3 id="styling-with-4-padding-values">Styling with 4 Padding Values</h3>
<p>You can individually style all four padding values in a single line:</p>
<div class="sourceCode" id="cb7">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb7-1" data-line-number="1"><span class="fu">.custom-padding</span> {</a>
<a class="sourceLine" id="cb7-2" data-line-number="2">  <span class="kw">padding</span>: <span class="dv">8px</span> <span class="dv">10px</span> <span class="dv">4px</span> <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb7-3" data-line-number="3">}</a></code></pre>
</div>
<p>The padding values start at the top and are given in clockwise order:</p>
<ol type="1">
<li>top</li>
<li>right</li>
<li>bottom</li>
<li>left</li>
</ol>
<h3 id="styling-with-2-padding-values">Styling with 2 Padding Values</h3>
<p>If the top and bottom padding is the same and the left and right padding is the same, then you can style them in a single line:</p>
<div class="sourceCode" id="cb8">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb8-1" data-line-number="1"><span class="fu">.custom-padding</span> {</a>
<a class="sourceLine" id="cb8-2" data-line-number="2">  <span class="kw">padding</span>: <span class="dv">0px</span> <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb8-3" data-line-number="3">}</a></code></pre>
</div>
<p>This first value is the top and bottom padding value. The second value is the left and right padding value.</p>
<h2 id="width">width</h2>
<p>You’ve seen that block elements take up the full width of the container they are in. The <span class="css-property">width</span> allows you to control the width of the HTML content:</p>
<div class="sourceCode" id="cb9">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="fu">.width-test</span> {</a>
<a class="sourceLine" id="cb9-2" data-line-number="2">  <span class="kw">width</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb9-3" data-line-number="3">  <span class="kw">border</span>: <span class="dv">2px</span> <span class="dv">solid</span> <span class="dv">red</span>;</a>
<a class="sourceLine" id="cb9-4" data-line-number="4">  <span class="kw">background-color</span>:lightgray;</a>
<a class="sourceLine" id="cb9-5" data-line-number="5">}</a></code></pre>
</div>
<p>As with other CSS properties, you specify dimensions in pixels.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<p>Applying the above code fragment to the following HTML code:</p>
<div class="sourceCode" id="cb10">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb10-1" data-line-number="1"><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">&quot;width-test&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb10-2" data-line-number="2">  This is a 200 pixel wide test paragraph.</a>
<a class="sourceLine" id="cb10-3" data-line-number="3"><span class="kw">&lt;/p&gt;</span></a>
<a class="sourceLine" id="cb10-4" data-line-number="4"><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">&quot;width-test&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb10-5" data-line-number="5">  Another paragraph.</a>
<a class="sourceLine" id="cb10-6" data-line-number="6"><span class="kw">&lt;/p&gt;</span></a></code></pre>
</div>
<p>will result in something like the following:</p>
<p style="width:200px;border:2px solid red;background:lightgray;">
This is a 200 pixel wide test paragraph.
</p>
<p style="width:200px;border:2px solid red;background:lightgray;">
Another paragraph.
</p>
<p>Notice that the HTML element:</p>
<ul>
<li>no longer expands to fill the full width of the container</li>
<li>the block elements still follow normal HTML flow and stack one atop the other<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></li>
</ul>
<h3 id="width-and-the-img-tag">width and the &lt;img&gt; tag</h3>
<p>Setting the <span class="css-property">width</span> property on an <span class="html-tag">img</span> tag to <span class="css-value">100%</span>, will scale the image to fit the enclosing container<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a> without distorting the image.</p>
<div class="sourceCode" id="cb11">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb11-1" data-line-number="1">img {</a>
<a class="sourceLine" id="cb11-2" data-line-number="2">  <span class="kw">width</span>: <span class="dv">100%</span>;</a>
<a class="sourceLine" id="cb11-3" data-line-number="3">}</a></code></pre>
</div>
<p>Consider the following 400x400px image:</p>
<p><img loading="lazy" decoding="async" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min.jpg" alt="Labrador Retriever puppy sitting in grass." width="400" height="400" class="aligncenter size-full wp-image-3746" srcset="https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min.jpg 400w, https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min-150x150.jpg 150w, https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min-300x300.jpg 300w" sizes="auto, (max-width: 400px) 100vw, 400px" /></p>
<p>If we style the <span class="html-tag">img</span> tag to have a <span class="css-property">width</span> of <span class="css-value">100%</span>:</p>
<div class="sourceCode" id="cb12">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb12-1" data-line-number="1">img {</a>
<a class="sourceLine" id="cb12-2" data-line-number="2">  <span class="kw">width</span>: <span class="dv">100%</span>;</a>
<a class="sourceLine" id="cb12-3" data-line-number="3">}</a></code></pre>
</div>
<p>and insert the image inside smaller and larger containers:</p>
<div class="sourceCode" id="cb13">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb13-1" data-line-number="1"><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">&quot;small-container&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb13-2" data-line-number="2">  <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">&quot;image.jpg&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb13-3" data-line-number="3"><span class="kw">&lt;/div&gt;</span></a>
<a class="sourceLine" id="cb13-4" data-line-number="4"></a>
<a class="sourceLine" id="cb13-5" data-line-number="5"><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">&quot;large-container&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb13-6" data-line-number="6">  <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">&quot;image.jpg&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb13-7" data-line-number="7"><span class="kw">&lt;/div&gt;</span></a></code></pre>
</div>
<p>where:</p>
<div class="sourceCode" id="cb14">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb14-1" data-line-number="1"><span class="fu">.small-container</span> {</a>
<a class="sourceLine" id="cb14-2" data-line-number="2">  <span class="kw">width</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb14-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb14-4" data-line-number="4"></a>
<a class="sourceLine" id="cb14-5" data-line-number="5"><span class="fu">.large-container</span> {</a>
<a class="sourceLine" id="cb14-6" data-line-number="6">  <span class="kw">width</span>: <span class="dv">500px</span>;</a>
<a class="sourceLine" id="cb14-7" data-line-number="7">}</a></code></pre>
</div>
<p>We get the following results:</p>
<div class="html-output">
<p>
200px wide container:
</p>
<div style="width:200px;">
<img decoding="async" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min.jpg" alt="Labrador Retriever puppy sitting in grass."/>
</div>
<p>
500px wide container:
</p>
<div style="width:500px;">
<img decoding="async" style="width:100%;" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/22-img-width-400-min.jpg" alt="Labrador Retriever puppy sitting in grass."/>
</div>
</div>
<h2 id="height">height</h2>
<p>You’ve seen that HTML elements expand in height to fit whatever content they contain. Just as you can specify the width of the HTML element, you can also specify its height:</p>
<div class="sourceCode" id="cb15">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="fu">.height-test</span> {</a>
<a class="sourceLine" id="cb15-2" data-line-number="2">  <span class="kw">height</span>: <span class="dv">100px</span>;</a>
<a class="sourceLine" id="cb15-3" data-line-number="3">  <span class="kw">border</span>: <span class="dv">5px</span> <span class="dv">green</span> <span class="dv">solid</span>;</a>
<a class="sourceLine" id="cb15-4" data-line-number="4">  <span class="kw">background-color</span>: <span class="dv">yellow</span>;</a>
<a class="sourceLine" id="cb15-5" data-line-number="5">}</a></code></pre>
</div>
<p>As with many of the other CSS properties, you specify dimensions in pixels.</p>
<p>Applying the above code fragment to the following HTML code:</p>
<div class="sourceCode" id="cb16">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb16-1" data-line-number="1"><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">&quot;height-test&quot;</span><span class="kw">&gt;</span></a>
<a class="sourceLine" id="cb16-2" data-line-number="2">  This paragraph box is 100px high.</a>
<a class="sourceLine" id="cb16-3" data-line-number="3"><span class="kw">&lt;/p&gt;</span></a></code></pre>
</div>
<p>will result in something like the following:</p>
<p style="height:100px;border:5px solid green;background:yellow;">
This paragraph box is 100px high..
</p>
<p>Notice that the HTML element is now 200 pixels high, even though it doesn’t need to be.</p>
<p>You can combine the width and height:</p>
<div class="sourceCode" id="cb17">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb17-1" data-line-number="1"><span class="fu">.width-height-test</span> {</a>
<a class="sourceLine" id="cb17-2" data-line-number="2">  <span class="kw">width</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb17-3" data-line-number="3">  <span class="kw">height</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb17-4" data-line-number="4">  <span class="kw">border</span>: <span class="dv">2px</span> <span class="dv">solid</span> <span class="dv">black</span>;</a>
<a class="sourceLine" id="cb17-5" data-line-number="5">  <span class="kw">background</span>: <span class="dv">lime</span>;</a>
<a class="sourceLine" id="cb17-6" data-line-number="6">}</a></code></pre>
</div>
<p>Applying the above code fragment to:</p>
<div class="sourceCode" id="cb18">
<pre class="sourceCode html"><code class="sourceCode html"><a class="sourceLine" id="cb18-1" data-line-number="1"><span class="kw">&lt;p</span><span class="ot"> class=</span><span class="st">&quot;width-height-test&quot;</span><span class="kw">&gt;&lt;/p&gt;</span></a></code></pre>
</div>
<p>Results in:</p>
<p style="width:200px;height:200px;border:2px solid black;background:lime;">
<h2 id="box-sizing">box-sizing</h2>
<p>By default, the <span class="css-property">width</span> and <span class="css-property">height</span> set the dimensions of the <strong>content</strong> area of the CSS Box Model. Any padding or borders you add are extra on top of the width and height.</p>
<p>However, Microsoft’s Internet Explorer used what is commonly known as the <strong>broken box model</strong>. Internet Explorer considered the padding and borders as part of the width and height of the HTML element.</p>
<p>In both cases, margins are always extra on top of whatever width or height you set.</p>
<p>Consider the following two HTML paragraph elements:<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a></p>
<p style="box-sizing:content-box; border:5px solid black;padding:20px;width:200px;height:200px;background:lime;">
width = 200px, <br /> height = 200px, <br />border = 5px <br /> padding = 20px, <br />Content sizing
</p>
<p style="box-sizing:border-box; border:5px solid black;padding:20px;width:200px;height:200px;background:yellow;">
width = 200px, <br /> height = 200px, <br /> border = 5px, <br /> padding = 20px, <br />Border sizing
</p>
<p>Both have exactly the same settings for:</p>
<ul>
<li>width</li>
<li>height</li>
<li>padding</li>
<li>border</li>
</ul>
<p>The green element is sized using the standard model which applies the width and height only to the content of the CSS Box. The padding and borders add extra width and height to the element.</p>
<p>The yellow element is sized using Internet Explorer’s <strong>broken box model</strong> which applies the width and height to the borders of the CSS Box. All padding and content is contained within that.</p>
<p>You can choose which model you want to use:</p>
<ul>
<li><strong>content-box</strong> &#8211; this is the default behaviour and can be considered to put the content “first” since it sizes the space for the content. However, it can make for more difficult layouts because changing the padding or border changes the size of the element on the page.</li>
<li><strong>border-box</strong> &#8211; this can be considered to put the layout “first” since it sizes the space for the entire HTML element (content + padding + border).</li>
</ul>
<p>Regardless of which box sizing method you choose, margins always add extra space.</p>
<p>Normally, you don’t set this property on an element by element basis, but for all elements in the document:</p>
<div class="sourceCode" id="cb20">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb20-1" data-line-number="1">* {</a>
<a class="sourceLine" id="cb20-2" data-line-number="2">  <span class="kw">box-sizing</span>: <span class="dv">border-box</span>;</a>
<a class="sourceLine" id="cb20-3" data-line-number="3">}</a></code></pre>
</div>
<p>The above code fragment will change the <span class="css-property">box-sizing</span> to <strong>border-box</strong> for all elements in the document. This is a typical use for the <strong>Universal</strong> selector.</p>
<p>This might seem somewhat pointless since the only layout flow you know is top to bottom (and nesting elements inside other elements). However, in a future tutorial, you will see how to change the normal <em>top to bottom</em> HTML flow so that HTML elements flow from <em>left to right</em> or <em>right to left</em>.</p>
<h2 id="font-size">font-size</h2>
<p>Fonts are graphical representations of characters that are (usually) used for text.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a></p>
<p>In general, the default font size in a browser is set to 16 pixels.<a href="#fn6" class="footnote-ref" id="fnref6"><sup>6</sup></a></p>
<p>You can change the size using the CSS property <span class="css-property">font-size</span>:</p>
<div class="sourceCode" id="cb21">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb21-1" data-line-number="1"><span class="fu">.large-font</span> {</a>
<a class="sourceLine" id="cb21-2" data-line-number="2">  <span class="kw">font-size</span>: <span class="dv">32px</span>;</a>
<a class="sourceLine" id="cb21-3" data-line-number="3">}</a></code></pre>
</div>
<p>The size is given in pixels.<a href="#fn7" class="footnote-ref" id="fnref7"><sup>7</sup></a></p>
<p style="font-size:32px; border:2px solid black;background:yellow;padding:0.5em; line-height:40px">
A sample paragraph with the font size set to 32px (and some other styling for background color and border).
</p>
<h2 id="font-family">font-family</h2>
<p>You can specify which font should be used. For this tutorial we only cover the 3 major font families:</p>
<ul>
<li><strong>serif</strong>: <span style="font-family:serif;">serif fonts have small strokes attached to the tips of each letter. <strong>Time New Roman</strong> is an example of a serif font.</span></li>
<li><strong>sans-serif</strong>: <span style="font-family:sans-serif;">sans-serif fonts do not have the extra strokes attached to each letter. <strong>Verdana</strong> or <strong>Arial</strong> are examples of san-serif fonts.</span></li>
<li><strong>monospace</strong>: <span style="font-family:monospace;">monospace fonts have characters that are all the same width. They may be serif or sans-serif. <strong>Courier New</strong> is an example of a monospace font.</span></li>
</ul>
<p>You can change the font family (the style of the font) using the <span class="css-property">font-family</span> property:</p>
<div class="sourceCode" id="cb22">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb22-1" data-line-number="1"><span class="fu">.serif</span> {</a>
<a class="sourceLine" id="cb22-2" data-line-number="2">  <span class="kw">font-family</span>: <span class="dv">serif</span>;</a>
<a class="sourceLine" id="cb22-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb22-4" data-line-number="4"></a>
<a class="sourceLine" id="cb22-5" data-line-number="5"><span class="fu">.sans</span> {</a>
<a class="sourceLine" id="cb22-6" data-line-number="6">  <span class="kw">font-family</span>: <span class="dv">sans-serif</span>;</a>
<a class="sourceLine" id="cb22-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb22-8" data-line-number="8"></a>
<a class="sourceLine" id="cb22-9" data-line-number="9"><span class="fu">.mono</span> {</a>
<a class="sourceLine" id="cb22-10" data-line-number="10">  <span class="kw">font-family</span>: <span class="dv">monospace</span>;</a>
<a class="sourceLine" id="cb22-11" data-line-number="11">}</a></code></pre>
</div>
<p>The above code fragment defines 3 different classes that can be used to change the font family.</p>
<p>In a future tutorial, we will see how to specify a specific font (like Arial or Times New Roman).<a href="#fn8" class="footnote-ref" id="fnref8"><sup>8</sup></a></p>
<h2 id="font-weight">font-weight</h2>
<p>Most fonts come in two weights: normal and bold. There can be more,<a href="#fn9" class="footnote-ref" id="fnref9"><sup>9</sup></a> but, for now, we only consider those two because those are the two most common font weights. Very few fonts have more than those two weights &#8211; sometimes they only have one weight.</p>
<p>You style it using the <span class="css-property">font-weight</span> property:</p>
<div class="sourceCode" id="cb23">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb23-1" data-line-number="1"><span class="fu">.bold-font</span> {</a>
<a class="sourceLine" id="cb23-2" data-line-number="2">  <span class="kw">font-weight</span>: <span class="dv">bold</span>;</a>
<a class="sourceLine" id="cb23-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb23-4" data-line-number="4"></a>
<a class="sourceLine" id="cb23-5" data-line-number="5"><span class="fu">.normal-font</span> {</a>
<a class="sourceLine" id="cb23-6" data-line-number="6">  <span class="kw">font-weight</span>: <span class="dv">normal</span>;</a>
<a class="sourceLine" id="cb23-7" data-line-number="7">}</a></code></pre>
</div>
<p>The above code fragment implements two classes that allow setting the font weight for an HTML element.</p>
<p>Applied to paragraph tags (with a bit of extra styling), the result looks like this:</p>
<p style="background:yellow;font-weight:normal">
This is some normal text.
</p>
<p style="background:yellow;font-weight:bold">
This is some bold text.
</p>
<h2 id="font-style">font-style</h2>
<p>Fonts have 3 different styles:</p>
<ul>
<li><strong>normal</strong>: this is the normal font</li>
<li><strong>italic</strong>: this is distinct from the normal font. It is typically designed to have an inclined appearance and calligraphic (handwritten) feel to it</li>
<li><strong>oblique</strong>: this is the normal font that has been tilted (typically about 10°) to the right.</li>
</ul>
<p>In practice, italic and oblique are pretty much synonymous<a href="#fn10" class="footnote-ref" id="fnref10"><sup>10</sup></a>.</p>
<div class="sourceCode" id="cb24">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb24-1" data-line-number="1"><span class="fu">.normal-style</span> {</a>
<a class="sourceLine" id="cb24-2" data-line-number="2">  <span class="kw">font-style</span>: <span class="dv">normal</span>;</a>
<a class="sourceLine" id="cb24-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb24-4" data-line-number="4"></a>
<a class="sourceLine" id="cb24-5" data-line-number="5"><span class="fu">.italic-style</span> {</a>
<a class="sourceLine" id="cb24-6" data-line-number="6">  <span class="kw">font-style</span>: <span class="dv">italic</span>;</a>
<a class="sourceLine" id="cb24-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb24-8" data-line-number="8"></a>
<a class="sourceLine" id="cb24-9" data-line-number="9"><span class="fu">.oblique-style</span> {</a>
<a class="sourceLine" id="cb24-10" data-line-number="10">  <span class="kw">font-style</span>: <span class="dv">oblique</span>;</a>
<a class="sourceLine" id="cb24-11" data-line-number="11">}</a></code></pre>
</div>
<p>Applied to paragraph tags (with a bit of extra styling), the result looks something like this:</p>
<p style="background:yellow;font-style:normal; font-family:serif; font-size:2em;padding:0.5em;">
This is some normal text.
</p>
<p style="background:yellow;font-style:oblique; font-family:serif; font-size:2em;;padding:0.5em;">
This is some oblique text.
</p>
<p style="background:yellow;font-style:italic; font-family:serif; font-size:2em;;padding:0.5em;">
This is some italic text.
</p>
<p>If your browser’s default serif font has italics, you will notice a difference between the oblique and italic text. You will see that the oblique is simply the normal skewed to the right.</p>
<h2 id="line-height">line-height</h2>
<p>You can also adjust the height of your lines using the <span class="css-property">line-height</span> property.</p>
<p>Single space lines would have the same height as the <span class="css-property">font-size</span>:</p>
<div class="sourceCode" id="cb25">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb25-1" data-line-number="1"><span class="fu">.single</span> {</a>
<a class="sourceLine" id="cb25-2" data-line-number="2">  <span class="kw">font-size</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb25-3" data-line-number="3">  <span class="kw">line-height</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb25-4" data-line-number="4">}</a>
<a class="sourceLine" id="cb25-5" data-line-number="5"></a>
<a class="sourceLine" id="cb25-6" data-line-number="6"><span class="fu">.double</span> {</a>
<a class="sourceLine" id="cb25-7" data-line-number="7">  <span class="kw">font-size</span>: <span class="dv">16px</span>;</a>
<a class="sourceLine" id="cb25-8" data-line-number="8">  <span class="kw">line-height</span>: <span class="dv">32px</span>;</a>
<a class="sourceLine" id="cb25-9" data-line-number="9">}</a></code></pre>
</div>
<p>The above code fragment applied to the following paragraphs results in something like this:</p>
<p style="line-height:1em; border:2px solid black;background:yellow;">
This paragraph has been styled to use a line-height equal to the font size. This makes the text “single spaced”. Depending on the font used, it can appear too dense. Normally, you would use a line height around 1.5 times the font size.
</p>
<p style="line-height:2em; border:2px solid black;background:yellow;">
This paragraph has been styled to use a line-height equal to double the font size. This makes the text “double spaced”. Depending on the font used, it can appear too sparse. Normally, you would use a line height around 1.5 times the font size.
</p>
<p style="line-height:1.5em; border:2px solid black;background:yellow;">
This paragraph has been styled to use a line-height equal to 1.5 times the font size. This makes the text. This is, typically, a good line spacing to use. Normally, you would use a line height around 1.5 times the font size.
</p>
<h2 id="text-align">text-align</h2>
<p>You can set your text alignment:</p>
<ul>
<li><strong>right</strong>: the text is right justified. This means the text lines up on the right side of the HTML element</li>
<li><strong>left</strong>: the text is left justified. This means the text lines up on the left side of the HTML element</li>
<li><strong>center</strong>: the text is horizontally centered inside the HTML element.</li>
<li><strong>justify</strong>: the text is fully justified. This means the text lines up on both the left and right side of the HTML element. White space is inserted as needed to justify the text.</li>
</ul>
<div class="sourceCode" id="cb26">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb26-1" data-line-number="1"><span class="fu">.right-align</span> {</a>
<a class="sourceLine" id="cb26-2" data-line-number="2">  <span class="kw">text-align</span>: <span class="dv">right</span>;</a>
<a class="sourceLine" id="cb26-3" data-line-number="3">}</a>
<a class="sourceLine" id="cb26-4" data-line-number="4"></a>
<a class="sourceLine" id="cb26-5" data-line-number="5"><span class="fu">.left-align</span> {</a>
<a class="sourceLine" id="cb26-6" data-line-number="6">  <span class="kw">text-align</span>: <span class="dv">left</span>;</a>
<a class="sourceLine" id="cb26-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb26-8" data-line-number="8"></a>
<a class="sourceLine" id="cb26-9" data-line-number="9"><span class="fu">.center-align</span> {</a>
<a class="sourceLine" id="cb26-10" data-line-number="10">  <span class="kw">text-align</span>: <span class="dv">center</span>;</a>
<a class="sourceLine" id="cb26-11" data-line-number="11">}</a>
<a class="sourceLine" id="cb26-12" data-line-number="12"></a>
<a class="sourceLine" id="cb26-13" data-line-number="13"><span class="fu">.justified-align</span> {</a>
<a class="sourceLine" id="cb26-14" data-line-number="14">  <span class="kw">text-align</span>: <span class="dv">justify</span>;</a>
<a class="sourceLine" id="cb26-15" data-line-number="15">}</a></code></pre>
</div>
<p>The code fragment above applied to the following paragraphs results in something like:</p>
<p style="text-align:right; border:2px solid black;background:yellow">
This paragraph is right aligned. The text lines up on the right side of the HTML element. The left side can be ragged.
</p>
<p style="text-align:left; border:2px solid black;background:yellow;">
This paragraph is left aligned. This means the text lines up on the left side of the HTML element. The right side can be ragged.
</p>
<p style="text-align:center; border:2px solid black;background:yellow;">
This paragraph is centered. This means the text horizontally centers itself inside the HTML element. The left and right sides can be ragged.
</p>
<p style="text-align:justify; border:2px solid black;background:yellow;">
This paragraph is justified. This means the text lines up on both the left and the right side of the HTML element. The left and right side will not be ragged except, possibly, the right side of the last line.
</p>
<h2 id="conclusion">Conclusion</h2>
<p>We covered quite a lot of stuff &#8211; but don’t worry, there is still plenty more.</p>
<ol type="1">
<li>There are multiple ways to style margins around HTML <strong>elements</strong>:
<ol type="1">
<li>Setting all margins to the same value by providing a single value to the <span class="css-property">margin</span> property</li>
<li>Setting each margin individually using the <span class="css-property">margin-left</span>, <span class="css-property">margin-right</span>, <span class="css-property">margin-top</span>, <span class="css-property">margin-bottom</span> properties.</li>
<li>Setting all margin values individually in a single line by providing 4 values to the <span class="css-property">margin</span> property. The margin values are given in clockwise order starting from the top: top, right, bottom, left.</li>
</ol>
</li>
<li>Remember that top and bottom margins are ignored for inline elements.</li>
<li>There are multiple ways to style padding around HTML <strong>content</strong>:
<ol type="1">
<li>Setting all padding to the same value by providing a single value to the <span class="css-property">padding</span> property</li>
<li>Setting each padding value individually using the <span class="css-property">padding-left</span>, <span class="css-property">padding-right</span>, <span class="css-property">padding-top</span>, <span class="css-property">padding-bottom</span> properties.</li>
<li>Setting all padding values individually in a single line by providing 4 values to the <span class="css-property">padding</span> property. The padding values are given in clockwise order starting from the top: top, right, bottom, left.</li>
</ol>
</li>
<li>The <span class="css-property">width</span> property allows you set the width of an HTML element. The width is given in pixels.</li>
<li>The <span class="css-property">height</span> property allows you set the height of an HTML element. The height is given in pixels.</li>
<li>By default, the width and height is applied to the <strong>content</strong> of the HTML element.</li>
<li>If you want the width and height to apply to the entire HTML element, including <strong>content</strong>, <strong>padding</strong>, and <strong>margins</strong>, then you set the <span class="css-property">box-sizing</span> property to <em>border-box</em>.</li>
<li>The <span class="css-property">font-size</span> property allows you set the size of the font inside an HTML element. The size is given in pixels.</li>
<li>In general, the default font size is 16px.</li>
<li>The <span class="css-property">font-family</span> property allows you set the type of font used inside an HTML element. The 3 main font types are:
<ul>
<li>serif (<span style="font-family:serif">Serif Example</span>)</li>
<li>sans-serif (<span style="font-family:sans-serif">San Serif Example</span>)</li>
<li>monospace (<span style="font-family:monospace">Monospace Example</span>)</li>
</ul>
</li>
<li>The <span class="css-property">font-weight</span> property allows you set the weight of the font inside an HTML element. The common weights are:
<ul>
<li>normal (<span style="font-weight:normal">Normal Example</span>)</li>
<li>bold (<span style="font-weight:bold">Bold Example</span>)</li>
</ul>
</li>
<li>The <span class="css-property">font-style</span> property allows you set the style of the font inside an HTML element. The 3 styles are:
<ul>
<li>normal (<span style="font-style:normal">Normal Example</span>)</li>
<li>oblique (<span style="font-style:oblique">Oblique Example</span>)</li>
<li>italic (<span style="font-style:italic">Italic Example</span>)</li>
</ul>
</li>
<li>Italic and oblique are very similar. User agents (browsers) commonly substitute oblique for italic if an italic version of the font is not available.</li>
<li>The <span class="css-property">line-height</span> property allows you set the height of the line inside an HTML element. The height is given in pixels.</li>
<li>Typical line heights are 1.5 times the font-size.</li>
<li>The <span class="css-property">text-align</span> property allows you specify how text is to be aligned inside an HTML element. The 4 alignment values are:
<ul>
<li>left</li>
<li>right</li>
<li>center</li>
<li>justify</li>
</ul>
</li>
</ol>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.</p>
<p>You have enough knowledge now to create the following style of webpage:</p>
<div style="background:white;padding:1em;">
<p style="margin:auto;width:60%;padding:1em;background:cornsilk;text-align:center;">
Header / Title
</p>
<p style="margin:auto;width:60%;padding:1em;background:aliceblue;text-align:left;">
A whole bunch of content. You don’t need to go overboard. The goal is to practice and reinforce your knowledge, not get bored.
</p>
<p style="margin:auto;width:60%;padding:1em;background:#FFF0F8;text-align:center;">
Copyright / Footer
</p>
</div>
<p>There are a number of ways to do this (I will show 3 in the next tutorial).</p>
<ol type="1">
<li>Don’t try to get the document looking good at all kinds of resolutions. Just make it look good in your browser at whatever resolution you are using. Future tutorials will get into how to make your site <strong>responsive</strong>.</li>
<li>What do you need to do to get a uniform margin on the left-hand side?</li>
<li>How are you going to control the width of the content in the center?</li>
<li>Don’t worry about background colours (I just used them in the example to highlight the task)</li>
<li>You don’t have to use all the HTML elements and CSS properties you have seen.</li>
<li>You want the content (roughly) in the center of the page.</li>
<li>The content width should be constrained.</li>
<li>The title should be centered.</li>
<li>The copyright should be centered.</li>
</ol>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://drafts.csswg.org/css-box-3/#margin-props">margin</a></li>
<li><a href="https://drafts.csswg.org/css-box-3/#padding-props">padding</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visudet.html#the-width-property">width</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">height</a></li>
<li><a href="https://drafts.csswg.org/css-ui-3/#box-sizing">box-sizing</a></li>
<li><a href="https://www.w3.org/TR/CSS2/fonts.html#propdef-font-size">font-size</a></li>
<li><a href="https://www.w3.org/TR/CSS2/fonts.html#propdef-font-family">font-family</a></li>
<li><a href="https://www.w3.org/TR/CSS2/fonts.html#propdef-font-weight">font-weight</a></li>
<li><a href="https://www.w3.org/TR/CSS2/fonts.html#propdef-font-style">font-style</a></li>
<li><a href="https://www.w3.org/TR/CSS2/visudet.html#propdef-line-height">line-height</a></li>
<li><a href="https://www.w3.org/TR/CSS2/text.html#alignment-prop">text-align</a></li>
</ol>
<div class="prev">
<p><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/five-examples-using-css-selectors">Prev</a></p>
</div>
<div class="next">
<p><a href="#">Next</a></p>
</div>
<div class="clear">
</div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">
<p>There are numerous ways to specify dimensions in CSS. For now, we will stick with pixels. Future tutorials will cover other dimensions.<a href="#fnref1" class="footnote-back">↩</a></p>
</li>
<li id="fn2">
<p>Getting HTML elements to flow one after the other, instead of one atop the other, will be covered in a future tutorial.<a href="#fnref2" class="footnote-back">↩</a></p>
</li>
<li id="fn3">
<p>It is a little more complicated: you also need to set the <span class="css-property">height</span> to <span class="css-value">auto</span>. Because this is the default value, there is no need to explicitly set it to <span class="css-value">auto</span>.<a href="#fnref3" class="footnote-back">↩</a></p>
</li>
<li id="fn4">
<p>The CSS used for this example is:</p>
<div class="sourceCode" id="cb19">
<pre class="sourceCode css"><code class="sourceCode css"><a class="sourceLine" id="cb19-1" data-line-number="1"><span class="fu">.content-box</span> {</a>
<a class="sourceLine" id="cb19-2" data-line-number="2">  <span class="kw">box-sizing</span>: <span class="dv">content-box</span>;</a>
<a class="sourceLine" id="cb19-3" data-line-number="3">  <span class="kw">border</span>: <span class="dv">5px</span> <span class="dv">solid</span> <span class="dv">black</span>;</a>
<a class="sourceLine" id="cb19-4" data-line-number="4">  <span class="kw">padding</span>: <span class="dv">20px</span>;<span class="kw">width</span>:<span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb19-5" data-line-number="5">  <span class="kw">height</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb19-6" data-line-number="6">  <span class="kw">background</span>: <span class="dv">lime</span>;</a>
<a class="sourceLine" id="cb19-7" data-line-number="7">}</a>
<a class="sourceLine" id="cb19-8" data-line-number="8"></a>
<a class="sourceLine" id="cb19-9" data-line-number="9"><span class="fu">.border-box</span> {</a>
<a class="sourceLine" id="cb19-10" data-line-number="10">  <span class="kw">box-sizing</span>:<span class="dv">border-box</span>;</a>
<a class="sourceLine" id="cb19-11" data-line-number="11">  <span class="kw">border</span>: <span class="dv">5px</span> <span class="dv">solid</span> <span class="dv">black</span>;</a>
<a class="sourceLine" id="cb19-12" data-line-number="12">  <span class="kw">padding</span>: <span class="dv">20px</span>;</a>
<a class="sourceLine" id="cb19-13" data-line-number="13">  <span class="kw">width</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb19-14" data-line-number="14">  <span class="kw">height</span>: <span class="dv">200px</span>;</a>
<a class="sourceLine" id="cb19-15" data-line-number="15">  <span class="kw">background</span>: <span class="dv">yellow</span>;</a>
<a class="sourceLine" id="cb19-16" data-line-number="16">}</a></code></pre>
</div>
<p><a href="#fnref4" class="footnote-back">↩</a></li>
<li id="fn5">
<p>There are fonts that are just pure graphics / symbols / icons. <a href="https://fontawesome.com/">Fontawesome</a> is one such font library. We will look at it in a future tutorial.<a href="#fnref5" class="footnote-back">↩</a></p>
</li>
<li id="fn6">
<p>Most browsers let the user to change the default font (or text) size. Unfortunately, most websites do not respect this. This website does. If you go to your browser settings and change the text size, you will find this site adjusts accordingly. Go to pretty much any other website and you will find they ignore the user’s preferred font size settings.<a href="#fnref6" class="footnote-back">↩</a></p>
</li>
<li id="fn7">
<p>This will hard code the size of the font. In a future tutorial, we will see how to set the font size so it respects the users text size setting in the browser.<a href="#fnref7" class="footnote-back">↩</a></p>
</li>
<li id="fn8">
<p>Specifying a specific font is simple &#8211; just write its name. However, all things considered, it is a little more complicated. It is better to first learn the core principles before adding more complexity.<a href="#fnref8" class="footnote-back">↩</a></p>
</li>
<li id="fn9">
<p>This will be discussed more in a future tutorial.<a href="#fnref9" class="footnote-back">↩</a></p>
</li>
<li id="fn10">
<p>They’re not. An italic font is specially designed. An oblique font is simply the normal font skewed to the right.<a href="#fnref10" class="footnote-back">↩</a></p>
</li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/nine-more-css-properties-to-play-with/">Nine More CSS Properties to Play With</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
