gpt4 book ai didi

html - 向元素的选定 Angular 添加圆 Angular 边框

转载 作者:太空狗 更新时间:2023-10-29 15:24:44 25 4
gpt4 key购买 nike

我怎样才能用纯 CSS 构建这样的东西?

SS

这是我到目前为止的进展:Fiddle

即使我继续添加额外的 span,我也在为如何获得那个圆 Angular 而苦苦挣扎。


代码:

body {
background: #000;
}

.container {
position: relative;
width: 300px;
height: 150px;
margin: 10% auto;
}

.top-right {
position: absolute;
top: -10px;
right: 0;
width: 50px;
height: 1px;
background: white;
border-radius: 5px;
}

.box {
width: 100%;
height: 100%;
background: red;
border-radius: 15px;
display: flex;
align-items: center;
justify-content: center;
}

h3 {
color: white;
}
<div class="container">
<span class="top-right"></span>
<div class="box">
<h3>Content</h3>
</div>
</div>

最佳答案

您可以通过在 .box 中使用伪元素 ::before/::after 使用属性 border< 来实现这一点border-radius

body {
background: #000;
}
.container {
width: 300px;
height: 150px;
margin: 3% auto 0 /* changed for demo */
}
h3 {
color: white;
}
.box {
width: 100%;
height: 100%;
background: red;
border-radius: 15px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.box::before,
.box::after {
content: "";
position: absolute;
border: solid white;
width: 50px;
height: 50px;
}
.box::before {
top: -15px;
left: -15px;
border-radius: 15px 0; /* top-left */
border-width: 5px 0 0 5px;
}
.box::after {
bottom: -15px;
right: -15px;
border-radius: 0 0 15px; /* bottom-right */
border-width: 0 5px 5px 0;
}
<div class="container">
<div class="box">
<h3>Content</h3>
</div>
</div>

关于html - 向元素的选定 Angular 添加圆 Angular 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37779742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com