是否可以仅使用CSS(不使用JS)以类似于响应的方式使图像相对于容器水平居中(显然,如果容器具有固定的宽度,我可以对像素进行数学运算以使其精确)??
这是该场景的一个小提琴:http : //jsfiddle.net/uqxu0vtv/1/
div.somediv { padding: 150px 2% 2%; border: 1px solid #000; position: relative;}
div.somediv img { position: absolute; top: 20px; left: 35%;}
是的,一点没错!:)
div.somediv {
padding: 150px 2% 2%;
border: 1px solid #000;
position: relative;
}
div.somediv img {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
}
<div class="somediv">
<img src="http://blog.grio.com/wp-content/uploads/2012/09/stackoverflow.png" />
<p>If the Federal Reserve prints more money, then the market will go up in nominal terms, creating the illusion that the stock market is going up, but it's not; our money is going down.</p>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句