css div 边缘渐变,围绕div的CSS3渐变边框

3 个答案:

答案 0 :(得分:1)

我建议使用border-image属性

.top-to-bottom {

border-bottom: 10px solid trasparent;

border-width: 10px;

border-style: solid;

-webkit-border-image: -webkit-gradient(linear, 0 0, 0 100%, from(black), to(rgba(0, 0, 0, 0))) 1 100%;

-webkit-border-image: -webkit-linear-gradient(#FBCDEA, rgba(0, 0, 0, 0)) 1 1;

-moz-border-image: -moz-linear-gradient(#FBCDEA, rgba(0, 0, 0, 0)) 1 1;

-o-border-image: -o-linear-gradient(#FBCDEA, rgba(0, 0, 0, 0)) 1 1;

border-image: linear-gradient(to bottom, #FBCDEA, rgba(0, 0, 0, 0)) 1 1;

height: 100px;

width: 97%;

border-top: 10px solid #FBCDEA;

}

.bottom-to-top {

border-top: 10px solid trasparent;

border-width: 10px;

border-style: solid;

-webkit-border-image: -webkit-gradient(linear, 0 100%, 0 0, from(#FBCDEA), to(rgba(0, 0, 0, 0))) 1 1;

-webkit-border-image: -webkit-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 1;

-moz-border-image: -moz-linear-gradient(bottom, #FBCDEA, rgba(0, 0, 0, 0)) 1 1;

-o-border-image: -o-linear-gradient(bottom, #FBCDEA, rgba(0, 0, 0, 0)) 1 1;

border-image: linear-gradient(to top, #FBCDEA, rgba(0, 0, 0, 0)) 1 1;

border-bottom: 10px solid #FBCDEA;

height: 100%;

width: 98%

}

答案 1 :(得分:1)

既然你想要纯css,这就是一种方式:

.dblgradbox {

margin: auto;

padding: 15px;

width: 275px;

height: 200px;

border: 15px solid transparent;

border-top: 10px solid transparent;

border-image: linear-gradient(to bottom, transparent, #FBCDEA) 3 100%;

box-shadow: 0 15px 0 0 #FBCDEA, 0 -5px 0 0 #F7FCFF, inset 0px 15px 0 0 #FBCDEA;

background-image: linear-gradient(#FBCDEA, transparent), linear-gradient(#FBCDEA, transparent);

background-size: 15px 100%;

background-position: 0 0, 100% 0;

background-repeat: no-repeat;

border-radius: 7px;

}

x3ns

运行代码段后查看“整页”。我没有包含任何跨浏览器属性,因为这是一个例子。

此方法通常通过应用渐变边框,并使用盒阴影插入技术来帮助完成元素内的效果 - 因此还需要填充以适合其中的内容。背景图像仅在插图的两侧显示两个渐变条。

答案 2 :(得分:0)

也许是这样?

*{

box-sizing: border-box;

}

.wrap{

width: 300px;

height: 300px;

padding: 20px;

margin: 25px auto;

border-radius: 10px;

background: rgb(254,249,253); /* Old browsers */

background: -moz-linear-gradient(top, rgb(254,249,253) 0%, rgb(253,230,246) 50%, rgb(253,204,234) 100%); /* FF3.6+ */

background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(254,249,253)), color-stop(50%,rgb(253,230,246)), color-stop(100%,rgb(253,204,234))); /* Chrome,Safari4+ */

background: -webkit-linear-gradient(top, rgb(254,249,253) 0%,rgb(253,230,246) 50%,rgb(253,204,234) 100%); /* Chrome10+,Safari5.1+ */

background: -o-linear-gradient(top, rgb(254,249,253) 0%,rgb(253,230,246) 50%,rgb(253,204,234) 100%); /* Opera 11.10+ */

background: -ms-linear-gradient(top, rgb(254,249,253) 0%,rgb(253,230,246) 50%,rgb(253,204,234) 100%); /* IE10+ */

background: linear-gradient(to bottom, rgb(254,249,253) 0%,rgb(253,230,246) 50%,rgb(253,204,234) 100%); /* W3C */

filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fef9fd', endColorstr='#fdccea',GradientType=0 ); /* IE6-9 */

}

.wrap div{

width: 100%;

height: 100%;

padding: 20px;

}

.wrap .inner{

background: rgb(253,204,234); /* Old browsers */

background: -moz-linear-gradient(top, rgb(253,204,234) 0%, rgb(253,230,246) 50%, rgb(254,249,253) 100%); /* FF3.6+ */

background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(253,204,234)), color-stop(50%,rgb(253,230,246)), color-stop(100%,rgb(254,249,253))); /* Chrome,Safari4+ */

background: -webkit-linear-gradient(top, rgb(253,204,234) 0%,rgb(253,230,246) 50%,rgb(254,249,253) 100%); /* Chrome10+,Safari5.1+ */

background: -o-linear-gradient(top, rgb(253,204,234) 0%,rgb(253,230,246) 50%,rgb(254,249,253) 100%); /* Opera 11.10+ */

background: -ms-linear-gradient(top, rgb(253,204,234) 0%,rgb(253,230,246) 50%,rgb(254,249,253) 100%); /* IE10+ */

background: linear-gradient(to bottom, rgb(253,204,234) 0%,rgb(253,230,246) 50%,rgb(254,249,253) 100%); /* W3C */

filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fdccea', endColorstr='#fef9fd',GradientType=0 ); /* IE6-9 */

}

.wrap .item{

background: #fff;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 CSS 中的 linear-gradient() 函数来实现 div渐变背景和渐变边框。 下面是一个设置渐变背景和渐变边框的示例代码: ```html <div class="gradient-box"></div> ``` ```css .gradient-box { width: 200px; height: 200px; background: linear-gradient(to bottom right, #ff0080, #ff8c00); border: 2px solid; border-image: linear-gradient(to bottom right, #ff0080, #ff8c00) 1; } ``` 在上面的代码中,使用 `background` 属性来设置 div渐变背景。`linear-gradient()` 函数中的参数 `to bottom right` 表示渐变方向为从左上角到右下角,`#ff0080` 和 `#ff8c00` 分别表示渐变的起始颜色和结束颜色。 使用 `border` 属性来设置 div边框,同时使用 `border-image` 属性来设置边框渐变。`linear-gradient()` 函数中的参数同样表示渐变方向,`1` 表示边框宽度为 1 像素。 需要注意的是,`border-image` 属性在一些浏览器中可能不被支持,此时可以使用 `background-clip` 属性来实现相同的效果。代码如下: ```css .gradient-box { width: 200px; height: 200px; background: linear-gradient(to bottom right, #ff0080, #ff8c00); border: 2px solid transparent; padding: 2px; background-clip: content-box, border; } ``` 在上面的代码中,使用 `padding` 属性来为 div 添加内边距,同时将 `border` 属性的颜色设置为 `transparent`,使边框不可见。使用 `background-clip` 属性来指定背景的绘制区域,`content-box` 表示背景仅在内容区域绘制,`border` 表示背景在边框区域绘制。这样,就可以实现相同的渐变边框效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值