Reputation: 1635
Can someone help me to get div id "loader" to float in the center of div class "Window". Thanks.
<div id="someid" class="Window">
<div id="loader"></div>
</div>
UPDATE* I need to center it in the absolute middle of a block. Lets say class "Window" was 400px high. How do I get "loader to float in the center (height/width) of that?
Upvotes: 5
Views: 16077
Reputation: 3495
#someid {
width:200px;
height:200px;
}
#loader {
position: relative;
height:80px;
width: 80px;
top: 50%;
margin-top: -40px; /* half of the height */
margin-left: auto;
margin-right: auto;
}
Upvotes: 0
Reputation: 92803
write this:
.window{
height:400px;
width:400px;
background:red;
vertical-align:middle;
line-height:400px;
text-align:center;
}
#loader{
width:20px;
height:20px;
background:green;
display:inline-block;
vertical-align:middle;
}
Check this http://jsfiddle.net/dxPfz/
Upvotes: 0
Reputation: 3345
Apply the following CSS to "loader":
where {E} is half the height of "loader"
Hope this helps.
Upvotes: 7
Reputation: 3097
Add this to your css:
#loader {
width: 123px;
margin:0 auto;
}
This will make your left and right margins be calculated automatically.
Upvotes: 0
Reputation: 11779
#someid.Window{
// give this some width
width: 100%
}
#loader{
// give width and margin auto on the sides
width: 100px;
margin: 0 auto;
}
Upvotes: 3