Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

CSS Layout – display: inline-block

The display: inline-block Value

When compared to display: inline, the notable distinction is that display: inline-block permits setting both width and height for the element.

Additionally, top and bottom margins/paddings are respected with display: inline-block, unlike display: inline where they are not.

In contrast to display: inlinedisplay: inline-block does not introduce a line break after the element, allowing it to sit adjacent to other elements.

The subsequent example illustrates the contrasting behaviors of display: inlinedisplay: inline-block, and display: block.

Example

span.a {
  display: inline; /* the default for span */
  width: 100px;
  height: 100px;
  padding: 5px;
  border: 1px solid blue; 
  background-color: yellow; 
}

span.b {
  display: inline-block;
  width: 100px;
  height: 100px;
  padding: 5px;
  border: 1px solid blue; 
  background-color: yellow; 
}

span.c {
  display: block;
  width: 100px;
  height: 100px;
  padding: 5px;
  border: 1px solid blue; 
  background-color: yellow; 
}

Using inline-block to Create Navigation Links

A prevalent application of display: inline-block is to present list items horizontally rather than vertically. The ensuing example demonstrates the creation of horizontal navigation links:

Example

.nav {
  background-color: yellow;
  list-style-type: none;
  text-align: center; 
  padding: 0;
  margin: 0;
}

.nav li {
  display: inline-block;
  font-size: 20px;
  padding: 20px;
}