29

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 ?

svick
  • 236,525
  • 50
  • 385
  • 514
N30
  • 3,463
  • 4
  • 34
  • 43

4 Answers4

55

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.

Shayan
  • 709
  • 1
  • 15
  • 31
DA.
  • 39,848
  • 49
  • 150
  • 213
  • was not aware of the inline object's behavior. thanks for the enlightenment. changing the display property to inline-block resolves the issue. – N30 Apr 22 '11 at 20:09
  • dang!! can't accept answer before 11 minutes..will mark your answer as accepted after that.. – N30 Apr 22 '11 at 20:10
15

Use this:

display:inline-block;
Undo
  • 25,519
  • 37
  • 106
  • 129
Moe Mamdouh
  • 195
  • 1
  • 4
1

Just adding that I had a similar problem and thought it was a Javascript/Jquery issue. This thread solved for me.

INLINE elements have no width, so you cannot set it via js.

Thanks.

Here's a link to my issue just in case.

Jquery and Jqueryui: set width not working after using resizable?

Community
  • 1
  • 1
noderman
  • 1,934
  • 1
  • 20
  • 36
1

This should do it

html

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
 </head>
    <body>
      <div class="step-section">
          <div class="step">1</div>
          <div class="step">2</div>
      </div>
      <div class="step-section">
          <div class="step">3</div>
          <div class="step">4</div>
      </div>
</body>
</html> 

css

.step
{
    margin:5px;
    height:150px;
    width:150px;    
    background: yellow;
    float:left;
}

.step-section
{
  clear:both;
}
Racter
  • 252
  • 1
  • 3
  • 15