CSS绝对垂直中心与像素偏移

夹克

我的页面背景固定。该页面有3个绝对定位的div设置为混合模式。在这3个div上(针对内容),我浮动了3个相同的div,但没有混合模式或背景色。我想按顺序排列这些div,一个在顶部,一个在底部,一个在底部。我尝试使用margin-top偏移div的高度,但这使所有内容都离顶部太远了,以致于无法再垂直居中。距离很近,但距离还不够远!

混合模式的问题意味着我无法设置父div来控制子代的位置,因为这样会丢失混合模式。我尝试用混合模式寻找解决父级情况的方法,但似乎找不到任何可靠的方法。

有没有解决的办法?

这是我的HTML:

<img src='http://www.pptback.com/uploads/blue-world-map-backgrounds-powerpoint.jpg' alt='background' id='bg' class='noselect' />
<div class='top-bg'></div>
<div class='main-bg'></div>
<div class='foot-bg'></div>
<div class='top-content'>This is the top</div>
<div class='main-content'>This is the main content</div>
<div class='foot-content'>This is the foot</div>

这是我的CSS

 #bg {position:fixed; min-height:100%; min-width:100%; top:0; left:0;}
.noselect {-webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none;}

.top-bg {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:-185px; background:#393939; mix-blend-mode:multiply; z-index:2;}
.main-bg {position:absolute; width:40%; height:430px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:61px; background:#515151; mix-blend-mode:multiply; z-index:2;}
.foot-bg {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:306px; background:#393939; mix-blend-mode:multiply; z-index:2;}

.top-content {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:-185px; color:#fff; z-index:3;}
.main-content {position:absolute; width:40%; height:430px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:61px; color:#fff; z-index:3;}
.foot-content {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:306px; color:#fff; z-index:3;}

小提琴 https://jsfiddle.net/c0noL31w/

夹克

弄清楚了。我玩弄了数字,并在第一篇文章中将顶部div的高度添加到了负偏移中,中间没有偏移,底部div与顶部具有相同的偏移,但是正高度,并且效果很好。

的HTML

<html>
<head></head>
<body>
<img src='http://www.pptback.com/uploads/blue-world-map-backgrounds-powerpoint.jpg' alt='background' id='bg' class='noselect' />
<div class='top-bg'></div>
<div class='main-bg'></div>
<div class='foot-bg'></div>
<div class='top-content'>This is the top</div>
<div class='main-content'>This is the main content</div>
<div class='foot-content'>This is the foot</div>
</body>
</html>

的CSS

#bg {position:fixed; min-height:100%; min-width:100%; top:0; left:0;}
.noselect {-webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none;}
.top-bg {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:-246px; background:#393939; mix-blend-mode:multiply; z-index:2;}
.main-bg {position:absolute; width:40%; height:430px; top:50%; left:50%; transform:translate(-50%,-50%); background:#515151; mix-blend-mode:multiply; z-index:2;}
.foot-bg {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:246px; background:#393939; mix-blend-mode:multiply; z-index:2;}
.top-content {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:-246px; color:#fff; z-index:3;}
.main-content {position:absolute; width:40%; height:430px; top:50%; left:50%; transform:translate(-50%,-50%); color:#fff; z-index:3;}
.foot-content {position:absolute; width:40%; height:60px; top:50%; left:50%; transform:translate(-50%,-50%); margin-top:246px; color:#fff; z-index:3;}

新提琴: https : //jsfiddle.net/jrox275g/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

CSS的垂直中心

来自分类Dev

CSS垂直中心

来自分类Dev

css。绝对位置DIV中的垂直中心

来自分类Dev

定位垂直中心

来自分类Dev

定位垂直中心

来自分类Dev

使用javascript和CSS的垂直中心出错

来自分类Dev

垂直中心div与flexbox

来自分类Dev

垂直中心线

来自分类Dev

固定div的垂直中心

来自分类Dev

div内垂直中心

来自分类Dev

Ipad垂直中心上的iOS Safari(位于绝对位置的容器中)

来自分类Dev

响应式垂直中心隐藏了溢出

来自分类Dev

UITableViewCell annexView的元素的垂直中心

来自分类Dev

页脚中的Bootstrap垂直中心容器

来自分类Dev

QGraphicsTextItem是否支持垂直中心对齐?

来自分类Dev

将小部件放置在垂直中心

来自分类Dev

浮点内的垂直中心div

来自分类Dev

UITableViewCell annexView的元素的垂直中心

来自分类Dev

Safari的垂直中心定位问题

来自分类Dev

页脚中的Bootstrap垂直中心容器

来自分类Dev

垂直中心骚动炒作容器

来自分类Dev

如何通过垂直中心居中块?

来自分类Dev

水平和垂直中心按钮

来自分类Dev

仅使用CSS的“链接和输入”控件中的垂直中心文本

来自分类Dev

为什么CSS3不直接支持垂直中心?

来自分类Dev

如何围绕字形的垂直中间或中心点应用CSS旋转过渡

来自分类Dev

为什么表格的字体垂直中心在CSS中不起作用?

来自分类Dev

JavaFX 8-定位HBox的文本垂直中心

来自分类Dev

将DIV与页面的垂直中心对齐