使图片垂直&水平居中的CSS实现方法
来源:互联网 发布:安卓系统刷windows系统 编辑:程序博客网 时间:2024/05/18 01:31
方法一:使用CSS的 background-image
html { width:100%; height:100%; background:url(logo.png) center center no-repeat;}
方法二:使用CSS的 margin 实现
img { position: absolute; top: 50%; left: 50%; width: 500px; /*图片宽度*/ height: 500px; /*图片高度*/ margin-top: -250px; /* 高度的一半 */ margin-left: -250px; /* 宽度的一半 */}
方法三:table 方式实现
CSS:
html, body, #wrapper { height:100%; width: 100%; margin: 0; padding: 0; border: 0;}#wrapper td { vertical-align: middle; text-align: center;}
HTML:
<html><body> <table id="wrapper"> <tr> <td><img src="logo.png" alt="" /></td> </tr> </table></body></html>
方法四:Flex 技术实现
CSS:
.container{ width: 1000px; height: 800px; border: 1px solid #ccc; margin: 0 auto;}div.horizontal { height: 100%; display: flex; // justify-content: center;}div.vertical { display: flex; flex-direction: column; justify-content: center;}
HTML:
<div class="container"> <div class="horizontal div1"> <div class="vertical"> <img src="logo.png" /> </div> </div></div>
0 0
- 使图片垂直&水平居中的CSS实现方法
- css实现垂直居中和水平居中的方法
- css图片实现水平、垂直居中
- css实现图片垂直水平居中
- css如何实现图片垂直水平居中
- 图片水平、垂直居中与父元素的css方法
- css实现div内图片的垂直、水平居中
- CSS实现水平垂直居中方法总结
- Css实现垂直和水平居中的方法
- 用css实现垂直水平居中的几种方法
- CSS实现元素水平/垂直居中的方法
- 【css】实现垂直水平居中的几种方法
- CSS实现水平垂直居中的几种方法
- css实现水平垂直居中的几种方法
- css实现div的水平垂直居中方法
- css实现垂直水平居中的5种方法
- css使图片水平垂直居中
- css 使图片水平垂直居中
- 学习MongoDB(四)——Master/Slave模式
- C中操作文件的几种模式
- Visual Studio中Debug与Release编译模式的区别以及Preprocesor directives的使用
- MYSQL 索引及优化
- 《UNIX网络编程》TCP网络编程基础(1)
- 使图片垂直&水平居中的CSS实现方法
- MyEclipse不编译问题的解决
- Shell中判断各种比较
- IM类app业务模块功能接口定义(三)
- php 的5 大 新特性!
- 央行发文放开银行远程开户,音视频软件迎契机
- runloop详解(一)
- drools 规约文件 —— 语法
- Gradle