作者:独孤依人x_762 | 来源:互联网 | 2023-05-18 01:25
IhaveadivthatIwanttocenterhorizontallyinsidemybrowserwindowwithoutchangingthevertic
I have a div that I want to center horizontally inside my browser window without changing the vertical position. Here's my div:
我有一个div,我想在浏览器窗口中水平居中,而不改变垂直位置。这是我的div:
{ERROR MESSAGE HERE}
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.
在这里尝试一下。说明:将所有框留空,只需单击下一步>>按钮。您应该会在顶部看到一个粉红色的错误消息div,显示“错误:所有字段都是必需的。”,但水平定位是关闭的。
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.
问题:我无法在浏览器窗口中水平居中divErrorMessage。我很确定这个位置:修复是问题,但是如果我删除它,我的div消失了,我找不到它。左:370px显然也是一个问题。如果我删除它,div在浏览器的左边对齐,我找不到任何方法来居中它。
Here are my only positioning requirements for this div:
以下是我对此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.
如果CSS不能轻易做到这一点,我也很乐意使用jquery解决方案,但我猜这应该很容易用CSS。
Important note: The error message div and much of the content is inside an iFrame.
重要说明:错误消息div和大部分内容都在iFrame中。
6 个解决方案