[英]Background overflowing from div
I am designing a page which has the following HTML structure. 我正在设计一个具有以下HTML结构的页面。
<div id="event">
<div id="event-image">
<div id="event-image-background">
</div>
<img src="image_url_here">
</div>
<div id="event-title">
EVENT 1
</div>
<div id="event-details-summary">
Event Summary Here
</div>
<div id="event-description">
</div>
</div>
And I am using the following CSS for the structure. 我在结构中使用以下CSS。
#event{
position: relative;
}
#event-image{
text-align: center;
margin: 0px auto;
border: 1px solid #fff;
box-shadow: 0px 5px 10px -7px #CCC, -5px 10px 10px -7px #CCC;
overflow: hidden;
}
#event-image-background{
background: url('image_url_here') no-repeat;
background-size: cover;
opacity: 0.1;
position: absolute;
height: 100%;
width: 100%;
z-index: 2;
}
#event-image img{
opacity: 1;
z-index: 3;
border: 1px solid rgba(204, 204, 204, 0);
}
The problem I am facing is that the background that I have applied to event-image-background is overflowing into the other divs, namely event-title and others that follow. 我面临的问题是,我应用于事件图像背景的背景正在溢出到其他div中,即事件标题和随后的其他div中。 I am not really good at CSS, and have no clue what's going wrong. 我不太擅长CSS,也不知道出了什么问题。 Kindly help. 请帮助。
Thanks :) 谢谢 :)
PS: I dont really want to use the max-height option, as the image that I will be adding via img src will have variable height for each event. PS:我真的不想使用max-height选项,因为我将通过img src添加的图像的每个事件的高度都将变化。
Try adding overflow: hidden;
尝试添加overflow: hidden;
to #event-image-background
. 到#event-image-background
。
Protip, I'd recommend favoring styling on classes (eg .event-image-background
and <div class="event-image-background">
) rather than ids. Protip,我建议您使用类(例如.event-image-background
和<div class="event-image-background">
)样式,而不要使用id。 See: http://css-tricks.com/the-difference-between-id-and-class/ . 参见: http : //css-tricks.com/the-difference-between-id-and-class/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.