Premium Features

Download Video

Display Block, Inline-Block, Inline, and None

Published 3 months ago

Display properties determine how your elements are displayed in the browser. By default, most elements have a display of block, but many others use inline natively instead.

An element with a display block will take up the entire width of its parent container by default. It acts as a "block" that pushes any content that would be next to it, beneath it. Block elements are useful for separating content into groups, and allow for usage of margin properties on their top and bottom sides.

An element with a display of inline will be placed next to other inline elements, as it does not take up the entire width of its parent element - it only takes up the exact amount of space of the content inside of it. An example of an element that is inline by default is the anchor tag: <a></a>. Anchor tags are used to link to other websites and are commonly placed in large bodies of text such as paragraphs. Since the anchor tag has a display of inline, it will be placed "inline" with whatever paragraph text it is associated with, so that the text still flows, but the element possesses the attribute of being able to link elsewhere.

Elements with a display of inline-block only take up the exact amount of space that the content inside of them consist of, but allow you to use margin properties to manipulate the amount of spacing between that element and the text around it.

Finally, elements with display none aren't rendered at all within the browser. They're typically used on elements that aren't supposed to show until a later point in time such as pop-ups and dropdowns. You wouldn't want a pop-up rendered on the screen at all times, you'd only want it rendered when it's ready to be displayed. Therefore, it's safe to put a display of none on the element, then when it's ready, apply a display of block with JavaScript to get the element showing on the screen.

Your code should look like the following at the end of this lesson:

index.html
<style>
  body {
    margin: 0;
  }

  .bg-gray-900 {
    background-color: #121826;
  }

  .text-white {
    color: white;
  }

  .block {
    display: block;
  }

  .inline-block {
    display: inline-block;
  }

  .inline {
    display: inline;
  }

  .hidden {
    display: none;
  }
</style>

<header class="bg-gray-900">
  <div>
    <img src="" alt="" />
    <a href="" class="text-white block">Pricing</a>
    <a href="" class="text-white">Courses</a>
    <a href="" class="text-white hidden">Blog</a>
    <a href="" class="text-white">Forum</a>
  </div>
  <div>
    <a href="" class="text-white">Login</a>
    <button>Sign Up</button>
  </div>
</header>

Comments

Want to participate?

Create a free Chris Courses account to begin

Login

No comments yet, be the first to add one

Cheat Sheet Preview

Download The Official Chris Courses HTML5 Canvas Cheat Sheet

Essential canvas syntax at your fingertips.

Download Now

Providing the lift to launch your development career

© 2021 Chris Courses. All rights reserved.