{"id":2457,"date":"2022-06-13T14:12:16","date_gmt":"2022-06-13T12:12:16","guid":{"rendered":"http:\/\/jakisproblem.pl\/?p=2457"},"modified":"2022-06-13T14:12:16","modified_gmt":"2022-06-13T12:12:16","slug":"introduction-to-css-layout","status":"publish","type":"post","link":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2022\/06\/13\/introduction-to-css-layout\/","title":{"rendered":"Introduction to CSS layout"},"content":{"rendered":"<div class=\"section-content\">\n<p>source: https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction<\/p>\n<p>This article will recap some of the CSS layout features we&#8217;ve already touched upon in previous modules, such as different\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/display\"><code>display<\/code><\/a>\u00a0values, as well as introduce some of the concepts we&#8217;ll be covering throughout this module.<\/p>\n<div class=\"table-scroll\">\n<table>\n<tbody>\n<tr>\n<th scope=\"row\">Prerequisites:<\/th>\n<td>The basics of HTML (study\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/HTML\/Introduction_to_HTML\">Introduction to HTML<\/a>), and an idea of How CSS works (study\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/First_steps\">Introduction to CSS<\/a>.)<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">Objective:<\/th>\n<td>To give you an overview of CSS page layout techniques. Each technique can be learned in greater detail in subsequent tutorials.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>CSS page layout techniques allow us to take elements contained in a web page and control where they&#8217;re positioned relative to the following factors: their default position in normal layout flow, the other elements around them, their parent container, and the main viewport\/window. The page layout techniques we&#8217;ll be covering in more detail in this module are:<\/p>\n<ul>\n<li>Normal flow<\/li>\n<li>The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/display\"><code>display<\/code><\/a>\u00a0property<\/li>\n<li>Flexbox<\/li>\n<li>Grid<\/li>\n<li>Floats<\/li>\n<li>Positioning<\/li>\n<li>Table layout<\/li>\n<li>Multiple-column layout<\/li>\n<\/ul>\n<p>Each technique has its uses, advantages, and disadvantages. No technique is designed to be used in isolation. By understanding what each layout method is designed for you&#8217;ll be in a good position to understand which method is most appropriate for each task.<\/p>\n<\/div>\n<section aria-labelledby=\"normal_flow\">\n<h2 id=\"normal_flow\"><a title=\"Permalink to Normal flow\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#normal_flow\">Normal flow<\/a><\/h2>\n<div class=\"section-content\">\n<p>Normal flow is how the browser lays out HTML pages by default when you do nothing to control page layout. Let&#8217;s look at a quick HTML example:<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>I love my cat.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>ul<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>Buy cat food<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>Exercise<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>Cheer up friend<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>li<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>ul<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>The end!<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>By default, the browser will display this code as follows:<\/p>\n<p><iframe loading=\"lazy\" id=\"frame_normal_flow\" class=\"sample-code-frame\" title=\"Normal flow sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.normal_flow.html\" width=\"100%\" height=\"200\" data-mce-fragment=\"1\"><\/iframe>Note how the HTML is displayed in the exact order in which it appears in the source code, with elements stacked on top of one another \u2014 the first paragraph, followed by the unordered list, followed by the second paragraph.<\/p>\n<p>The elements that appear one below the other are described as\u00a0<strong>block<\/strong>\u00a0elements, in contrast to\u00a0<strong>inline<\/strong>\u00a0elements, which appear beside one another like the individual words in a paragraph.<\/p>\n<div id=\"sect1\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0The direction in which block element contents are laid out is described as the Block Direction. The Block Direction runs vertically in a language such as English, which has a horizontal writing mode. It would run horizontally in any language with a Vertical Writing Mode, such as Japanese. The corresponding Inline Direction is the direction in which inline contents (such as a sentence) would run.<\/p>\n<\/div>\n<p>For many of the elements on your page, the normal flow will create exactly the layout you need. However, for more complex layouts you will need to alter this default behavior using some of the tools available to you in CSS. Starting with a well-structured HTML document is very important because you can then work with the way things are laid out by default rather than fighting against it.<\/p>\n<p>The methods that can change how elements are laid out in CSS are:<\/p>\n<ul>\n<li><strong>The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/display\"><code>display<\/code><\/a>\u00a0property<\/strong>\u00a0\u2014 Standard values such as\u00a0<code>block<\/code>,\u00a0<code>inline<\/code>\u00a0or\u00a0<code>inline-block<\/code>\u00a0can change how elements behave in normal flow, for example, by making a block-level element behave like an inline-level element (see\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/Building_blocks\/The_box_model#block_and_inline_boxes\">Types of CSS boxes<\/a>\u00a0for more information). We also have entire layout methods that are enabled via specific\u00a0<code>display<\/code>\u00a0values, for example,\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Grids\">CSS Grid<\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Flexbox\">Flexbox<\/a>, which alter how child elements are laid out inside their parents.<\/li>\n<li><strong>Floats<\/strong>\u00a0\u2014 Applying a\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/float\"><code>float<\/code><\/a>\u00a0value such as\u00a0<code>left<\/code>\u00a0can cause block-level elements to wrap along one side of an element, like the way images sometimes have text floating around them in magazine layouts.<\/li>\n<li><strong>The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/position\"><code>position<\/code><\/a>\u00a0property<\/strong>\u00a0\u2014 Allows you to precisely control the placement of boxes inside other boxes.\u00a0<code>static<\/code>\u00a0positioning is the default in normal flow, but you can cause elements to be laid out differently using other values, for example, as fixed to the top of the browser viewport.<\/li>\n<li><strong>Table layout<\/strong>\u00a0\u2014 Features designed for styling parts of an HTML table can be used on non-table elements using\u00a0<code>display: table<\/code>\u00a0and associated properties.<\/li>\n<li><strong>Multi-column layout<\/strong>\u00a0\u2014 The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Columns\">Multi-column layout<\/a>\u00a0properties can cause the content of a block to layout in columns, as you might see in a newspaper.<\/li>\n<\/ul>\n<\/div>\n<\/section>\n<section aria-labelledby=\"the_display_property\">\n<h2 id=\"the_display_property\"><a title=\"Permalink to The display property\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#the_display_property\">The display property<\/a><\/h2>\n<div class=\"section-content\">\n<p>The main methods for achieving page layout in CSS all involve specifying values for the\u00a0<code>display<\/code>\u00a0property. This property allows us to change the default way something displays. Everything in normal flow has a default value for\u00a0<code>display<\/code>; i.e., a default way that elements are set to behave. For example, the fact that paragraphs in English display one below the other is because they are styled with\u00a0<code>display: block<\/code>. If you create a link around some text inside a paragraph, that link remains inline with the rest of the text, and doesn&#8217;t break onto a new line. This is because the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/a\"><code>&lt;a&gt;<\/code><\/a>\u00a0element is\u00a0<code>display: inline<\/code>\u00a0by default.<\/p>\n<p>You can change this default display behavior. For example, the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/li\"><code>&lt;li&gt;<\/code><\/a>\u00a0element is\u00a0<code>display: block<\/code>\u00a0by default, meaning that list items display one below the other in our English document. If we were to change the display value to\u00a0<code>inline<\/code>\u00a0they would display next to each other, as words would do in a sentence. The fact that you can change the value of\u00a0<code>display<\/code>\u00a0for any element means that you can pick HTML elements for their semantic meaning without being concerned about how they will look. The way they look is something that you can change.<\/p>\n<p>In addition to being able to change the default presentation by turning an item from\u00a0<code>block<\/code>\u00a0to\u00a0<code>inline<\/code>\u00a0and vice versa, there are some more involved layout methods that start out as a value of\u00a0<code>display<\/code>. However, when using these you will generally need to invoke additional properties. The two values most important for our discussion of layout are\u00a0<code>display: flex<\/code>\u00a0and\u00a0<code>display: grid<\/code>.<\/p>\n<\/div>\n<\/section>\n<section aria-labelledby=\"flexbox\">\n<h2 id=\"flexbox\"><a title=\"Permalink to Flexbox\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#flexbox\">Flexbox<\/a><\/h2>\n<div class=\"section-content\">\n<p>Flexbox is the short name for the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Flexible_Box_Layout\">Flexible Box Layout<\/a>\u00a0CSS module, designed to make it easy for us to lay things out in one dimension \u2014 either as a row or as a column. To use flexbox, you apply\u00a0<code>display: flex<\/code>\u00a0to the parent element of the elements you want to lay out; all its direct children then become\u00a0<em>flex items<\/em>. We can see this in a simple example.<\/p>\n<\/div>\n<\/section>\n<section aria-labelledby=\"setting_display_flex\">\n<h3 id=\"setting_display_flex\"><a title=\"Permalink to Setting display: flex\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#setting_display_flex\">Setting display: flex<\/a><\/h3>\n<div class=\"section-content\">\n<p>The HTML markup below gives us a containing element with a class of\u00a0<code>wrapper<\/code>, inside of which are three\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/div\"><code>&lt;div&gt;<\/code><\/a>\u00a0elements. By default these would display as block elements, that is, below one another in our English language document.<\/p>\n<p>However, if we add\u00a0<code>display: flex<\/code>\u00a0to the parent, the three items now arrange themselves into columns. This is due to them becoming\u00a0<em>flex items<\/em>\u00a0and being affected by some initial values that flexbox sets on the flex container. They are displayed in a row because the property\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/flex-direction\"><code>flex-direction<\/code><\/a>\u00a0of the parent element has an initial value of\u00a0<code>row<\/code>. They all appear to stretch in height because the property\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/align-items\"><code>align-items<\/code><\/a>\u00a0of their parent element has an initial value of\u00a0<code>stretch<\/code>. This means that the items stretch to the height of the flex container, which in this case is defined by the tallest item. The items all line up at the start of the container, leaving any extra space at the end of the row.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.wrapper<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> flex<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>wrapper<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>One<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Two<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box3<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Three<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_setting_display_flex\" class=\"sample-code-frame\" title=\"Setting display flex sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.setting_display_flex.html\" width=\"300\" height=\"200\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"setting_the_flex_property\">\n<h3 id=\"setting_the_flex_property\"><a title=\"Permalink to Setting the flex property\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#setting_the_flex_property\">Setting the flex property<\/a><\/h3>\n<div class=\"section-content\">\n<p>In addition to properties that can be applied to a\u00a0<em>flex container<\/em>, there are also properties that can be applied to\u00a0<em>flex items<\/em>. These properties, among other things, can change the way that items\u00a0<em>flex<\/em>, enabling them to expand or contract according to available space.<\/p>\n<p>As a simple example, we can add the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/flex\"><code>flex<\/code><\/a>\u00a0property to all of our child items, and give it a value of\u00a0<code>1<\/code>. This will cause all of the items to grow and fill the container, rather than leaving space at the end. If there is more space then the items will become wider; if there is less space they will become narrower. In addition, if you add another element to the markup, the other items will all become smaller to make space for it; the items all together continue taking up all the space.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.wrapper<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> flex<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">.wrapper &gt; div<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">flex<\/span><span class=\"token punctuation\">:<\/span> 1<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>wrapper<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>One<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Two<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box3<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Three<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_setting_the_flex_property\" class=\"sample-code-frame\" title=\"Setting the flex property sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.setting_the_flex_property.html\" width=\"300\" height=\"200\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<div id=\"sect2\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0This has been a very short introduction to what is possible in Flexbox. To find out more, see our\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Flexbox\">Flexbox<\/a>\u00a0article.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section aria-labelledby=\"grid_layout\">\n<h2 id=\"grid_layout\"><a title=\"Permalink to Grid Layout\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#grid_layout\">Grid Layout<\/a><\/h2>\n<div class=\"section-content\">\n<p>While flexbox is designed for one-dimensional layout, Grid Layout is designed for two dimensions \u2014 lining things up in rows and columns.<\/p>\n<\/div>\n<\/section>\n<section aria-labelledby=\"setting_display_grid\">\n<h3 id=\"setting_display_grid\"><a title=\"Permalink to Setting display: grid\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#setting_display_grid\">Setting display: grid<\/a><\/h3>\n<div class=\"section-content\">\n<p>Similar to flexbox, we enable Grid Layout with its specific display value \u2014\u00a0<code>display: grid<\/code>. The below example uses similar markup to the flex example, with a container and some child elements. In addition to using\u00a0<code>display: grid<\/code>, we also define some row and column\u00a0<em>tracks<\/em>\u00a0for the parent using the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/grid-template-rows\"><code>grid-template-rows<\/code><\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/grid-template-columns\"><code>grid-template-columns<\/code><\/a>\u00a0properties respectively. We&#8217;ve defined three columns, each of\u00a0<code>1fr<\/code>, as well as two rows of\u00a0<code>100px<\/code>. We don&#8217;t need to put any rules on the child elements; they&#8217;re automatically placed into the cells our grid&#8217;s created.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.wrapper<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> grid<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-template-columns<\/span><span class=\"token punctuation\">:<\/span> 1fr 1fr 1fr<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-template-rows<\/span><span class=\"token punctuation\">:<\/span> 100px 100px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">gap<\/span><span class=\"token punctuation\">:<\/span> 10px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>wrapper<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>One<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Two<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box3<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Three<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box4<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Four<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box5<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Five<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box6<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Six<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_setting_display_grid\" class=\"sample-code-frame\" title=\"Setting display grid sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.setting_display_grid.html\" width=\"300\" height=\"330\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"placing_items_on_the_grid\">\n<h3 id=\"placing_items_on_the_grid\"><a title=\"Permalink to Placing items on the grid\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#placing_items_on_the_grid\">Placing items on the grid<\/a><\/h3>\n<div class=\"section-content\">\n<p>Once you have a grid, you can explicitly place your items on it, rather than relying on the auto-placement behavior seen above. In the next example below, we&#8217;ve defined the same grid, but this time with three child items. We&#8217;ve set the start and end line of each item using the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/grid-column\"><code>grid-column<\/code><\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/grid-row\"><code>grid-row<\/code><\/a>\u00a0properties. This causes the items to span multiple tracks.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.wrapper<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> grid<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-template-columns<\/span><span class=\"token punctuation\">:<\/span> 1fr 1fr 1fr<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-template-rows<\/span><span class=\"token punctuation\">:<\/span> 100px 100px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">gap<\/span><span class=\"token punctuation\">:<\/span> 10px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">.box1<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">grid-column<\/span><span class=\"token punctuation\">:<\/span> 2 \/ 4<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-row<\/span><span class=\"token punctuation\">:<\/span> 1<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">.box2<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">grid-column<\/span><span class=\"token punctuation\">:<\/span> 1<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-row<\/span><span class=\"token punctuation\">:<\/span> 1 \/ 3<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">.box3<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">grid-row<\/span><span class=\"token punctuation\">:<\/span> 2<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">grid-column<\/span><span class=\"token punctuation\">:<\/span> 3<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>wrapper<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>One<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Two<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box3<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Three<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_placing_items_on_the_grid\" class=\"sample-code-frame\" title=\"Placing items on the grid sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.placing_items_on_the_grid.html\" width=\"300\" height=\"330\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<div id=\"sect3\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0These two examples reveal just a small sample of the power of Grid layout. To learn more, see our\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Grids\">Grid Layout<\/a>\u00a0article.<\/p>\n<\/div>\n<p>The rest of this guide covers other layout methods that are less important for the main layout of your page, but still help to achieve specific tasks. By understanding the nature of each layout task you will soon find that when you look at a particular component of your design, the type of layout most suitable for it will often be clear.<\/p>\n<\/div>\n<\/section>\n<section aria-labelledby=\"floats\">\n<h2 id=\"floats\"><a title=\"Permalink to Floats\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#floats\">Floats<\/a><\/h2>\n<div class=\"section-content\">\n<p>Floating an element changes the behavior of that element and the block level elements that follow it in normal flow. The floated element is moved to the left or right and removed from normal flow, and the surrounding content\u00a0<em>floats<\/em>\u00a0around it.<\/p>\n<p>The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/float\"><code>float<\/code><\/a>\u00a0property has four possible values:<\/p>\n<ul>\n<li><code>left<\/code>\u00a0\u2014 Floats the element to the left.<\/li>\n<li><code>right<\/code>\u00a0\u2014 Floats the element to the right.<\/li>\n<li><code>none<\/code>\u00a0\u2014 Specifies no floating at all. This is the default value.<\/li>\n<li><code>inherit<\/code>\u00a0\u2014 Specifies that the value of the\u00a0<code>float<\/code>\u00a0property should be inherited from the element&#8217;s parent element.<\/li>\n<\/ul>\n<p>In the example below, we float a\u00a0<code>&lt;div&gt;<\/code>\u00a0left and give it a\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/margin\"><code>margin<\/code><\/a>\u00a0on the right to push the surrounding text away from it. This gives us the effect of text wrapped around the boxed element, and is most of what you need to know about floats as used in modern web design.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>Simple float example<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>box<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Float<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla luctus aliquam dolor, eu lacinia lorem placerat vulputate. Duis felis orci, pulvinar id metus ut, rutrum luctus orci. Cras porttitor imperdiet nunc, at ultricies tellus laoreet sit amet. Sed auctor cursus massa at porta. Integer ligula ipsum, tristique sit amet orci vel, viverra egestas ligula. Curabitur vehicula tellus neque, ac ornare ex malesuada et. In vitae convallis lacus. Aliquam erat volutpat. Suspendisse ac imperdiet turpis. Aenean finibus sollicitudin eros pharetra congue. Duis ornare egestas augue ut luctus. Proin blandit quam nec lacus varius commodo et a urna. Ut id ornare felis, eget fermentum sapien.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.box<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">float<\/span><span class=\"token punctuation\">:<\/span> left<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 150px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">height<\/span><span class=\"token punctuation\">:<\/span> 150px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">margin-right<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_floats\" class=\"sample-code-frame\" title=\"Floats sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.floats.html\" width=\"100%\" height=\"600\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<div id=\"sect4\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0Floats are fully explained in our lesson on the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Floats\">float and clear<\/a>\u00a0properties. Prior to techniques such as Flexbox and Grid Layout, floats were used as a method of creating column layouts. You may still come across these methods on the web; we will cover these in the lesson on\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Legacy_Layout_Methods\">legacy layout methods<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section aria-labelledby=\"positioning_techniques\">\n<h2 id=\"positioning_techniques\"><a title=\"Permalink to Positioning techniques\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#positioning_techniques\">Positioning techniques<\/a><\/h2>\n<div class=\"section-content\">\n<p>Positioning allows you to move an element from where it would otherwise be placed in normal flow over to another location. Positioning isn&#8217;t a method for creating the main layouts of a page; it&#8217;s more about managing and fine-tuning the position of specific items on a page.<\/p>\n<p>There are, however, useful techniques for obtaining specific layout patterns that rely on the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/position\"><code>position<\/code><\/a>\u00a0property. Understanding positioning also helps in understanding normal flow, and what it means to move an item out of the normal flow.<\/p>\n<p>There are five types of positioning you should know about:<\/p>\n<ul>\n<li><strong>Static positioning<\/strong>\u00a0is the default that every element gets. It just means &#8222;put the element into its normal position in the document layout flow \u2014 nothing special to see here&#8221;.<\/li>\n<li><strong>Relative positioning<\/strong>\u00a0allows you to modify an element&#8217;s position on the page, moving it relative to its position in normal flow, as well as making it overlap other elements on the page.<\/li>\n<li><strong>Absolute positioning<\/strong>\u00a0moves an element completely out of the page&#8217;s normal layout flow, like it&#8217;s sitting on its own separate layer. From there, you can fix it to a position relative to the edges of its closest positioned ancestor (which becomes\u00a0<code>&lt;html&gt;<\/code>\u00a0if no other ancestors are positioned). This is useful for creating complex layout effects, such as tabbed boxes where different content panels sit on top of one another and are shown and hidden as desired, or information panels that sit off-screen by default, but can be made to slide on screen using a control button.<\/li>\n<li><strong>Fixed positioning<\/strong>\u00a0is very similar to absolute positioning except that it fixes an element relative to the browser viewport, not another element. This is useful for creating effects such as a persistent navigation menu that always stays in the same place on the screen as the rest of the content scrolls.<\/li>\n<li><strong>Sticky positioning<\/strong>\u00a0is a newer positioning method that makes an element act like\u00a0<code>position: static<\/code>\u00a0until it hits a defined offset from the viewport, at which point it acts like\u00a0<code>position: fixed<\/code>.<\/li>\n<\/ul>\n<\/div>\n<\/section>\n<section aria-labelledby=\"simple_positioning_example\">\n<h3 id=\"simple_positioning_example\"><a title=\"Permalink to Simple positioning example\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#simple_positioning_example\">Simple positioning example<\/a><\/h3>\n<div class=\"section-content\">\n<p>To provide familiarity with these page layout techniques, we&#8217;ll show you a couple of quick examples. Our examples will all feature the same HTML structure (a heading followed by three paragraphs), which is as follows:<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>Positioning<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>I am a basic block level element.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>positioned<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>I am a basic block level element.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>I am a basic block level element.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>This HTML will be styled by default using the following CSS:<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">body<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 500px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">margin<\/span><span class=\"token punctuation\">:<\/span> 0 auto<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">p<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">background-color<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token function\">rgb<\/span><span class=\"token punctuation\">(<\/span>207<span class=\"token punctuation\">,<\/span>232<span class=\"token punctuation\">,<\/span>220<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">border<\/span><span class=\"token punctuation\">:<\/span> 2px solid <span class=\"token function\">rgb<\/span><span class=\"token punctuation\">(<\/span>79<span class=\"token punctuation\">,<\/span>185<span class=\"token punctuation\">,<\/span>227<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">padding<\/span><span class=\"token punctuation\">:<\/span> 10px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">margin<\/span><span class=\"token punctuation\">:<\/span> 10px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">border-radius<\/span><span class=\"token punctuation\">:<\/span> 5px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>The rendered output is as follows:<\/p>\n<p><iframe loading=\"lazy\" id=\"frame_simple_positioning_example\" class=\"sample-code-frame\" title=\"Simple positioning example sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.simple_positioning_example.html\" width=\"100%\" height=\"300\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"relative_positioning\">\n<h3 id=\"relative_positioning\"><a title=\"Permalink to Relative positioning\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#relative_positioning\">Relative positioning<\/a><\/h3>\n<div class=\"section-content\">\n<p>Relative positioning allows you to offset an item from its default position in normal flow. This means you could achieve a task such as moving an icon down a bit so it lines up with a text label. To do this, we could add the following rule to add relative positioning:<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.positioned<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">position<\/span><span class=\"token punctuation\">:<\/span> relative<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">top<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">left<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>Here we give our middle paragraph a\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/position\"><code>position<\/code><\/a>\u00a0value of\u00a0<code>relative<\/code>. This doesn&#8217;t do anything on its own, so we also add\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/top\"><code>top<\/code><\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/left\"><code>left<\/code><\/a>\u00a0properties. These serve to move the affected element down and to the right. This might seem like the opposite of what you were expecting, but you need to think of it as the element being pushed on its left and top sides, which results in it moving right and down.<\/p>\n<p>Adding this code will give the following result:<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\"><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_relative_positioning\" class=\"sample-code-frame\" title=\"Relative positioning sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.relative_positioning.html\" width=\"100%\" height=\"300\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"absolute_positioning\">\n<h3 id=\"absolute_positioning\"><a title=\"Permalink to Absolute positioning\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#absolute_positioning\">Absolute positioning<\/a><\/h3>\n<div class=\"section-content\">\n<p>Absolute positioning is used to completely remove an element from the normal flow and instead position it using offsets from the edges of a containing block.<\/p>\n<p>Going back to our original non-positioned example, we could add the following CSS rule to implement absolute positioning:<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.positioned<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">position<\/span><span class=\"token punctuation\">:<\/span> absolute<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">top<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">left<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>Here we give our middle paragraph a\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/position\"><code>position<\/code><\/a>\u00a0value of\u00a0<code>absolute<\/code>\u00a0and the same\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/top\"><code>top<\/code><\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/left\"><code>left<\/code><\/a>\u00a0properties as before. Adding this code will produce the following result:<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\"><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_absolute_positioning\" class=\"sample-code-frame\" title=\"Absolute positioning sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.absolute_positioning.html\" width=\"100%\" height=\"300\" data-mce-fragment=\"1\"><\/iframe>This is very different! The positioned element has now been completely separated from the rest of the page layout and sits over the top of it. The other two paragraphs now sit together as if their positioned sibling doesn&#8217;t exist. The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/top\"><code>top<\/code><\/a>\u00a0and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/left\"><code>left<\/code><\/a>\u00a0properties have a different effect on absolutely positioned elements than they do on relatively positioned elements. In this case the offsets have been calculated from the top and left of the page. It is possible to change the parent element that becomes this container and we will take a look at that in the lesson on\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Positioning\">positioning<\/a>.<\/p>\n<\/div>\n<\/section>\n<section aria-labelledby=\"fixed_positioning\">\n<h3 id=\"fixed_positioning\"><a title=\"Permalink to Fixed positioning\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#fixed_positioning\">Fixed positioning<\/a><\/h3>\n<div class=\"section-content\">\n<p>Fixed positioning removes our element from document flow in the same way as absolute positioning. However, instead of the offsets being applied from the container, they are applied from the viewport. Because the item remains fixed in relation to the viewport, we can create effects such as a menu that remains fixed as the page scrolls beneath it.<\/p>\n<p>For this example, our HTML contains three paragraphs of text so that we can scroll through the page, as well as a box with the property of\u00a0<code>position: fixed<\/code>.<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>Fixed positioning<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>positioned<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Fixed<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span> Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\nNulla luctus aliquam dolor, eu lacinia lorem placerat vulputate. Duis felis\r\norci, pulvinar id metus ut, rutrum luctus orci.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span> Cras porttitor imperdiet nunc, at ultricies tellus laoreet sit amet.\r\nSed auctor cursus massa at porta. Integer ligula ipsum, tristique sit amet\r\norci vel, viverra egestas ligula. Curabitur vehicula tellus neque, ac ornare\r\nex malesuada et.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span> In vitae convallis lacus. Aliquam erat volutpat. Suspendisse ac\r\nimperdiet turpis. Aenean finibus sollicitudin eros pharetra congue. Duis\r\nornare egestas augue ut luctus. Proin blandit quam nec lacus varius commodo\r\net a urna. Ut id ornare felis, eget fermentum sapien.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.positioned<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">position<\/span><span class=\"token punctuation\">:<\/span> fixed<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">top<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n    <span class=\"token property\">left<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_fixed_positioning\" class=\"sample-code-frame\" title=\"Fixed positioning sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.fixed_positioning.html\" width=\"100%\" height=\"200\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"sticky_positioning\">\n<h3 id=\"sticky_positioning\"><a title=\"Permalink to Sticky positioning\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#sticky_positioning\">Sticky positioning<\/a><\/h3>\n<div class=\"section-content\">\n<p>Sticky positioning is the final positioning method that we have at our disposal. It mixes static positioning with fixed positioning. When an item has\u00a0<code>position: sticky<\/code>, it&#8217;ll scroll in normal flow until it hits offsets from the viewport that we have defined. At that point it becomes &#8222;stuck&#8221; as if it had\u00a0<code>position: fixed<\/code>\u00a0applied.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.positioned<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">position<\/span><span class=\"token punctuation\">:<\/span> sticky<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">top<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">left<\/span><span class=\"token punctuation\">:<\/span> 30px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_sticky_positioning\" class=\"sample-code-frame\" title=\"Sticky positioning sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.sticky_positioning.html\" width=\"100%\" height=\"200\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<div id=\"sect5\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0To find more out about positioning, see our\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Positioning\">Positioning<\/a>\u00a0article.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section aria-labelledby=\"table_layout\">\n<h2 id=\"table_layout\"><a title=\"Permalink to Table layout\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#table_layout\">Table layout<\/a><\/h2>\n<div class=\"section-content\">\n<p>HTML tables are fine for displaying tabular data, but many years ago \u2014 before even basic CSS was supported reliably across browsers \u2014 web developers used to also use tables for entire web page layouts, putting their headers, footers, columns, etc. into various table rows and columns. This worked at the time, but it has many problems: table layouts are inflexible, very heavy on markup, difficult to debug, and semantically wrong (e.g., screen reader users have problems navigating table layouts).<\/p>\n<p>The way that a table looks on a webpage when you use table markup is due to a set of CSS properties that define table layout. These same properties can also be used to lay out elements that aren&#8217;t tables, a use which is sometimes described as &#8222;using CSS tables&#8221;.<\/p>\n<p>The example below shows one such use. It must be noted, using CSS tables for layout should be considered a legacy method at this point, for those situations where you have very old browsers that lack support for Flexbox or Grid.<\/p>\n<p>Let&#8217;s look at an example. First, some simple markup that creates an HTML form. Each input element has a label, and we&#8217;ve also included a caption inside a paragraph. Each label\/input pair is wrapped in a\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/div\"><code>&lt;div&gt;<\/code><\/a>\u00a0for layout purposes.<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>form<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>First of all, tell us your name and age.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>label <span class=\"token attr-name\">for<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fname<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>First name:<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>label<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>text<span class=\"token punctuation\">\"<\/span><\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fname<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>label <span class=\"token attr-name\">for<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>lname<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Last name:<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>label<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>text<span class=\"token punctuation\">\"<\/span><\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>lname<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>label <span class=\"token attr-name\">for<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>age<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>Age:<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>label<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n    <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>input <span class=\"token attr-name\">type<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>text<span class=\"token punctuation\">\"<\/span><\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>age<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n  <span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>form<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>As for the CSS, most of it&#8217;s fairly ordinary except for the uses of the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/display\"><code>display<\/code><\/a>\u00a0property. The\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/form\"><code>&lt;form&gt;<\/code><\/a>,\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/div\"><code>&lt;div&gt;<\/code><\/a>s, and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/label\"><code>&lt;label&gt;<\/code><\/a>s and\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/input\"><code>&lt;input&gt;<\/code><\/a>s have been told to display like a table, table rows, and table cells respectively. Basically, they&#8217;ll act like HTML table markup, causing the labels and inputs to line up nicely by default. All we then have to do is add a bit of sizing, margin, etc., to make everything look a bit nicer and we&#8217;re done.<\/p>\n<p>You&#8217;ll notice that the caption paragraph has been given\u00a0<code>display: table-caption;<\/code>, which makes it act like a table\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/caption\"><code>&lt;caption&gt;<\/code><\/a>, and\u00a0<code>caption-side: bottom;<\/code>\u00a0to tell the caption to sit on the bottom of the table for styling purposes, even though the markup is before the\u00a0<code>&lt;input&gt;<\/code>\u00a0elements in the source. This allows for a nice bit of flexibility.<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">html<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">font-family<\/span><span class=\"token punctuation\">:<\/span> sans-serif<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> table<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">margin<\/span><span class=\"token punctuation\">:<\/span> 0 auto<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form div<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> table-row<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form label, form input<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> table-cell<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">margin-bottom<\/span><span class=\"token punctuation\">:<\/span> 10px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form label<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 200px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">padding-right<\/span><span class=\"token punctuation\">:<\/span> 5%<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">text-align<\/span><span class=\"token punctuation\">:<\/span> right<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form input<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 300px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n<span class=\"token selector\">form p<\/span> <span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> table-caption<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">caption-side<\/span><span class=\"token punctuation\">:<\/span> bottom<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 300px<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">color<\/span><span class=\"token punctuation\">:<\/span> #999<span class=\"token punctuation\">;<\/span>\r\n  <span class=\"token property\">font-style<\/span><span class=\"token punctuation\">:<\/span> italic<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>This gives us the following result:<\/p>\n<p><iframe loading=\"lazy\" id=\"frame_table_layout\" class=\"sample-code-frame\" title=\"Table layout sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.table_layout.html\" width=\"100%\" height=\"200\" data-mce-fragment=\"1\"><\/iframe>You can also see this example live at\u00a0<a class=\"external\" href=\"https:\/\/mdn.github.io\/learning-area\/css\/styling-boxes\/box-model-recap\/css-tables-example.html\" rel=\" noopener\">css-tables-example.html<\/a>\u00a0(see the\u00a0<a class=\"external\" href=\"https:\/\/github.com\/mdn\/learning-area\/blob\/main\/css\/styling-boxes\/box-model-recap\/css-tables-example.html\" rel=\" noopener\">source code<\/a>\u00a0too.)<\/p>\n<div id=\"sect6\" class=\"notecard note\">\n<p><strong>Note:<\/strong>\u00a0Table layout, unlike the other topics of this page, won&#8217;t be further covered in this module due to its legacy application.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section aria-labelledby=\"multi-column_layout\">\n<h2 id=\"multi-column_layout\"><a title=\"Permalink to Multi-column layout\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#multi-column_layout\">Multi-column layout<\/a><\/h2>\n<div class=\"section-content\">\n<p>The multi-column layout CSS module provides us a way to lay out content in columns, similar to how text flows in a newspaper. While reading up and down columns is less useful in a web context due to the users having to scroll up and down, arranging content into columns can, nevertheless, be a useful technique.<\/p>\n<p>To turn a block into a multi-column container, we use either the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/column-count\"><code>column-count<\/code><\/a>\u00a0property, which tells the browser\u00a0<em>how many<\/em>\u00a0columns we would like to have, or the\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/column-width\"><code>column-width<\/code><\/a>\u00a0property, which tells the browser to fill the container with as many columns as possible of a\u00a0<em>specified width<\/em>.<\/p>\n<p>In the below example, we start with a block of HTML inside a containing\u00a0<code>&lt;div&gt;<\/code>\u00a0element with a class of\u00a0<code>container<\/code>.<\/p>\n<div class=\"code-example\">\n<pre class=\"brush: html notranslate\"><code><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>div <span class=\"token attr-name\">class<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>container<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>Multi-column Layout<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>h1<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla\r\n luctus aliquam dolor, eu lacinia lorem placerat vulputate. Duis felis orci,\r\n pulvinar id metus ut, rutrum luctus orci. Cras porttitor imperdiet nunc, at\r\n ultricies tellus laoreet sit amet. Sed auctor cursus massa at porta.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>Nam vulputate diam nec tempor bibendum. Donec luctus augue eget\r\n malesuada ultrices. Phasellus turpis est, posuere sit amet dapibus ut,\r\n facilisis sed est. Nam id risus quis ante semper consectetur eget aliquam\r\n lorem.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n <span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>Vivamus tristique elit dolor, sed pretium metus suscipit vel. Mauris\r\n ultricies lectus sed lobortis finibus. Vivamus eu urna eget velit cursus\r\n viverra quis vestibulum sem. Aliquam tincidunt eget purus in interdum. Cum\r\n sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus\r\n mus.<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n\r\n<span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>div<span class=\"token punctuation\">&gt;<\/span><\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p>We&#8217;re using a\u00a0<code>column-width<\/code>\u00a0of 200 pixels on that container, causing the browser to create as many 200 pixel columns as will fit. Whatever space is left between the columns will be shared.<\/p>\n<div class=\"code-example\"><\/div>\n<div class=\"code-example\">\n<pre class=\"brush: css notranslate\"><code><span class=\"token selector\">.container<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">column-width<\/span><span class=\"token punctuation\">:<\/span> 200px<span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p><button class=\"icon copy-icon\" type=\"button\"><span class=\"visually-hidden\">Copy to Clipboard<\/span><\/button><\/div>\n<p><iframe loading=\"lazy\" id=\"frame_multi-column_layout\" class=\"sample-code-frame\" title=\"Multi-column layout sample\" src=\"https:\/\/yari-demos.prod.mdn.mozit.cloud\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction\/_sample_.multi-column_layout.html\" width=\"100%\" height=\"250\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/section>\n<section aria-labelledby=\"summary\">\n<h2 id=\"summary\"><a title=\"Permalink to Summary\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction#summary\">Summary<\/a><\/h2>\n<div class=\"section-content\">\n<p>This article has provided a brief summary of all the layout technologies you should know about. Read on for more information on each individual technology!<\/p>\n<\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">source: https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/CSS_layout\/Introduction This article will recap some of the CSS layout features we&#8217;ve already touched upon in previous modules, such as different\u00a0display\u00a0values, as well as introduce some of the concepts we&#8217;ll be covering throughout this module. Prerequisites: The basics of HTML (study\u00a0Introduction to HTML), and an idea of How CSS works (study\u00a0Introduction to CSS.) Objective:&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/2022\/06\/13\/introduction-to-css-layout\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[34,122],"class_list":["post-2457","post","type-post","status-publish","format-standard","hentry","category-bez-kategorii","tag-css","tag-html"],"_links":{"self":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/comments?post=2457"}],"version-history":[{"count":1,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2457\/revisions"}],"predecessor-version":[{"id":2458,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/posts\/2457\/revisions\/2458"}],"wp:attachment":[{"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/media?parent=2457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/categories?post=2457"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/u239160.webh.me\/jakisproblem.pl\/index.php\/wp-json\/wp\/v2\/tags?post=2457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}