I have a div that I want to center horizontally inside my browser window without changing the vertical position. Here's my div:
<div id="divErrorMessage" class="ErrorClientSide">
<div class="ui-icon ui-icon-info" style="float: left; margin-right: 6px;"></div>
<div id="divErrorMessageText" style="margin-left: 6px;margin-top: 2px;">{ERROR MESSAGE HERE}</div>
<img src="./Images/Icons/tinyx.png" style="position: absolute; top: 4px; right:4px; cursor:pointer" onclick="closeErrorMessage();" />
</div>
And here's the class:
.ErrorClientSide {
display: none;
position: fixed;
top: 4px;
left: 370px;
padding: 10px 25px 10px 25px;
border-radius: 7px;
}
Note: I removed the color styles and such from the class above for brevity.
Try it out here. Instructions: Leave all boxes blank and just click the Next >> button. You should see a pink error message div appear at the top that says "Error: All fields are required.", but the horizontal positioning is way off.
Problem: I cannot center divErrorMessage
horizontally in my browser window. I'm pretty sure that position:fixed
is the problem, but if I remove that, my div disappears and I can't find it. left:370px
is clearly a problem as well. If I remove that, the div aligns at the left of the browser and I can't find any way to center it.
Here are my only positioning requirements for this div:
- It needs to be positioned vertically a little below the brown header at the top.
- It needs to be horizontally centered in the browser window.
If CSS can't do this easily I would be happy for a jquery solution as well, but I'm guessing this should be easy with CSS.
Important note: The error message div and much of the content is inside an iFrame.