让一个图片在div中居中(四种方法)
2016-10-26 09:42
260 查看
第一种方法:
第二种方法:
第三种方法:
第四种方法:
***:红色部分就是主要代码
<div class="title"> <div class="flag"></div> <div class="content"> <img src="img_p1_title.png"> </div> </div>
.title { width: 100%; font-size: 0; height: 10%; } .title .content img { width: 35%; } /*--主要的--*/ .content{ display: inline-block; vertical-align: middle; } .flag{ display: inline-block; vertical-align: middle; height: 100%; width: 0; }
第二种方法:
<div class="title"> <img src="img_p1_title.png"> </div>
.title { display: flex; justify-content: center; align-items: center; } .title img { width: 35%; } //该方法有些旧系统不支持
第三种方法:
<div class="title"> <span>第三种方法</span> </div>
.title { height: 15%; font-size: 18px; position: relative; } .title span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
第四种方法:
<div class="title"> <span>第四种方法</span> </div>
.title { width: 200px; height: 200px; vertical-align: middle; display: table-cell; text-align: center; }
***:红色部分就是主要代码
相关文章推荐
- 让一个图片在div中居中(四种方法)
- Div图片垂直居中的方法
- css图片在div内上下居中的方法
- Div图片垂直居中的方法
- CSS 图片在DIV中垂直居中的方法
- 一个div在浏览器水平居中的实现方法
- Div图片垂直居中的方法
- DIV+CSS中让布局、背景图片、文字内容居中的方法
- <转载>使CSS文字图片div元素居中方法之水平居中的几个方法
- 使一个div在body中水平垂直居中的方法
- DIV里面的图片水平与垂直居中的方法
- Div图片垂直居中的方法
- Div垂直居中及容器内图片垂直居中的CSS解决方法
- <转载>使CSS文字图片div元素居中方法之水平居中的几个方法
- 刚写好一个图片居中裁剪并指定大小缩放的方法
- 一个图片垂直居中的方法
- 让图片img标签在div里上下左右居中的方法
- 在DIV中图片垂直、水平居中(最简单方法)
- 一个好用的让DIV水平垂直居中的方法
- 分享一个网页背景图与div居中的方法