Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right div on float:right appears a line below the left one

Here's my problem.

I have a wrapper div(width: 800px and height: 250px) which contains two divs occupying all the space in height and dividing their width in half.

I set up my css, float the right div to float: right and this one appears where it should but "below" the other one, exceeding the wrapper div space(which shouldn't even be possibile).

I'm posting both the jdfiddle and the code.

JS Fiddle http://jsfiddle.net/FV9yC/

HTML

<div id="wrapper">
    <!-- left div -->
    <div id="leftDiv">
        <h1>This is my heading</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>
    <!-- right div -->
    <div id="rightDiv">
        <h1>This is my heading</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>
</div>

CSS

#wrapper {
    background-color: grey;
    height: 200px;
    width: 500px; }

#leftDiv {
    background-color: purple;
    height: 200px;
    width: 250px; }

#rightDiv {
    background-color: green;
    float: right;
    height: 250px;
    width: 250px; }
like image 807
daghene Avatar asked Jul 08 '13 11:07

daghene


People also ask

How do I float a div to the right?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

Why is my div on the left?

It means that the div will spread on the entire width of the page. Try deleting this width attribute, and beside that delete all float attributes.


1 Answers

Just shift the div with ID rightDiv above the div with ID leftDiv. That's it.

Here is the WORKING SOLUTION

The Code:

<div id="wrapper">
    <!-- right div -->
    <div id="rightDiv">
        <h1>This is my heading</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>    
    <!-- left div -->
    <div id="leftDiv">
        <h1>This is my heading</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    </div>
</div>
like image 114
Nitesh Avatar answered Nov 02 '22 06:11

Nitesh