Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 divs both 100% next to each other

Quite simple question but tried about everything.

what i want is 2 (actually 5) divs next to eachother with the class "container" so i can make a horizontal 1page website. Each div has to be 100% wide. so 2 divs mean 2 screens next to eachother.

This is the css line i have now:

.container { width: 100%; float: left; display: inline; }

I cant get them to line up next to each other.

Here is a visual to make it more clear. enter image description here image url for bigger preview: http://www.luukratief.com/stackoverflow.png

The scrolling part is not the issue for me, just the placement of the divs.

Is this possible using percentages or is this simply not possible. If so, please tell me how to do this with css.

Thanks in advance!

like image 886
Luuk Avatar asked Jul 06 '11 14:07

Luuk


People also ask

How do I align two divs next to each other?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How do I put 4 divs next to each other?

you can use flex property for, Display:flex apply flex layout to the flex items or children of the container only. So, the container itself stays a block level element and thus takes up the entire width of the screen. ...

Why my divs are overlapping?

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.

Can we place two div blocks at same line?

The problem of aligning 2 divs horizontally: Since <div> tag is a block element, only one div can be placed in a line, and all the space to the left and right is taken by it.


1 Answers

You can make a container with 200% width and then put two divs inside of that element with 50% width so you will make sure that one div always gets the whole visitors screen width.

For example:

<div class="container">
    <div class="contentContainer"></div>
    <div class="contentContainer"></div>
</div>

And CSS:

.container {
    width: 200%;
}

.contentContainer {
    width: 50%;
    float: left;
}
like image 61
Johan Davidsson Avatar answered Sep 26 '22 23:09

Johan Davidsson