Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CSS, can I line up heights of inline-blocks?

Tags:

css

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?

like image 851
Steve Hwan Avatar asked Jun 23 '12 23:06

Steve Hwan


People also ask

Can we set height of inline element?

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.

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.

Can we change the height and width of inline block?

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.

Can inline block have margin?

Inline-block elements are similar to inline elements, except they can have padding and margins added on all four sides.


1 Answers

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.

like image 180
brezanac Avatar answered Sep 19 '22 20:09

brezanac