Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display:inline resets height and width

Tags:

I have created example at http://jsfiddle.net/GKnkW/2/

html

<!DOCTYPE html> <html> <head>     <title>Test</title>  </head> <body>       <div class="step">1</div>&nbsp;       <div class="step">2</div>       <br/><br/>       <div class="step1">3</div>&nbsp;       <div class="step1">4</div> </body> </html>  

css

.step {     height:150px;     width:150px;         background:yellow;     display:inline; }  .step1 {     height:150px;     width:150px;         background:yellow; } 

I want to display two divs side by side with their original height and width ( set in css ) as soon as i add display:inline property to css it seems to loose height and width defined earlier. [ check divs with # 1 and #2 which seems to loose height and width setting ]

can some one pin point an error which I seems to be doing or workaround for this weird behavior ?

like image 844
N30 Avatar asked Apr 22 '11 20:04

N30


People also ask

Can a display inline have width and height?

inline The element doesn't start on a new line and only occupy just the width it requires. 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.

What is the deal with display inline-block?

The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.

What does display inline do?

display: inlineAn element with a display property set to inline will not start on a new line and it will take up the remaining/available screen width. It just takes up the space such an element would normally take.

Is display flex block or inline?

Container with display:flex behaves like a block-level element itself, while display:inline-flex makes the container behaves like an inline element.


1 Answers

Inline objects don't have heights or widths. Why are you setting them inline to begin with? You probably want to either float them or use display: inline-block.

like image 81
DA. Avatar answered Oct 06 '22 00:10

DA.