问题描述:
想要在chrome 模拟手机上让不规则尺寸图片垂直水平居中。
边框适应屏幕设置成正方形。
现在只能做到水平居中。
达达们有什么好的建议和意见?
-
-
-
-
-
-
-
-
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
既然你说到了h5,那肯定首推Flex布局呀。
justify-content: center;用于水平居中,align-items: center;设置垂直居中。用fle布局
既然是h5,当然弹性布局是首先应该尝试的。而且flex用起来也很方便。
没人想到table-cell么。。。?渲染比flex效率要高
left:50%; transform:translate(-50%, 0)
h5有个width height的新单位,vw vh,你查查就懂了
图片用js设置height和width一样变成正方形,图片的上一层用display:table使图片垂直居中
做成背景图片更简单