【发布时间】:2016-11-11 11:32:35
【问题描述】:
我有一张图片需要放在一个最大宽度为 700px 的 div 中间;
当窗口变窄并且 div 变得小于它包含的图像的宽度时,我希望图像也变小。
在下面的小提琴中,我分别添加了这两个函数:https://jsfiddle.net/rb1hyxh2/,但我找不到将它们组合起来的方法(例如,margin: 0 auto; 不适用于此处的内联块...)
<div class="header1"><div class="header2">
<img src="http://wp.patheos.com.s3.amazonaws.com/blogs/faithwalkers/files/2013/03/bigstock-Test-word-on-white-keyboard-27134336.jpg" class="header3">
</div></div>
<div class="header1">
<img src="http://wp.patheos.com.s3.amazonaws.com/blogs/faithwalkers/files/2013/03/bigstock-Test-word-on-white-keyboard-27134336.jpg" class="headerA">
</div>
.header1{
padding-bottom: 16px;
background-color: red;
max-width: 700px;
margin-bottom: 30px;
}
.header2{
background-color: blue;
display:inline-block;
}
.header3{
width: 100%;
}
.headerA{
display:block;
margin:auto;
}
【问题讨论】: