Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically Align Two Divs [duplicate]

Tags:

html

css

New to everything web-programming wise.

I'm trying to vertically align the two wrapper divs so that they are in the middle of the page, irrespective of the browser. The website can be found here: www.armedwithreason.com/massshooting

I've looked up dozens of tutorials on this very question, and cannot get anything to work. Any ideas?

like image 663
Parseltongue Avatar asked Sep 18 '13 12:09

Parseltongue


People also ask

How do I vertically align two divs?

To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.

How do I vertically align a div inside another div?

Vertically centering div items inside another div Just set the container to display:table and then the inner items to display:table-cell . Set a height on the container, and then set vertical-align:middle on the inner items. This has broad compatibility back as far as the days of IE9.

How do you vertically align elements in CSS?

The vertical-align property in CSS controls how elements set next to each other on a line are lined up. In order for this to work, the elements need to be set along a baseline. As in, inline (e.g. <span> , <img> ) or inline-block (e.g. as set by the display property) elements.


1 Answers

You've set width and height on those two div, then you can use this kind of code :

.wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -170px;
    margin-left: -300px;
}
.wrapper2 {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: 150px;
    margin-left: -300px;
}

With top: 50%; left: 50%, you put the div's top-left corner in the middle, then you ajust its position with /positive/negative margins.

JsFiddle (a basic one with your own style)

like image 187
zessx Avatar answered Oct 07 '22 11:10

zessx