如何让图片垂直居中显示

第1种,居中效果

居中效果

/*第1种,垂直居中效果*/.box{       width: 200px;height: 200px;border: 1px solid #ccc;       position: relative;  }.center{      width: 100px;height: 100px;background: gray;      margin: auto;position: absolute;top: 0;left: 0;bottom: 0;right: 0;    }

第2种 图片居中

如何让图片垂直居中显示

/*第2种 图片垂直居中*//* span是辅助元素 vertical-align这个属性的特点,它是相对兄弟级行高(line-height)来定位*/.box2{    width: 350px;height: 350px;border: 1px solid #F22727;    text-align: center;}.center2{ vertical-align: middle;}.block{ line-height: 350px;}/*跟父级一样高*/

第3种,居中效果 父元素使用display: table; 子元素display: table-cell; 

如何让图片垂直居中显示

/*第3种,居中效果*/.box3{    width: 350px;height: 350px;border: 1px solid #F22727;display: table;text-align: center;}.center3{    display: table-cell;vertical-align: middle;}

 第4种,居中效果

如何让图片垂直居中显示

/*第4种,居中效果  根据父元素来计算*/.box4{    width:300px;height: 300px;border: 1px solid #F22727;}.center4{    width: 200px;height: 200px;position: relative;left: 16%;top: 19%;}

以上就是如何让图片垂直居中显示的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1608267.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月23日 21:38:45
下一篇 2025年12月23日 21:38:55

相关推荐

发表回复

登录后才能评论
关注微信