Vertically And Horizontally Aligning In Css
I'm having trouble getting my form to align both vertically and horizontally. I don't mind if this doesn't support IE--I plan on implementing an IE detection script to tell the use
Solution 1:
Do you want something like this?
try this css
#login{
position:absolute;
left:50%;
top:50%;
margin-left:-120px;
margin-top:-60px;
border:1px solid #ccc;
width:240px;
height:120px;
}
If you want a form centered vertically and horizontally, you can use css attribute position:absolute; and then use left:50%; top:50% to align the top-left corner of div to center of browser. But your Div will not look centered by this. because it is centered to window by its top left corner. I just used negative margin with half of width and height of div to center it properly.
Hope this is what you are looking for.
Thanks Bojangles, for suggestion !
Solution 2:
Right now your #login div is using 100% of the page width, you need to set a smaller width so it can be centered correctly. And you can center it vertically by setting top to 50% minus div height / 2.
Like this
#login
{
position: relative;
margin-left: auto;
margin-right: auto;
width: 300px;
top: 50%;
margin-top:-50px;
}
Post a Comment for "Vertically And Horizontally Aligning In Css"