I wondered how to center any element horizontaly (ie. DIV). When I do this in CSS, it works in IE but not in Mozilla. I don't know how to set height to 100%.
.myElement {
width: 100%;
height: 100%;
text-align: center;
vertical-align: middle;
}
<body>
<div class="myElement">
someText
</div>
</body>
Element height: 100%
-
- Posts: 634
- Joined: November 5th, 2002, 5:35 am
- Location: The Netherlands, when not travelling
margin-left: auto;
margin-right: auto;
for centering blocks.
set a height: 100% on the body to get the element to take up the full height. (but then you'll need to set padding and margin on the body to 0 to prevent scrollbars, and then if you want margin / padding again you'll need to use the children for that.
(The DOM-Inspector, btw, is your friend. It would've told you that the body's height wasn't taking up the entire screen.)
margin-right: auto;
for centering blocks.
set a height: 100% on the body to get the element to take up the full height. (but then you'll need to set padding and margin on the body to 0 to prevent scrollbars, and then if you want margin / padding again you'll need to use the children for that.
(The DOM-Inspector, btw, is your friend. It would've told you that the body's height wasn't taking up the entire screen.)