Last active
June 3, 2018 08:51
-
-
Save xiangst0816/149b5f8117b0c7be1523 to your computer and use it in GitHub Desktop.
将不同大小的img放在固定大小的div中;
要求img不能被拉伸覆盖、要水平居中放置在中间;
如果图片高度超出容器,则以高度为基准确定宽度,反之亦然; img不固定大小设置为inline,外层用line-height和text-align:center确定水平垂直居中;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href=""> | |
<div class="cbCoorBox_e"> | |
<img src="img/index/hanya.png" alt="合作机构"> | |
</div> | |
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.cbCoorBox_e { | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
width: 202px; | |
height: 53px; | |
margin:18px 20px; | |
float: left; | |
border: 1px solid #e3e3e3; | |
border-radius: 5px; | |
line-height: 36px; | |
overflow: hidden; | |
padding: 6px 15px; | |
text-align: center; | |
} | |
.cbCoorBox_e img{ | |
display: inline; | |
max-width: 100%; | |
max-height: 100%; | |
} |
max-width: 100%;
max-height: 100%;
这两行代码是 【点题】的 核心 。
垂直居中:
&:before {
content: '';
display: inline-block;
height: 100%;
line-height: 100%;
vertical-align: middle;
}
img {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
其中之一的方法。。。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
并没有垂直居中