bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/CSS/CSS Foundations
CSS•CSS Foundations

CSS display: inline-block

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind CSS display: inline-block?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

display: inline; /* the default ___ span */
3Order

Put the learning moves in the order that makes the concept easiest to apply.

An element with display: inline-block will appear on the same line as other inline or inline-block elements.
The display: inline-block property combines the features of both inline and block elements.
The CSS display: inline-block

The CSS display: inline-block

The display: inline-block property combines the features of both inline and block elements.

An element with display: inline-block will appear on the same line as other inline or inline-block elements. In addition, you can set the width , height , margin-top , and margin-bottom properties for the element (like block elements).

The following example shows the different behavior of display: inline , display: inline-block and display: block :

Example

Formatted code
span.a {
  display: inline; /* the default for span */
  padding: 5px;
  border: 2px solid red;
}
span.b {
  display: inline-block;
  width: 100px;
  height: 35px;
  padding: 5px;
  border: 2px
  solid red;
}
span.c {
  display: block;
  width: 100px;
  height: 35px;
  padding: 5px;
  border: 2px solid red;
}

Live preview

Create a Horizontal Navigation Menu

A common use for display: inline-block is to display list items horizontally instead of vertically. The following example creates a horizontal navigation menu:

Example

Formatted code
.nav {
  background-color: lightgray;
  list-style-type: none;
  padding: 0;
  margin: 0;
} .nav li {
display: inline-block;
font-size: 18px;
padding: 15px;
}

Live preview

CSS Property

PropertyDescription
displaySpecifies the display behavior (the type of rendering box) of an element

Previous

CSS clear and Clearfix Hack

Next

CSS Center Align