I am making overlay effect but problem is overlay div is not wrapping all the divs inside. Overlay background is visible but divs are also visible outside of overlay div.
CSS
.overlay_effect {
background-color: rgba(0,0,0,0.5);
z-index: 2;
}
.overlay_effect {
background-color: rgba(0,0,0,0.5);
z-index: 2;
}
.columns_sum {
width: 340px;
padding: 8px;
}
.price {
list-style-type: none;
border: 1px solid #22ADE3;
margin: 0;
padding: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
overflow: hidden;
}
.price .header {
background-color: #22ADE3;
color: #fff;
font-size: 13px;
padding: 10px;
}
.price li {
padding: 7px;
text-align: center;
}
li:nth-child(4) {
border-right: 1px solid #22ADE3;
}
.price .grey_price {
float: left;
width: 50%;
background-color: #eee;
font-size: 13px;
border-right: 1px solid #22ADE3;
border-bottom: 1px solid #22ADE3;
}
.price .grey_price_right {
float: left;
width: 50%;
background-color: #eee;
font-size: 13px;
border-bottom: 1px solid #22ADE3;
}
.coverage_left {
float: left;
width: 50%;
font-size: 13px;
border-bottom: 1px solid #22ADE3;
}
.avl_text {
display: inline-block;
text-align: justify !important;
font-size: 13px;
}
<div class="columns_sum">
<div class="overlay_effect">
<ul class="price">
<li class="header">Dummy text</li>
<li class="grey_msg">Dummy text</li>
<li class="coverage_left">Dummy Text</li>
<li class="coverage_left">Dummy Text</li>
<li class="avl_text">Availability: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In rutrum. Praesent dapibus. Phasellus et lorem id felis nonummy placerat. Nulla non lectus sed nisl molestie malesuada.</li>
</ul>
</div>
</div>
答案 0 :(得分:1)
For an overlay that covers the content of a host element (here: div.columns_sum
) simply use a pseudo element ::after
:
.columns_sum::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,.5);
}
For the positioning to work properly, you need to add position: relative;
to the element that hosts ::after
:
.columns_sum {
position: relative;
}
Otherwise the absolute positioning refers to the closest positioned ancestor element (and if there is none, the body
).
.columns_sum {
width: 340px;
padding: 8px;
position: relative;
}
.columns_sum::after {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,.5);
}
.price {
list-style-type: none;
border: 1px solid #22ADE3;
margin: 0;
padding: 0;
transition: 0.3s;
overflow: hidden;
}
.price .header {
background-color: #22ADE3;
color: #fff;
font-size: 13px;
padding: 10px;
}
.price li {
padding: 7px;
text-align: center;
}
li:nth-child(4) {
border-right: 1px solid #22ADE3;
}
.price .grey_price {
float: left;
width: 50%;
background-color: #eee;
font-size: 13px;
border-right: 1px solid #22ADE3;
border-bottom: 1px solid #22ADE3;
}
.price .grey_price_right {
float: left;
width: 50%;
background-color: #eee;
font-size: 13px;
border-bottom: 1px solid #22ADE3;
}
.coverage_left {
float: left;
width: 50%;
font-size: 13px;
border-bottom: 1px solid #22ADE3;
}
.avl_text {
display: inline-block;
text-align: justify !important;
font-size: 13px;
}
<div class="columns_sum">
<ul class="price">
<li class="header">Dummy text</li>
<li class="grey_msg">Dummy text</li>
<li class="coverage_left">Dummy Text</li>
<li class="coverage_left">Dummy Text</li>
<li class="avl_text">Availability: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In rutrum. Praesent dapibus. Phasellus et lorem id felis nonummy placerat. Nulla non lectus sed nisl molestie malesuada.</li>
</ul>
</div>
答案 1 :(得分:0)
You can put the overlay as a child element of the <div class="columns_sum">
and not the parent of the ul
list
<div class="columns_sum">
<div class="overlay_effect">
</div>
<ul class="price">
<li class="header">Dummy text</li>
<li class="grey_msg">Dummy text</li>
<li class="coverage_left">Dummy Text</li>
<li class="coverage_left">Dummy Text</li>
<li class="avl_text">Availability: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In rutrum. Praesent dapibus. Phasellus et lorem id felis nonummy placerat. Nulla non lectus sed nisl molestie malesuada.</li>
</ul>
</div>
after that put the parent element in the relative position like this
.columns_sum {
position:relative;
/* and all other code to style this element goes here */
}
and the overlay_effect element will be put in the position absolute
.overlay_effect {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
}
this will put the overlay_effect
element over all other child within the .columns_sum
element