Git Product home page Git Product logo

css-display's Introduction

CSS Display

Learning Goals

  • The default display behavior of different elements.
  • How to adjust the way an element displays.

Introduction

This lesson will discuss the way different elements will display in the browser. We will focus on the difference between inline and block elements, as well as how to change the display property.

Make sure to check out the code example in the Resources section to see how these properties work!

Element Display

All elements in the browser have a default display behavior. We will focus on the two most common, inline and block. Later lessons demonstrate other display values such as table and table-cell among others.

Block Elements

Block level elements are king of the horizontal space, meaning they take up all of the horizontal space by default. They stretch 100% wide unless we set the width property to something else. They always stack vertically by default. Their height can bet set, but by default they will scale to the height of their inner content. Some examples of commonly used block elements are:

<div>...</div>
<h1>...</h1>
<h2>...</h2>
<h3>...</h3>
<h4>...</h4>
<h5>...</h5>
<h6>...</h6>
<p>...</p>
<ul>
  <li>...</li>
</ul>
<ol>
  <li>...</li>
</ol>

Inline Elements

Inline level elements can coexist side by side sharing the horizontal space. They can't have a width or top and bottom margins set on them. Their size will only be as wide and tall as their inner content. Some examples of commonly used inline elements are:

<img />
<a>...</a>
<span>...</span>
<input />

Display Property

We can set the display property to adjust the way an element displays (overriding its default display).

display: inline

display: block

For example we could set a div to display inline or a span to display block thus changing their default orientation.

Conclusion

In this lesson, you have learned about the different ways of controlling how elements are displayed using CSS. To summarize:

  • All elements in the browser have a default display value.
  • Block elements stack vertically. They are 100% wide by default and accept width values so you can set their width. They also accept margin on all sides.
  • Inline elements stack horizontally and ignore width and margin values. They are only as wide and tall as their content.
  • We can set the display property on elements to either: inline or block to change their default display to another set of rules.

Resources

css-display's People

Contributors

alveem avatar annjohn avatar ihollander avatar jongrover avatar lizbur10 avatar samegel avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

fs-academy-xi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.