In CSS, can I line up heights of inline-blocks?
I thought by setting margins to 0 and height to auto, that the block would expand to fit the available space, but it still tightly wraps around the block.
.myclass { display: inline-block; margin: 0em; padding: 1em; height: auto; border: solid; }
http://jsfiddle.net/6NQDw/
I would like both boxes to be the same height, but want the div width/heights to be determined by their content, not specifying a width/height in pixels.
Is there some kind of padding/margin/alignment CSS or something like that that I can use?
Inline element properties: The height of an inline element is the height of the content. The width of an inline element is the width of the content. The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS.
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.
You can't set the width or height. inline-block It's formatted just like the inline element, where it doesn't start on a new line. BUT, you can set width and height values. block The element will start on a new line and occupy the full width available.
Inline-block elements are similar to inline elements, except they can have padding and margins added on all four sides.
You could use display:table-cell;
if you require a pure CSS solution but do take note that it won't work in IE7 (I guess IE6 is by now completely forgotten).
.myclass { display: table-cell; margin: 0em; padding: 1em; height: auto; border: solid; }
Cross browser support for display:table-cell
Your best bet for achieving what you need is JavaScript however explicitly setting width of containers with dynamic content is almost always not the right way to solve the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With