CSS Layout - The inline-block Value
The display: inline-block value is a powerful tool for CSS layout, combining the best features of inline and block elements.
Comparing Display Values
Compared to display: inline, the major difference is that display: inline-block allows you to set a width and height on the element.
Compared to display: block, the major difference is that display: inline-block does not add a line-break after the element, so the element can sit next to other elements.
Use Case: Navigation Links
inline-block is a great choice for creating a horizontal navigation bar where you want each link to have a specific width, padding, and margin, while still flowing horizontally.
Example
css
.nav-link {
display: inline-block;
width: 120px;
height: 40px;
padding: 10px;
text-align: center;
background-color: lightgray;
}Test Yourself with an Exercise
What is the main advantage of `display: inline-block` over `display: inline`?