 
    
<?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>border Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/border/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/border/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Mon, 16 Apr 2018 04:41:46 +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>Introducing HTML Flow and the CSS Box Model</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/introducing-html-flow-and-the-css-box-model/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 16 Apr 2018 04:41:46 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[box model]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[margin]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3577</guid>

					<description><![CDATA[<p>Knowing how HTML flows on the page and how CSS models HTML elements as boxes is essential to mastering front-end development.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/introducing-html-flow-and-the-css-box-model/">Introducing HTML Flow and the CSS Box Model</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">
Knowing how HTML flows on the page and how CSS models HTML elements as boxes is essential to mastering front-end development.
</div>
<p>You probably didn’t think much about what was happening with your content when you were coding plain HTML documents. You may have wished you could have given then some pizazz, but they looked as you coded them.<br />
Some styling &#8211; just background colour and text colour &#8211; was introduced in the <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/introducing-css">previous tutorial</a> and if you played around with it, you may have noticed some interesting behaviour.<br />
My <a href="https://complete-concrete-concise.com/sample/14-css.html">example page</a> looks like this:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-html-flow-css-box-64-1.png"><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-3588" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-html-flow-css-box-64-1.png" alt="Colourful HTML page" width="554" height="492" /></a><br />
Aside from being garish looking, it hints at the behaviour of HTML and CSS.<br />
You can style any HTML element. However, it doesn’t make sense to style elements which are not displayed. Styling the <span class="html-tag">head</span>, <span class="html-tag">title</span>, <span class="html-tag">style</span>, or <span class="html-tag">meta</span> doesn’t have any effect because they are not seen.<br />
Let’s explore this a bit more.</p>
<h2>Contents</h2>
<ol type="1">
<li><a href="#every-html-element-is-a-box">Every HTML Element is a Box</a></li>
<li><a href="#css-box-model">CSS Box Model</a>
<ol type="1">
<li><a href="#content">Content</a></li>
<li><a href="#padding">Padding</a></li>
<li><a href="#border">Border</a></li>
<li><a href="#margin">Margin</a></li>
</ol>
</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="every-html-element-is-a-box">Every HTML Element is a Box</h2>
<p>More accurately, every HTML element in the <span class="html-tag">body</span> section that is displayed is a box (if you placed a <span class="html-tag">style</span> block on the body section, it will not be a box because it is not displayed). The <span class="html-tag">html</span> tag is special and will be discussed later.<br />
Like all boxes, you can stack them like blocks:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-stacked-boxes.png"><img decoding="async" class="aligncenter size-full wp-image-3582" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-stacked-boxes.png" alt="stacked boxes" width="600" height="338" /></a><br />
or put one inside another like containers:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-nested-boxes.png"><img decoding="async" class="aligncenter size-full wp-image-3583" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-nested-boxes.png" alt="nested boxes" width="600" height="338" /></a><br />
or combine stacking and containment:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-nested-and-stacked.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3584" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-nested-and-stacked.png" alt="nested and stacked boxes" width="600" height="338" /></a></p>
<h2 id="css-box-model">CSS Box Model</h2>
<p>This concept of boxes is captured in the CSS Box Model:<br />
<a href="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-css-box-model.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-3590" src="https://complete-concrete-concise.com/wp-content/uploads/2018/04/15-css-box-model.png" alt="CSS Box Model" width="600" height="338" /></a></p>
<h3 id="content">Content</h3>
<p>Content is at the centre of the box. This content is, usually, text, but it can also be embedded content such as images, audio, or videos. It can also be considered the <em>foreground</em>. This is what the <strong>color</strong> attribute affects.<br />
The box expands to fit the size of the content.</p>
<h3 id="padding">Padding</h3>
<p>Padding is the space around the content. It allows you to control the amount of background space surrounding your content.<br />
You control the amount of padding around the content using the <strong>padding</strong> property:</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>p {
<a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">padding</span>: <span class="dv">5px</span>;
<a id="cb2-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>The above code snippet adds an extra 5 pixels to the padding around the content in paragraphs. In other words, 5 pixels are added to the left, right, top, and bottom of the <em>background</em> for each paragraph.<br />
There are many ways of specifying the <strong>padding</strong> property, but, for now, this is all you need.</p>
<h3 id="border">Border</h3>
<p>The border goes around the padding. By default, the border is transparent and 0 pixels in width.<br />
You use the <strong>border</strong> property to adjust the <em>width</em> and <em>colour</em> of the border:</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>p {
<a id="cb3-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">border</span>: <span class="dv">5px</span> <span class="dv">solid</span> <span class="dv">red</span>;
<a id="cb3-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>The above code snippet draws a solid red border that is 5 pixels thick around every paragraph. The order of the parameters doesn’t matter. The colour can be: named, hexadecimal, or RGB.<br />
There are many ways of specifying the <strong>border</strong> property, but, for now, this is all you need. There are many border styles, in addition to <strong>solid</strong>, you can try <strong>dotted</strong>, <strong>dashed</strong>, or <strong>double</strong>.</p>
<h3 id="margin">Margin</h3>
<p>The margin is empty space around the border. It is always transparent, so you can never see it &#8211; except for the spacing effect it produces. This allows you to control the spacing between various HTML elements.<br />
You control the amount of margin around the border using the <strong>margin</strong> property:</p>
<div id="cb4" class="sourceCode">
<pre class="sourceCode css"><code class="sourceCode css"><a id="cb4-1" class="sourceLine" data-line-number="1"></a>p {
<a id="cb4-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">margin</span>: <span class="dv">5px</span>;
<a id="cb4-3" class="sourceLine" data-line-number="3"></a>}</code></pre>
</div>
<p>The above code snippet adds an extra 5 pixels to the margin around the border in paragraphs. In other words, 5 pixels are added to the left, right, top, and bottom of each paragraph. The margin is always transparent.</p>
<h2 id="conclusion">Conclusion</h2>
<ol type="1">
<li>Every HTML element in the <span class="html-tag">body</span> section that is displayed is a box.</li>
<li>You can stack HTML elements.</li>
<li>You can embed HTML elements inside other HTML elements.</li>
<li>CSS specifies a Box Model for HTML elements.</li>
<li>At the centre of every box is the <strong>content</strong>. Boxes expand to contain the content.</li>
<li>Content is surrounded by space called <strong>padding</strong>.</li>
<li>The amount of padding can be adjusted using the <strong>padding</strong> property.</li>
<li>The <strong>padding</strong> property (for now) takes a single value: the number of pixels to be used for padding. It is applied to the top, right, bottom, and left of the content.</li>
<li>The <strong>padding</strong> is the same colour as the <strong>background-color</strong> of the HTML element.</li>
<li>A <strong>border</strong> surrounds the padding.</li>
<li>The border can be customized using the <strong>border</strong> property.</li>
<li>The <strong>border</strong> property takes 3 values: <em>border width</em> (in pixels), <em>border style</em> (usually <strong>solid</strong>), and the <em>border colour</em> (named, hexadecimal, or RGB). It is applied to the top, right, bottom, and left of the padding surrounding the content.</li>
<li>The <strong>border</strong> values can be in any order.</li>
<li>There is a <strong>margin</strong> around the border.</li>
<li>The <strong>margin</strong> is always transparent.</li>
<li>The margin can be adjusted using the <strong>margin</strong> property.</li>
<li>The <strong>margin</strong> property (for now) takes a single value: the number of pixels to be used for padding. It is applied to the top, right, bottom, and left of the border of the HTML 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 />
This tutorial showed you that HTML elements can be considered as boxes. It also introduced the CSS Box model.<br />
Using the <strong>border</strong> and <strong>margin</strong> properties, create some simple HTML documents and see how the boxes stack and nest with each other.<br />
You can use the following sample code (which is the same as the previous) as a starting point:</p>
<ul>
<li>Style one element at a time and see what happens.</li>
<li>I recommend using a border with a width of 5 pixels.</li>
<li>I recommend using a margin of 2 pixels.</li>
</ul>
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" data-line-number="1"></a><span class="dt">&lt;!DOCTYPE </span>HTML<span class="dt">&gt;</span>
<a id="cb5-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;html&gt;</span>
<a id="cb5-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;head&gt;</span>
<a id="cb5-4" class="sourceLine" data-line-number="4"></a>    <span class="kw">&lt;title&gt;</span>Hello World<span class="kw">&lt;/title&gt;</span>
<a id="cb5-5" class="sourceLine" data-line-number="5"></a>    <span class="kw">&lt;meta</span><span class="ot"> charset=</span><span class="st">"utf-8"</span>  <span class="kw">/&gt;</span>
<a id="cb5-6" class="sourceLine" data-line-number="6"></a>
<a id="cb5-7" class="sourceLine" data-line-number="7"></a>    <span class="kw">&lt;style&gt;</span>
<a id="cb5-8" class="sourceLine" data-line-number="8"></a>
<a id="cb5-9" class="sourceLine" data-line-number="9"></a>      body {
<a id="cb5-10" class="sourceLine" data-line-number="10"></a>
<a id="cb5-11" class="sourceLine" data-line-number="11"></a>      }
<a id="cb5-12" class="sourceLine" data-line-number="12"></a>
<a id="cb5-13" class="sourceLine" data-line-number="13"></a>      h1 {
<a id="cb5-14" class="sourceLine" data-line-number="14"></a>
<a id="cb5-15" class="sourceLine" data-line-number="15"></a>      }
<a id="cb5-16" class="sourceLine" data-line-number="16"></a>
<a id="cb5-17" class="sourceLine" data-line-number="17"></a>      h2 {
<a id="cb5-18" class="sourceLine" data-line-number="18"></a>
<a id="cb5-19" class="sourceLine" data-line-number="19"></a>      }
<a id="cb5-20" class="sourceLine" data-line-number="20"></a>
<a id="cb5-21" class="sourceLine" data-line-number="21"></a>      p {
<a id="cb5-22" class="sourceLine" data-line-number="22"></a>
<a id="cb5-23" class="sourceLine" data-line-number="23"></a>      }
<a id="cb5-24" class="sourceLine" data-line-number="24"></a>
<a id="cb5-25" class="sourceLine" data-line-number="25"></a>      li {
<a id="cb5-26" class="sourceLine" data-line-number="26"></a>
<a id="cb5-27" class="sourceLine" data-line-number="27"></a>      }
<a id="cb5-28" class="sourceLine" data-line-number="28"></a>
<a id="cb5-29" class="sourceLine" data-line-number="29"></a>      ol {
<a id="cb5-30" class="sourceLine" data-line-number="30"></a>
<a id="cb5-31" class="sourceLine" data-line-number="31"></a>      }
<a id="cb5-32" class="sourceLine" data-line-number="32"></a>
<a id="cb5-33" class="sourceLine" data-line-number="33"></a>      ul {
<a id="cb5-34" class="sourceLine" data-line-number="34"></a>
<a id="cb5-35" class="sourceLine" data-line-number="35"></a>      }
<a id="cb5-36" class="sourceLine" data-line-number="36"></a>
<a id="cb5-37" class="sourceLine" data-line-number="37"></a>      strong {
<a id="cb5-38" class="sourceLine" data-line-number="38"></a>
<a id="cb5-39" class="sourceLine" data-line-number="39"></a>      }
<a id="cb5-40" class="sourceLine" data-line-number="40"></a>
<a id="cb5-41" class="sourceLine" data-line-number="41"></a>      mark {
<a id="cb5-42" class="sourceLine" data-line-number="42"></a>
<a id="cb5-43" class="sourceLine" data-line-number="43"></a>      }
<a id="cb5-44" class="sourceLine" data-line-number="44"></a>
<a id="cb5-45" class="sourceLine" data-line-number="45"></a>      a {
<a id="cb5-46" class="sourceLine" data-line-number="46"></a>
<a id="cb5-47" class="sourceLine" data-line-number="47"></a>      }
<a id="cb5-48" class="sourceLine" data-line-number="48"></a>
<a id="cb5-49" class="sourceLine" data-line-number="49"></a>    <span class="kw">&lt;/style&gt;</span>
<a id="cb5-50" class="sourceLine" data-line-number="50"></a>
<a id="cb5-51" class="sourceLine" data-line-number="51"></a>  <span class="kw">&lt;/head&gt;</span>
<a id="cb5-52" class="sourceLine" data-line-number="52"></a>  <span class="kw">&lt;body&gt;</span>
<a id="cb5-53" class="sourceLine" data-line-number="53"></a>    <span class="kw">&lt;h1&gt;</span>This is a heading (for testing purposes)<span class="kw">&lt;/h1&gt;</span>
<a id="cb5-54" class="sourceLine" data-line-number="54"></a>
<a id="cb5-55" class="sourceLine" data-line-number="55"></a>    <span class="kw">&lt;p&gt;</span>Paragraphs are the bread and butter of HTML.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-56" class="sourceLine" data-line-number="56"></a>
<a id="cb5-57" class="sourceLine" data-line-number="57"></a>    <span class="kw">&lt;p&gt;</span>They can include <span class="kw">&lt;strong&gt;</span>strong<span class="kw">&lt;/strong&gt;</span> tags.
<a id="cb5-58" class="sourceLine" data-line-number="58"></a>    <span class="kw">&lt;/p&gt;</span>
<a id="cb5-59" class="sourceLine" data-line-number="59"></a>
<a id="cb5-60" class="sourceLine" data-line-number="60"></a>    <span class="kw">&lt;ol&gt;</span>
<a id="cb5-61" class="sourceLine" data-line-number="61"></a>      <span class="kw">&lt;li&gt;</span>Lists are cool!<span class="kw">&lt;/li&gt;</span>
<a id="cb5-62" class="sourceLine" data-line-number="62"></a>      <span class="kw">&lt;li&gt;</span>The list things.<span class="kw">&lt;/li&gt;</span>
<a id="cb5-63" class="sourceLine" data-line-number="63"></a>      <span class="kw">&lt;li&gt;</span>This one has an <span class="kw">&lt;i&gt;</span>i<span class="kw">&lt;/i&gt;</span> inside.<span class="kw">&lt;/li&gt;</span>
<a id="cb5-64" class="sourceLine" data-line-number="64"></a>      <span class="kw">&lt;li&gt;&lt;p&gt;</span>This one contains a <span class="dv">&amp;lt;</span>ul<span class="dv">&amp;gt;</span>:<span class="kw">&lt;/p&gt;</span>
<a id="cb5-65" class="sourceLine" data-line-number="65"></a>        <span class="kw">&lt;ul&gt;</span>
<a id="cb5-66" class="sourceLine" data-line-number="66"></a>          <span class="kw">&lt;li&gt;</span>Item 1<span class="kw">&lt;/li&gt;</span>
<a id="cb5-67" class="sourceLine" data-line-number="67"></a>          <span class="kw">&lt;li&gt;&lt;mark&gt;</span>Marked item<span class="kw">&lt;/mark&gt;&lt;/li&gt;</span>
<a id="cb5-68" class="sourceLine" data-line-number="68"></a>          <span class="kw">&lt;li&gt;</span>Final item<span class="kw">&lt;/li&gt;</span>
<a id="cb5-69" class="sourceLine" data-line-number="69"></a>        <span class="kw">&lt;/ul&gt;</span>
<a id="cb5-70" class="sourceLine" data-line-number="70"></a>        <span class="kw">&lt;li&gt;&lt;h2&gt;</span>What happens with an h2?<span class="kw">&lt;/h2&gt;&lt;/li&gt;</span>
<a id="cb5-71" class="sourceLine" data-line-number="71"></a>      <span class="kw">&lt;li&gt;</span>Final order<span class="kw">&lt;/li&gt;</span>
<a id="cb5-72" class="sourceLine" data-line-number="72"></a>    <span class="kw">&lt;/ol&gt;</span>
<a id="cb5-73" class="sourceLine" data-line-number="73"></a>
<a id="cb5-74" class="sourceLine" data-line-number="74"></a>    <span class="kw">&lt;p&gt;</span>A final paragraph with a dummy
<a id="cb5-75" class="sourceLine" data-line-number="75"></a>      <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"#"</span><span class="kw">&gt;</span>link<span class="kw">&lt;/a&gt;</span> inside it.<span class="kw">&lt;/p&gt;</span>
<a id="cb5-76" class="sourceLine" data-line-number="76"></a>
<a id="cb5-77" class="sourceLine" data-line-number="77"></a>  <span class="kw">&lt;/body&gt;</span>
<a id="cb5-78" class="sourceLine" data-line-number="78"></a><span class="kw">&lt;/html&gt;</span></code></pre>
</div>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://www.w3.org/TR/CSS2/box.html#box-dimensions">CSS Box Model</a></li>
<li><a href="https://www.w3.org/TR/CSS2/box.html#padding-properties">Padding</a></li>
<li><a href="https://www.w3.org/TR/CSS2/box.html#border-properties">Border</a></li>
<li><a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">Margin</a></li>
</ol>
<div class="prev">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-basic-css-example">Prev</a>
</div>
<div class="next">
<a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-css-example-with-boxes">Next</a>
</div>
<div class="clear"></div>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/introducing-html-flow-and-the-css-box-model/">Introducing HTML Flow and the CSS Box Model</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
