When dealing with background color for an element, the entire element gets covered by it. Though there is a property called background-size
, it specifically works only for background images.
To tackle this issue, you can utilize a pseudo-element to create a background effect.
.media-body {
position: relative; /* Allows child elements to be positioned relative to this container */
border: 1px solid black;
}
.media-body::before {
content: ''; /* Sets empty content */
position: absolute; /* Positions the pseudo-element absolutely */
height: 90%; /* Determines height and width as required */
width: 90%;
top: 5%; /* Sets desired vertical offset */
left: 5%;
z-index: -1; /* Moves element behind other elements */
background-color: gray;
}
<div class="media-body">
<h5>Lagoa Azul</h5>
<span class="text-media-body">
Cras sit amet nibh libero, in gravida nulla. Nulla
vel metus scelerisque ante sollicitudin.
</span>
</div>