Is there a way to center a div horizontally inside the browser window while maintaining its vertical position? Below is the div in question:
<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>
Here is the corresponding class for the above div:
.ErrorClientSide {
display: none;
position: fixed;
top: 4px;
left: 370px;
padding: 10px 25px 10px 25px;
border-radius: 7px;
}
Note: Color styles have been removed from the class description.
Click here to see it in action. To test it, leave all fields blank and click the Next >> button. A pink error message will appear at the top stating, "Error: All fields are required," but the horizontal alignment may be off.
The issue lies in aligning the divErrorMessage
horizontally within the browser window. The culprit appears to be the position:fixed
property, without which the div disappears entirely. Additionally, the left:370px
positioning seems to cause alignment problems as well.
These are the positioning requirements for the div:
- It should be placed vertically below the brown header at the top of the page.
- Horizontally, it needs to be centered within the browser window.
If solving this with CSS proves difficult, a jQuery solution is also acceptable. However, it is believed that achieving this using CSS alone should be feasible.
Please note: The error message div and content are located inside an iFrame.