我正在尝试将图像居中放置在其父div内并对其进行修复。我想给它折叠的标头外观(即使它不是真正的标头),所以我一直在使用background-attachment: fixed;
它。
这种方法的问题是,当我随后background-position: center center;
将图像居中时,图像没有居中。
显然,如果我删除background-attachment: fixed;
CSS行,则图像将居中。
有什么方法可以background-attachment: fixed;
使图像居中吗?
.aparent {
min-height:200px;
}
#achild {
background-image: url(https://images.unsplash.com/photo-1442589031151-61d5645469d7?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=86aed4d82f9ab1324e46ae97b4cd98e1);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-attachment:fixed;
}
显示代码的笔-http: //codepen.io/anon/pen/GoBJpR(删除该图标background-attachment:fixed;
以显示其外观)
谢谢。
编辑:笔坏了
试试这个:http : //codepen.io/anon/pen/RrBPob我通过以下方式获得了所需的外观:
background-position: 50% 70%;
background-attachment: fixed;
调整百分比以适合您。第一个值是水平(X),第二个值是垂直(Y)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句