【发布时间】:2016-06-25 19:28:38
【问题描述】:
我有一个带有 CSS 代码的简单 HTML 页面。
当我调整窗口大小(从大到小)并左右滚动页面时,文本“This is working OK”保持在其位置。它已修复并且工作正常。
但是如果我左右滚动页面,文本“这不正常”将不会居中。这是主要问题。即使在左右滚动页面后,此 div 也应始终水平居中并位于页面底部 - 而不是位于屏幕底部。
<div style="width: 1050px;
top: 0;
left: 50%;
margin-left: -525px;
position: fixed;
z-index: 10;">
This is working OK
</div>
<div style="white-space: nowrap;
margin-left: auto;
margin-right: auto;
margin-top: 150px;
overflow: visible;">
Here is text which is so long that a horizontal scrollbar will be needed for the browser window
</div>
<div style="clear: both;
position: relative;
overflow: hidden;
width: 1050px;
margin-left: auto;
margin-right: auto;">
<div style="position: relative; clear: both;">
<div style="clear: both;
width: auto;
margin-left: 30px;
margin-right: 30px;">
This is not working OK
</div>
</div>
</div>
那么,我该如何修复代码?
【问题讨论】:
-
那么问题出在哪里?这个做什么/不做什么,你需要它做什么/不做什么?
-
向左或向右滚动页面后,第三个 div 未水平居中。
-
单独在 div3 上会使其居中对齐现在原问题已经修改了。您有什么需求可以在这里解释一下吗?请留下其他工作正常的人。