Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML CSS div floating left goes under , below div floating right?

I'm hoping someone can help me: I have a left column container #left-column, with a float:left; and some elements (slideshow, images, text) floating on the right. Everything is placed in the main container which has a width value of 990px; The left column is 240px, while all the elements on the right have widths which are enough to fit on the right side (720px). Here is a graphic of what is happening:

What can I do to solve this ? My guess is that there is something to do with the slideshow div...

Left column floats to left; all the other elements (slideshow, images, text) are floating to the right. The left column goes under the slideshow for some reason...

#main-container {
    width:990px;
    margin:8px auto;
}
#left-column {
    width:240px;
    float:left;
}
#slideshow {
    float:right;
    width:720px;
    height:300px;
}
a.image {
    float: right;
    display:inline-block;
}
.text {
    float:right;
    width:720px;
}

What should I do ? MANY thanks...!!

EDIT - When I put a position:asbolute to the left-column container, it goes straight up to the top, which looks fine , but this is not the solution I'm looking for.

like image 921
mlclm Avatar asked Nov 19 '13 15:11

mlclm


People also ask

How float left and right in div?

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.

How do you float left and right in CSS?

How do you float an image in CSS? Let's say you want an image to float to the right of the text in a container. You can use a type selector to target the image and define it with the rule float: left or float: right.

Why is my div not floating left?

You need to float the blocks on the right side not push them over with left margin. Set them to float: right and they'll kick up where you want them. Until you float the elements they want to take up the full width of their parent container.

How do you float left and right in HTML?

Introduction to HTML Float Left. Alignment of the elements for building the HTML webpage is one of the most important tasks. This can be done by using one of the CSS property called float with its position value. Float property can be used with values as Right, Left, none, inline-start, inline-end.


1 Answers

Difficult to understand specifically for your context without the HTML, but here is a global idea : you generally don't need to put float: left; for left column, and float: right; for right column, even if it seems logical for you.

An easier and more reliable way would be to put all your elements that will be next to each other on float: left; (so the right column would be floating left, just near the left column)

With your image, I would do something like that :

<div id="leftColumn">
</div>
<div id="rightColumn">
    <div id="slideshow"></div>
    <div id="imgWrapper">
        <div class="imgDiv"></div>
        <div class="imgDiv"></div>
    </div>
    <div id="text"></div>
</div>


#leftColumn {
    float: left;
    overflow: hidden;
}

#rightColumn {
    float: left;
    overflow: hidden;
}

.imgDiv {
    float: left;
    overflow: hidden;
}

#imgWrapper { overflow: hidden; }
like image 183
Jérémy Dutheil Avatar answered Nov 15 '22 12:11

Jérémy Dutheil