šŸ“• Build AI Agents using LangGraph.js is now out!

Fixing the CSS inline-block elements with text pushed downward

While working on the example for selecting all elements between two CSS classes I remembered a problem we had some while ago when working with inline-block elements that where containing text.

The problem

If we have a set of elements with the display property set to inline-block, and some elements are empty while some have text, then the elements containing text will be pushed downward.

See the below example:
CSS inline-block elements with text pushed downward

The same will happen if we use inline-grid or inline-flex.

The solution

So, why are CSS inline-block elements containing text pushed downward? Well, because the default value for vertical-align in CSS is baseline. And, when we have text this goes sideways.

So, what we need to do is to revert this by adding vertical-align:top avoiding those elements with text to be pushed downward:

div {
    display: inline-block;
    vertical-align:top;
    /* rest of the syling here */
}

CSS inline-block elements with text pushed downward

Checkout full code on GitHub, and you can play with the final live example here.

šŸ“– Build a full trivia game app with LangChain

Learn by doing with this FREE ebook! This 35-page guide walks you through every step of building your first fully functional AI-powered app using JavaScript and LangChain.js

šŸ“– Build a full trivia game app with LangChain

Learn by doing with this FREE ebook! This 35-page guide walks you through every step of building your first fully functional AI-powered app using JavaScript and LangChain.js


Leave a Reply

Your email address will not be published. Required fields are marked *