Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop these divs from overlapping?

Tags:

html

css

I have three divs, within a content div.

Container width 70%. Within that I have -Left, width 20%. -Content, width 60%. -Right, width 20%.

I would like container to take up 70% of the page's width, and the inner ones (left, content, and right) to take up 20%, 60% and 20% of the container div.

I have tried other questions on here, I have tried Google, but can't seem to find the right answer. Please help me stop them from overlapping.

Maximized Browser

But when I re-size the browser, the divs overlap. Like this:

Re-sized Browser

Here's the relevant CSS code:

#container{
    width: 70%;
}
#left {
    float: left;
    width: 20%;
    min-width: 200px;
}
#content {
    float: left;
    width: 60%;
    min-width: 600px;
}
#right {
    float: right;
    width: 20%;
    min-width: 200px;
}
like image 673
Josh Avatar asked Jun 12 '12 06:06

Josh


People also ask

How do I stop DIVS from overlapping?

Just remove the min-width from your CSS! And give min-width to the container with margin: auto to make it center. Save this answer.

Why are my DIVS stacking on top of each other?

It is because inherently objects in HTMK And CSS are stacked on top of each other. If you want to stack them horizontally you will have to use certain CSS Properties. I have two divs side by side.

Why are my DIVS overlapping HTML?

This could happen for several reasons, especially when you consider the position problems with divs from one website to another. Similarly, box elements may overlap for a few reasons, ranging from positioning errors to overflow issues and simple float problems.


2 Answers

Just remove the min-width from your CSS! And give min-width to the container with margin: auto to make it center.

Try this CSS:

#container{
    width: 70%;
    min-width: 1000px;
    margin: auto;
}
#left {
    float: left;
    width: 20%;
}
#content {
    float: left;
    width: 60%;
}
#right {
    float: right;
    width: 20%;
}

Check out fiddle here: http://jsfiddle.net/UaqU7/2/

like image 63
Praveen Kumar Purushothaman Avatar answered Oct 02 '22 03:10

Praveen Kumar Purushothaman


Instead of giving min-width of child DIV's you can give it to #container. Write like this:

#container{
    width: 70%;
    min-width:1000px;
}
#left {
    float: left;
    width: 20%;
}
#content {
    float: left;
    width: 60%;
}
#right {
    float: right;
    width: 20%;
}

Check this http://jsfiddle.net/yLVsb/

like image 27
sandeep Avatar answered Oct 02 '22 03:10

sandeep