【发布时间】:2017-04-20 18:19:50
【问题描述】:
我想在桌面显示器和移动设备的原始纵横比上以宽格式显示全宽图像(将图像顶部裁剪为最大高度:500 像素;)。
我在 Wordpress 网站上使用龙门框架。我使用了一个 css 解决方法来强制图像在父盒装容器之外显示全宽。
示例除了在图像高度小于 max-height 时将空间推到顶部之外,这会从顶部裁剪?
.boxed-container{
margin:30px;
padding: 30px;
background:red;
}
.bg-img{
position: relative;
display: block;
overflow: hidden;
padding: 0px;
margin: 0px;
width: 100vw;
height: 100vh;
max-height: 300px;
left: 50%;
right: 50%;
margin-left: -50vw !important;
margin-right: -50vw !important;
background: url(http://www.photographymad.com/files/images/rule-of-thirds-movement.jpg) no-repeat bottom;
background-size: 100% auto;
}
h1 {
position: absolute;
width: 100%;
bottom: 0px;
text-align: center;
margin-bottom: 0px;
}
<div class="boxed-container">
This is where the boxed content belongs.
<div class="bg-img">
<h1>This is the header</h1>
</div>
</div>
【问题讨论】:
-
你能更清楚地表达你的目标吗?
-
你看到我的回答了吗???
-
是的,我确实看到了您的回答,谢谢,这非常有帮助且有效。
-
很高兴它成功了! :)
标签: image css responsive-design