分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

css实现图片垂直居中

发布时间:2023-09-06 01:25责任编辑:赖小花关键词:暂无标签

1、行高 == 高度:已知图片的高宽

<div style="text-align: center; width: 500px;height:200px; line-height:200px; border: green solid 1px;"> ??<img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="display: inline-block; vertical-align: middle;" /></div>

2、display:table display:table-cell:不兼容IE6/IE7

<div style="text-align: center; width: 500px;height:200px; display: table;border: green solid 1px;"> ???<span style="display: table-cell; vertical-align: middle; "><img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="display: inline-block;" /></span></div>

3、绝对定位:已知图片的高宽

<div style="width: 500px;height:200px; position: relative; border: green solid 1px;"> ???<img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="width: 120px; height: 40px;position: absolute; left:50%; top: 50%; margin-left: -60px;margin-top: -20px;" /></div>

4、flex布局:h5端可用

<style type="text/css"> ???.ui-flex { ???????display: -webkit-box !important; ???????display: -webkit-flex !important; ???????display: -ms-flexbox !important; ???????display: flex !important; ???????-webkit-flex-wrap: wrap; ???????-ms-flex-wrap: wrap; ???????flex-wrap: wrap ???} ???.ui-flex, .ui-flex *, .ui-flex :after, .ui-flex :before { ???????box-sizing: border-box ???} ???.ui-flex.justify-center { ???????-webkit-box-pack: center; ???????-webkit-justify-content: center; ???????-ms-flex-pack: center; ???????justify-content: center ???} ???.ui-flex.center { ???????-webkit-box-pack: center; ???????-webkit-justify-content: center; ???????-ms-flex-pack: center; ???????justify-content: center; ???????-webkit-box-align: center; ???????-webkit-align-items: center; ???????-ms-flex-align: center; ???????align-items: center ???}</style><div class="ui-flex justify-center center" style="border: green solid 1px; width: 500px; height: 200px;"> ???<div class="cell"> ???<img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="" /> ???</div></div>

css实现图片垂直居中

原文地址:http://www.cnblogs.com/ilovexiaoming/p/7839563.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved