Вы можете использовать несколько фонов, используя linear-gradient
для создания прозрачной детали без необходимости использования дополнительного элемента:
.image {
background-image: url(https://picsum.photos/id/10/2500/1667);
background-size: cover;
background-repeat: no-repeat;
height: 400px;
}
.floater {
width: 400px;
background:
linear-gradient(blue,blue) 0 0/100% 50px no-repeat,
linear-gradient(blue,blue) 0 100%/100% 50px no-repeat,
linear-gradient(blue,blue) 0 0/50px 100% no-repeat,
linear-gradient(blue,blue) 100% 0/50px 100% no-repeat;
}
.title,
.description {
padding: 20px
}
<div class="image">
<div class="floater">
<div class="title">
My Title
</div>
<div class="description">
Short Description
</div>
</div>
</div>
Вот более хитрая идея с использованием clip-path
:
.image {
background-image: url(https://picsum.photos/id/10/2500/1667);
background-size: cover;
background-repeat: no-repeat;
height: 400px;
}
.floater {
width: 400px;
-webkit-clip-path: polygon(0% 0%, 0% 100%, 20% 100%, 20% 29%, 75% 29%, 75% 69%, 20% 69%, 20% 100%, 100% 100%, 100% 0%);
clip-path: polygon(0% 0%, 0% 100%, 20% 100%, 20% 29%, 75% 29%, 75% 69%, 20% 69%, 20% 100%, 100% 100%, 100% 0%);
background:blue;
}
.title,
.description {
padding: 20px
}
<div class="image">
<div class="floater">
<div class="title">
My Title
</div>
<div class="description">
Short Description
</div>
</div>
</div>
Еще один, использующий вставку box-shadow:
.image {
background-image: url(https://picsum.photos/id/10/2500/1667);
background-size: cover;
background-repeat: no-repeat;
height: 400px;
}
.floater {
width: 400px;
box-shadow:0 0 0 50px blue inset;
}
.title,
.description {
padding: 20px
}
<div class="image">
<div class="floater">
<div class="title">
My Title
</div>
<div class="description">
Short Description
</div>
</div>
</div>
Вы также можете рассмотреть псевдоэлемент с границами:
.image {
background-image: url(https://picsum.photos/id/10/2500/1667);
background-size: cover;
background-repeat: no-repeat;
height: 400px;
}
.floater {
position:relative;
width: 400px;
z-index:0;
}
.floater:before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
border-width:50px 20px 50px 20px;
border-style:solid;
border-color:blue;
z-index:-1;
}
.title,
.description {
padding: 20px
}
<div class="image">
<div class="floater">
<div class="title">
My Title
</div>
<div class="description">
Short Description
</div>
</div>
</div>