I want the background color or image of .txt to be displayed as the background color or image of the border-radius of .next.
I’d like to know how to do this without changing the transform of .txt.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #f00;
}
.wrap {
position: relative;
overflow: hidden;
}
.txt {
background-color: #00f;
height: 300px;
translate: none;
rotate: none;
scale: none;
transform: translate3d(0px, 150px, 0px);
}
.txt img {
width: 100%;
}
.next {
position: relative;
height: 1000px;
background-color: #ccc;
border-radius: 20px 20px 0 0;
}
</style>
</head>
<body>
<div class="wrap">
<div class="txt"><img src="https://picsum.photos/640/360" alt=""></div>
</div>
<div class="next">next</div>
</body>
</html>
2
Answers
Add in a
body
styles:The red color in your layout is set as a background for the
body
. Just make the background at the beginning red and under the next element blue.I have a different solution compared to ‘Andrei’ but before that I would like to address the issue of why its happening.
So you have added
border-radius
tonext
which basically shrinks border of next and revels component behind it and in your case its body with background color red.To resolve this issue you can use andrei solution but if this same thing happens with multiple element with different colors or something else then adding
linear-gradient
would be less effective.What I usually do with this kind of situation is adding
margin-top
in negative so it moves element up and above its top element. In your case I have addedmargin-top: -15px
tonext
this won’t cause any trouble even with different type of elements.Below is working example.