It probably doesn't work because the pseudo-element is not generated if the value is contentomitted . The default contentvalue is equal none, which probably means you are not seeing the pseudo-element. Therefore, you need to specify a value other than nonefor the property content:
.modal:after {
content: '';
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
, , , .modal, . , - :before .modal, :
.modal {
position: fixed;
top: 100px;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
width: 500px;
border: 2px solid #736D61;
background: #fff;
padding: 10px;
}
.modal-overlay:before {
content: '';
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
<div class="modal-overlay">
<div class="modal">MODAL</div>
</div>
Hide result