tags:

views:

69

answers:

4

Hi,

I have created two rounded corner boxes which i would like to be aligned next to each other .But the 2nd box is appearing directly below the first one inspite of me using float:left on the 1st one. Any way to fix this would be really helpful. Below are the html and the css.

The HTML :

<html>
    <head>
     <title>Homepage</title>
     <link rel="stylesheet" href="layout.css"/>
    </head>

    <body>

     <div id="containerDiv"> 

                    <!-- Box 1 -->

      <div id="box1" class="boxDiv">
       <div class="upperRound"></div>
       <div class="boxTagLine">
         Some Tag Line
       </div>
       <div class="boxContent">
        Heres some content
       </div>
       <div class="lowerRound"></div>
      </div>

      <!-- Box 2 -->

      <div id="box2" class="boxDiv">
       <div class="upperRound"></div>
       <div class="boxTagLine">
         Some Tag Line
       </div>
       <div class="boxContent">
        Heres some content
       </div>
       <div class="lowerRound"></div>
      </div>

     </div>


    </body>
</html>

The CSS :

#containerDiv {
    width: 1000px;

}
.boxDiv {
    width: 248px;
}
.upperRound {
    background-image: url('rounded_upper.gif');
    height: 20px;
}

.lowerRound {
    background-image: url('rounded_lower.gif');
    height: 20px;
}

.boxContent,.boxTagLine {
    border-left: 2px solid #B5B5B5;
    border-right: 2px solid #B5B5B5;
    padding: 10px;
    background-color:#F8F8F8;
    solid #B5B5B5;

}

.boxTagLine {
    color:#0066FF;
}

#box1 {
    float:left;
}
+1  A: 

Second div must float to right and next element should clear float. I'll add more info in a second.


I was a bit wrong. You even don't need clearing div.

Check out this question.


So - in your case, add this to css=>

#box2 {
    float:right;
}

#containerDiv {
    width: 1000px;
    overflow: hidden;
}

I didn't try it, but it should work.


Mine approach will leave space between boxes. So - it might be not desired effect.

Arnis L.
A: 

You would be better off using spans

But if you have to use divs :

.boxDiv {
    width: 248px;
    display: inline;
}
Nick Brooks
Even better approach, if this works. :)
Arnis L.
A: 

float both boxes left:

#box1,#box2 {
    float:left;
}
Paul
A: 

You'd be better off floating your .boxDiv left, like so:

.boxDiv {
    width: 248px;
    float: left;
}

That way if you add more boxes they'll float straight away, otherwise you'd have add the specific class names:

#box1, #box2, #box3, #box4 {
    float:left;
}
Jonny Haynes