栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

具有边界半径的边界渐变

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

具有边界半径的边界渐变

You cannot use

border-radius
with gradient. Here is another idea where you
can rely on multiple background and adjust the
background-clip
:

.white-grad {    background:     linear-gradient(#ccc,#ccc) padding-box,      linear-gradient(to right, #9c20aa, #fb3570) border-box;    color: #313149;    padding:10px;    border: 5px solid transparent;    border-radius:15px;    display:inline-block;    margin: 75px 0;}<div > Some text here</div><div > Some long long long text here</div><div > Some long long <br>long text here</div>

如果需要透明性,可以考虑使用SVG,如下所示:

svg {  width:200px;  height:100px;  margin:10px;}<svg xmlns="http://www.w3.org/2000/svg"><defs>      <linearGradient id="Gradient" x1="0" x2="100" y1="0" y2="0" gradientUnits="userSpaceOnUse">         <stop stop-color="#9c20aa" offset="0"/>         <stop stop-color="#fb3570" offset="1"/>      </linearGradient>   </defs>  <rect x="5" y="5" height="100%" width="100%"  rx="20" ry="20" stroke-width="10" fill="transparent" stroke="url(#Gradient)"/></svg>

That you can apply as background:

.white-grad {    background:url('data:image/svg+xml;utf8,<svg   xmlns="http://www.w3.org/2000/svg" ><defs><linearGradient id="Gradient" x1="0" x2="100" y1="0" y2="0" gradientUnits="userSpaceOnUse"><stop stop-color="%239c20aa" offset="0"/><stop stop-color="%23fb3570" offset="1"/></linearGradient></defs><rect x="5" y="5" width="100%" height="100%"  rx="20" ry="20" stroke-width="10" fill="transparent" stroke="url(%23Gradient)"/></svg>');    color: #313149;    padding:25px;    border-radius:15px;    display:inline-block;    margin: 75px 0;}body {  background:yellow;}<div > Some text here</div><div > text very loooooooooooong here</div>

You can also use it as common element and consider

position:absolute
to
place it around the text:

.white-grad {  color: #313149;  padding: 25px;  border-radius: 15px;  display: inline-block;  margin: 75px 0;  position:relative;  z-index:0;}.white-grad > svg {  position:absolute;  top:0;  left:0;  height:100%;  width:100%;  z-index:-1;}body {  background: yellow;}.hide { height:0; width:0;}<svg  xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="Gradient" x1="0" x2="100" y1="0" y2="0" gradientUnits="userSpaceOnUse"><stop stop-color="#9c20aa" offset="0"/><stop stop-color="#fb3570" offset="1"/></linearGradient></defs><rect x="5" y="5" width="100%" height="100%" id="border"  rx="20" ry="20" stroke-width="10" fill="transparent" stroke="url(#Gradient)"/></svg><div ><svg xmlns="http://www.w3.org/2000/svg">  <use href="#border" /></svg>Some text here</div><div ><svg xmlns="http://www.w3.org/2000/svg">  <use href="#border" /></svg>text very loooooooooooong here</div>

Here is a different and complex idea with CSS using

mask
where you will have
transparency and it will also be responsive:

.white-grad {  color: #313149;  padding: 10px;  display: inline-block;  margin: 75px 0;  position:relative;  z-index:0;}.white-grad:before {  content:"";  position:absolute;  z-index:-1;  top:0;  left:0;  right:0;  bottom:0;  border: 5px solid transparent;  border-radius: 15px;  background: linear-gradient(to right, #9c20aa, #fb3570) border-box;  -webkit-mask:    radial-gradient(farthest-side at bottom left ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) top     right/15px 15px,    radial-gradient(farthest-side at top right   ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) bottom  left /15px 15px,    radial-gradient(farthest-side at top left    ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) bottom  right/15px 15px,    radial-gradient(farthest-side at bottom right,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) top     left /15px 15px,    linear-gradient(#fff,#fff) top   /100% 5px,    linear-gradient(#fff,#fff) bottom/100% 5px,    linear-gradient(#fff,#fff) left  /5px 100%,    linear-gradient(#fff,#fff) right /5px 100%;  -webkit-mask-repeat:no-repeat;  mask:    radial-gradient(farthest-side at bottom left ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) top     right/15px 15px,    radial-gradient(farthest-side at top right   ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) bottom  left /15px 15px,    radial-gradient(farthest-side at top left    ,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) bottom  right/15px 15px,    radial-gradient(farthest-side at bottom right,transparent calc(100% - 5px),#fff calc(100% - 4px) 100%) top     left /15px 15px,    linear-gradient(#fff,#fff) top   /100% 5px,    linear-gradient(#fff,#fff) bottom/100% 5px,    linear-gradient(#fff,#fff) left  /5px 100%,    linear-gradient(#fff,#fff) right /5px 100%;  mask-repeat:no-repeat;}<div > Some text here</div><div > Some long long long text here</div><div > Some long long <br>long text here</div>

With CSS variables, we can make it easy to adjust:

.white-grad {  --b:5px;    --r:15px;   --g:transparent calc(100% - var(--b)),#fff calc(100% - var(--b) + 1px) 100%;  color: #313149;  padding: calc(var(--b) + 5px);  display: inline-block;  margin: 75px 0;  position:relative;  z-index:0;}.white-grad:before {  content:"";  position:absolute;  z-index:-1;  top:0;  left:0;  right:0;  bottom:0;  border: var(--b) solid transparent;  border-radius: var(--r);  background: var(--c,linear-gradient(to right, #9c20aa, #fb3570)) border-box;  -webkit-mask:    radial-gradient(farthest-side at bottom left ,var(--g)) top     right/var(--r) var(--r),    radial-gradient(farthest-side at top right   ,var(--g)) bottom  left /var(--r) var(--r),    radial-gradient(farthest-side at top left    ,var(--g)) bottom  right/var(--r) var(--r),    radial-gradient(farthest-side at bottom right,var(--g)) top     left /var(--r) var(--r),    linear-gradient(#fff,#fff) top   /100% var(--b),    linear-gradient(#fff,#fff) bottom/100% var(--b),    linear-gradient(#fff,#fff) left  /var(--b) 100%,    linear-gradient(#fff,#fff) right /var(--b) 100%;  -webkit-mask-repeat:no-repeat;  mask:    radial-gradient(farthest-side at bottom left ,var(--g)) top     right/var(--r) var(--r),    radial-gradient(farthest-side at top right   ,var(--g)) bottom  left /var(--r) var(--r),    radial-gradient(farthest-side at top left    ,var(--g)) bottom  right/var(--r) var(--r),    radial-gradient(farthest-side at bottom right,var(--g)) top     left /var(--r) var(--r),    linear-gradient(#fff,#fff) top   /100% var(--b),    linear-gradient(#fff,#fff) bottom/100% var(--b),    linear-gradient(#fff,#fff) left  /var(--b) 100%,    linear-gradient(#fff,#fff) right /var(--b) 100%;  mask-repeat:no-repeat;}body {  background:#f2f2f2;}<div > Some text here</div><div  > Some long long long text here</div><div   > Some long long <br>long text here</div><div   > Some long long <br>long text here<br> more and more more and more</div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/635374.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号