-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS基础测试19期 #66
Comments
.radius {
width: 200px;
height: 100px;
position: relative;
background-color: #fff;
margin: 40px;
}
.radius::after {
content: '';
position: absolute;
width: 220px;
height: 120px;
background: linear-gradient(deepskyblue, deeppink);
border-radius: 10px;
z-index: -1;
left: -10px;
top: -10px;
} <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS19</title>
</head>
<body>
<div class="radius">
圆角渐变框
</div>
</body>
</html> 我记得好像用特别的带圆角的图片 + border-image 是不是也可以做到类似的效果呢?我自己试了下用 linear-gradient 生成貌似是不太靠谱。。。回头可以再试试 |
想到了下面四种方式:
<h3>第一种</h3>
<div class="box box-1">
<div class="box-in">圆角渐变边框</div>
</div>
<h3>第二种</h3>
<div class="box box-2">
<div class="box-in">圆角渐变边框</div>
</div> .box{
display:inline-block;
border-radius:8px;
}
.box-in{
padding:1em 3em;
}
/*第一种*/
.box-1{
padding:8px;
background:linear-gradient(deepskyblue, deeppink);
}
.box-1 .box-in{
background-color:#ffffff;
}
/*第二种*/
.box-2{
overflow:hidden;
}
.box-2 .box-in{
border:8px solid;
border-image:linear-gradient(deepskyblue, deeppink) 8;
} |
{
border-radius: 10px;
background: linear-gradient(white,white) center/calc(100% - 20px) calc(100% - 20px) no-repeat,linear-gradient(deepskyblue,deeppink);
padding: 10px;
} |
.gorgeous-box {
position: relative;
height: 100px;
width: 600px;
padding: 10px;
overflow: hidden;
border-radius: 10px;
}
.gorgeous-box::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: -1;
border: 10px solid transparent;
border-image: linear-gradient(deepskyblue, deeppink) 10;
} <div class="gorgeous-box"></div> |
.button1{ } .button2{ |
<div class="box">
圆角渐变框
</div> * {
padding: 0;
margin: 0;
}
body {
--boxWidth: 200px;
--boxHeight: calc(var(--boxWidth) / 2);
--radiusSize: 10px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.box {
position: relative;
width: var(--boxWidth);
height: var(--boxHeight);
text-align: center;
line-height: var(--boxHeight);
background-color: #fff;
}
.box:after {
position: absolute;
content: "";
width: calc(var(--boxWidth) + 2 * var(--radiusSize));
height: calc(var(--boxHeight) + 2 * var(--radiusSize));
left: calc(-1 * var(--radiusSize));
top: calc(-1 * var(--radiusSize));
background-image: linear-gradient(deepskyblue, deeppink);
border-radius: var(--radiusSize);
z-index: -1;
} |
<div class="box">
圆角渐变边框
</div> .box {
position: relative;
width: 300px;
height: 86px;
border-radius: 10px;
padding: 10px;
overflow: hidden;
text-align: center;
box-sizing: border-box;
display: table-cell;
vertical-align: middle;
}
.box::after {
content:'';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
border: 10px solid;
border-image: linear-gradient(to bottom, deepskyblue, deeppink) 10;
} |
<div>圆角渐变边框</div> div{
width: 280px;
height: 66px;
border: 10px solid transparent;
border-radius: 10px;
background:
linear-gradient(#fff,#fff) padding-box,
linear-gradient(deepskyblue,deeppink) border-box;
text-align: center;
line-height: 66px;
} |
<div class="demo">圆角渐变边框</div> .demo {
position: relative;
width: 300px;
height: 100px;
line-height: 100px;
text-align: center;
border-radius: 10px;
overflow: hidden;
}
.demo::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(180deg, deepskyblue, deeppink);
z-index: -1;
}
.demo::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
clip-path: inset(10px 10px 10px 10px);
background-color: #fff;
z-index: -1;
} |
裁剪一下 <div class="container">圆角渐变框</div> .container {
height: 100px;
width: 400px;
line-height: 100px;
border: 20px solid #eee;
text-align: center;
border-image: linear-gradient(deepskyblue, deeppink) 10;
clip-path: inset(0 round 20px);
} |
两个方法:
|
请实现下图所示的圆角渐变边框,颜色是 deepskyblue 和 deeppink,外圆角大小是
10px。
原图不显示点击这里
请附上对应的CSS代码,注意缩进和代码高亮,可以使用下面语法进行高亮:
本期小测需要提供在线demo,不要参考别人的回答,诚实守信。
本期小测无直播答疑,但是会总结要点。
感谢您的参与!
The text was updated successfully, but these errors were encountered: