Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical align bottom + inline block

I have the following HTML structure

<div class = "box">
  <div class="box1 item"></div>
  <div class="box2 item"></div>
  <div class="box3 item"></div>
  <div class="box4 item"></div>
</div>

box1 -> box4 has a display of inline-block.

.box {
   min-height: 403px;
}
.item { 
   display: inline-block;
   vertical-align: bottom;
   max-width: 20%;
}

For some reason, I cannot vertically align the divs with class "item" to the bottom of the box container. Does anyone know why?

Each element with class name item is part of a carousel that bleeds to the next page. Meaning each page shows 3.5 images.

like image 561
Chris Hansen Avatar asked Feb 16 '26 22:02

Chris Hansen


1 Answers

vertical-align: bottom aligns inline-level elements to the bottom of their line box.

.box {
  min-height: 403px;
  border: 1px solid blue;
}
.item { 
  display: inline-block;
  vertical-align: bottom;
  border: 1px solid;
}
<div class="box">
  <div class="box1 item">1<br />1<br />1<br />1</div>
  <div class="box2 item">2<br />2<br />2</div>
  <div class="box3 item">3<br />3</div>
  <div class="box4 item">4</div>
</div>

If you want to align them to the bottom of the container, you need more advanced layouts, like CSS tables, or flexbox:

.box {
  display: flex;
  align-items: flex-end;
  min-height: 403px;
  border: 1px solid blue;
}
.item { 
  border: 1px solid;
}
<div class="box">
  <div class="box1 item">1<br />1<br />1<br />1</div>
  <div class="box2 item">2<br />2<br />2</div>
  <div class="box3 item">3<br />3</div>
  <div class="box4 item">4</div>
</div>
like image 60
Oriol Avatar answered Feb 19 '26 11:02

Oriol