Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My inline-block elements are not lining up properly

Tags:

html

css

All of the elements within .track-container should line up nice and in line, each side by side, constrained by the 200px height they've been given with no weird margins or padding. Instead, you have the strangeness that occurs in the aforementioned fiddle.

What is causing .album-artwork and .track-info to get pushed halfway down the page, and how can I fix it? Also, I acknowledge that a table may be a better way of approaching this whole setup, but I want to figure out the problem from the code above so I can learn from this mistake.

.track-container {      padding:0;      width: 600px;      height: 200px;      border: 1px solid black;      list-style-type: none;      margin-bottom: 10px;  }    .position-data {      overflow: none;      display: inline-block;      width: 12.5%;      height: 200px;      margin: 0;      padding: 0;      border: 1px solid black;  }    .current-position, .position-movement {      height: 100px;      width: 100%;      margin: 0;      padding: 0;      border: 1px solid black;  }    .album-artwork {      display: inline-block;      height: 200px;      width: 20%;      border: 1px solid black;  }    .track-info {      display: inline-block;      padding-left: 10px;      height: 200px;      border: 1px solid black;  }
<div class="track-container">      <div class="position-data">          <div class="current-position">1</div>          <div class="position-movement">2</div>      </div>      <div class="album-artwork">fdasfdsa</div>      <div class="track-info">fdafdsa</div>  </div>

Here's a JSFiddle.

like image 561
user1427661 Avatar asked Oct 14 '13 18:10

user1427661


People also ask

How do you align inline block elements?

To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.

How do you make elements stay on the same line?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do I center an inline block list?

Just give the list centered text (e.g. ul. nav { text-align: center; } ) and the list items inline-block (e.g. ul. nav li { display: inline-block; } ). If you want to do it with margin for whatever reason, look into width: fit-content; .

How do you make inline blocks not wrap?

We apply the white-space: nowrap; property to class “a” which keeps the line of text in the same line even if the screen size is small. Syntax: white-space: nowrap; Next, we apply white-space: normal; which is the default for “white-space”.


1 Answers

10.8 Line height calculations: the 'line-height' and 'vertical-align' properties

The baseline of an 'inline-block' is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its 'overflow' property has a computed value other than 'visible', in which case the baseline is the bottom margin edge.

This is a common issue involving inline-block elements. In this case, the default value of the vertical-align property is baseline. If you change the value to top, it will behave as expected.

Updated Example

.position-data {     vertical-align: top; } 
like image 106
Josh Crozier Avatar answered Oct 13 '22 06:10

Josh Crozier