Home > Web Front-end > HTML Tutorial > 使用CSS3伸缩盒实现图片垂直居中_html/css_WEB-ITnose

使用CSS3伸缩盒实现图片垂直居中_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:24:58
Original
1191 people have browsed it

用CSS实现图片垂直居中的方法有很多,针对移动端设备可以用CSS3伸缩盒来实现图片垂直居中。

代码如下:

<div class="box">    <img src="1.png" alt=""></div>
Copy after login

1 .box{4     display: flex;    /*容器为伸缩盒*/5     align-items: center;  /*纵轴方向上的对齐方式设置为居中*/6 }7 img{8     width: 100%;9 }
Copy after login

以上是新版伸缩盒实现的,支持安卓4.4+,如果需要兼容安卓4.4-,需要再另外添加旧伸缩盒,如下:

.box{    display: -webkit-box;    /*容器为旧伸缩盒*/    -webkit-box-align: center; /*设置旧伸缩盒对齐方式*/      display: flex;            /*容器为伸缩盒*/    align-items: center;  /*纵轴方向上的对齐方式设置为居中*/}img{    width: 100%;}
Copy after login

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template