【发布时间】:2015-12-28 20:59:13
【问题描述】:
我想让一个 div 的高度相对于浏览器宽度变化,就像我们创建一个 div width:100%; 并在里面放 img width:100%; height:auto;,所以在这种情况下,div 的高度相对于 img 的高度是可变的,即重新调整大小从窗口宽度。
但在我的情况下,我不想将 img 放在父 div 中,(里面也是 div 宽度文本块)我想做出父 div 的行为,就像里面是 img。
如何获得?有可能吗?
.hero-section-inner {
width: 100%;
}
.hero-section-inner img,
.hero-section-inner-half img {
width: 100%!important;
height: auto!important;
}
.hero-section-inner-half {
width: 50%;
margin-top: 50px;
}
<div class="hero-section-inner">
<img class="alignnone size-full wp-image-4769" src="http://www.ev-interiordesign.ru/wp-content/uploads/2015/10/about-header.jpg">
</div>
<div class="hero-section-inner-half">
<img class="alignnone size-full wp-image-4769" src="http://www.ev-interiordesign.ru/wp-content/uploads/2015/10/about-header.jpg">
</div>
所以这是 img 的例子。
【问题讨论】:
-
与我们分享您的代码。
-
你想要它作为背景图片吗?还是只作为一个小图片