# I have a very basic CSS question! :]

## Recommended Posts

<html>
<body>
<div style="background-color:red;position:absolute;width:400px;top:50%">
[non-breaking-space]
<div style="background-color:blue;width:50px;position:relative;top:-50%;">
[non-breaking-space]
</div>
[non-breaking-space]
</div>
</body>
</html>


Aparently, in Firefox, if an element isn't absolute:positioned, you can't use percentage units with the top property. It's frustrating! I'm trying to vertically center images (yes, the above code is incomplete, but it demonstrates my point about percentage units); is there a work-around? EDIT: I'm sorry for the initial post; I wasn't quite sure how I was supposed to post HTML! [Edited by - iaminternets on October 24, 2008 9:52:39 PM]

##### Share on other sites
Is there any reason for that div to have absolute positioning? (I'm by far no web expert but) I don't see any reason for that to have absolute positioning.

Anyway, first google result right here:

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

Let me know if that helps ;-)

##### Share on other sites

I'll probably just end up using the solution that article provided, but why won't 'top' accept a percentage value if the element isn't absolutely positioned?

## Create an account

Register a new account