Reputation: 633
Again about css layout:
#container{
width:979px;
height:590px;
margin-left:auto; //works
margin-right:auto; //works
margin-top:auto; //doesn't work
margin-bottom:auto; //doesn't work
}
So, I want #container to place in the center of screen.
I also tried: margin:auto - without result.
Upvotes: 2
Views: 3338
Reputation: 11
If u just want the container to place in the center of the screen. try this
CSS:
html, body { margin:0; padding:0; }
#container{
width:979px;
height:590px;
margin:0 auto;
}
HTML
<div id="container">
Data goes here
</div>
Hope this helps
Upvotes: 0
Reputation: 10769
What about something like:
#container{
width:979px;
height:590px;
position:absolute;
left:50%;
top:50%;
margin:-295px 0 0 -490px;
}
Upvotes: 2
Reputation: 616
You should set it manually by padding if you want to do it with css. or else if you want it to be dynamic you should write a javascript like following:-
var a = window.outerHeight;
var b = $('#id of div').height();
var c = (a-b)/2;
$('#id of div').css("margin-top",c);
Upvotes: 2
Reputation: 5217
I think you are looking for vertical centering, there is a blog about how to do that. Hope helpful.
Upvotes: 1
Reputation: 258
Or maybe you can use this solution :
<div class="container">
<div class="block">
<p>Hello world, i'm a vertical align div !</p>
</div>
</div>
div.bloc {
display:inline-block;
vertical-align:middle;
}
Upvotes: 2
Reputation: 21050
If you know the height and width of #container you can do the following:
Upvotes: 1
Reputation: 2121
The best method is to use display: table-cell
and vertical-align: middle
(which doesn't work on IE7-).
Because we don't have your HTML, the best I can do is link you this article which present you all the different method to achieve it.
Upvotes: 1