我正在尝试在显示的左侧图像上实现以下圆形效果(使用CSS,我不想走图像编辑器路线):
到目前为止,我已经尝试了2种选择:
::before
路线(我只想显示照片中位于红色方块内的部分):
html {
background: yellow;
}
.pre {
width: 100%;
height: 100px;
border: 1px solid black;
}
.container {
margin-top: 50px;
border: 1px solid black;
}
.top {
width: 100px;
height: 100px;
margin: 0 auto;
border: 1px solid red;
position: relative;
}
.top::before {
content: '';
width: 200px;
height: 200px;
background: url("https://source.unsplash.com/WLUHO9A_xik/1600x900");
background-size: cover;
border-radius: 50%;
position: absolute;
top: -50px;
left: -160%;
z-index: -1;
}
<div class="pre"></div>
<div class="container">
<div class="top"></div>
<div class="bottom"></div>
</div>
但是,我不知道如何
.pre
div掩盖照片。border-top-right-radius
,但效果并不完全相同,没有我想要的那么整洁:
.container {
margin-top: 50px;
box-shadow: 10px 10px 5px #DEDEDE;
width: 70%;
height: 300px;
margin: 0 auto;
display: flex;
flex-direction: row;
justify-content: space-evenly;
}
.right {
flex-grow: 3;
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 20px 50px;
border: 1px solid red;
padding-top: 25px;
}
.left {
border-top-right-radius: 50%;
border-bottom-right-radius: 50%;
background: url("https://source.unsplash.com/WLUHO9A_xik/1600x900");
background-size: cover;
flex-grow: 1;
}
<div class="container">
<div class="left"></div>
<div class="right">
</div>
</div>
有人可以指出我正确的方向吗?谢谢!
答案 0 :(得分:1)
您的第一个想法实际上非常接近。您只是忘了添加
overflow:hidden;
进入您的.top
班。
html {
background: yellow;
}
.pre {
width: 100%;
height: 100px;
border: 1px solid black;
}
.container {
margin-top: 50px;
border: 1px solid black;
}
.top {
width: 100px;
height: 100px;
margin: 0 auto;
border: 1px solid red;
position: relative;
overflow:hidden;
}
.top::before {
content: '';
width: 200px;
height: 200px;
background: url("https://source.unsplash.com/WLUHO9A_xik/1600x900");
background-size: cover;
border-radius: 50%;
position: absolute;
top: -50px;
left: -160%;
z-index: -1;
}
<div class="pre"></div>
<div class="container">
<div class="top"></div>
<div class="bottom"></div>
</div>