在线性渐变背景中,我创建了一个圆圈,并在其中创建了一个小方块。圆具有淡蓝色,正方形应具有主体的线性渐变,但是问题是div元素的线性渐变的位置与主体背景不匹配。
我尝试background:inherit使用div元素,但渐变与主体不匹配。
body {
background: linear-gradient(45deg, yellow, green);
background-size: 400% 400%;
}
.circle {
height: 150px;
width: 150px;
border-radius: 50%;
position: relative;
margin: auto;
background: dodgerblue;
}
.square {
height: 50px;
width: 50px;
transform: translate(250px, -100px);
background: inherit;
}Run Code Online (Sandbox Code Playgroud)
<body>
<div class="circle"></div>
<div class="square"></div>
</body>Run Code Online (Sandbox Code Playgroud)