我环顾四周,似乎无法找到解决问题的方法。
底部的两个div为何在Windows 8上以左右完美的一半被切开,但是在我的android s5上却没有居中?http://danny4help.com/
#grad4_left img {
height: 100%;
width: 100%;
border-radius: 10px 0px 0px 10px;
}
#grad4_right {
z-index: inherit;
height: 700px;
background-color: #F1EEF7;
top: 705px;
width: 50%;
left: 50%;
text-align: center;
font-size: 80px;
line-height: 40px;
color: #4A4A4A;
}
.grad#grad4_left {
z-index: inherit;
height: 700px;
background-color: black;
top: 705px;
right: 50%;
color: #4A4A4A;
width: 50%;
}
You have several divs
that have fixed widths in pixels, both above and below the incorrectly centered divs
. These divs
are wider than the body, so the viewport automatically expands to show the full width of those elements, making it seem as though your divs
are incorrectly centered. Simply replace the pixel units of the width
of the too wide divs
with either percents of viewport units and you'll be good to go (e.g., .grad
has a width of 1280px
. Change that to 100vw
). For a quick and dirty fix, add this block to the top:
* {
max-width: 100vw;
}
编辑:其他一些答案建议您不要在响应式布局中使用绝对定位。使用position: absolute
实际上是OK,只要你使用的是相对单位(例如%
,em
,vw
),而不是固定的单位(例如px
,in
,pt
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句