 
    
<?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>div Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/div/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/div/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Mon, 30 Apr 2018 04:45:00 +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>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>
	</channel>
</rss>
