下图注册按钮的边框有渐变效果,如果让你来实现,你会怎么做呢

  

  

  个人觉得,省事的做法,直接让UI给背景图片就可以了,如下图

  

  不过这种做法感觉不太灵活,如果要修改border的渐变颜色,就需要UI重新做图。那应该怎么做呢?

  我首先想到的方法就是用CSS3的border-image属性

  border-image有2种用法

  ①:使用图片    

  

   ②:使用渐变

   

  注:然后我选择使用上面第二种方法,渐变来实现。但遇到一个问题——border-raduis圆角属性设置无效

  后来经过多番查找,终于找到了解决方法,截图和demo如下

  

<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<style>
.border {
position: relative;
outline: 0;
width: 100%;
text-align: center;
border: 4px solid transparent;
border-radius: 16px;
background: linear-gradient(orange, violet);
background-clip: padding-box;
padding: 10px;
/* just to show box-shadow still works fine */
box-shadow: 0 3px 9px black, inset 0 0 9px white;
} .border::after {
position: absolute;
top: -4px;
bottom: -4px;
left: -4px;
right: -4px;
background: linear-gradient(red, blue);
content: '';
z-index: -1;
border-radius: 16px;
</style>
</head> <body>
<button class="border">点我</button>
</body> </html>

  原文链接:https://segmentfault.com/q/1010000006613100/a-1020000006619501

  

  

  补充:然后我根据这个demo和UI给的设计图注册按钮做了小的调整,效果截图和demo如下 

      因为我是自己取的色,可能会有偏差,尽力还原了,见谅

<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<style>
body {
/* 只是为了更好的查看效果添加的背景颜色 */
background-color: #090909;
}
.border {
position: relative;
outline: 0;
width: 100%;
text-align: center;
border: 1px solid transparent;
border-radius: 16px;
background-color: #3B3933;
background-clip: padding-box;
color: #F6DFB4;
padding: 10px;
} .border::after {
position: absolute;
top: -4px;
bottom: -4px;
left: -4px;
right: -4px;
background: linear-gradient(#AB8124,#F0DF67,#2F1F08);
content: '';
z-index: -1;
border-radius: 16px;
</style>
</head> <body>
<button class="border">注册</button>
</body> </html>

  

CCS3怎么实现border边框渐变效果的更多相关文章

  1. iPhone 6/plus iOS Safari fieldset border 边框消失

    问题:iPhone6 plus 手机浏览网页,fieldset border 边框消失. 示例代码: <div> <fieldset style="border: 1px ...

  2. css 使用background背景实现border边框效果

    css中,我们一般使用border给html元素设置边框,但也可以使用background背景来模拟css边框效果,本文章向大家介绍css 使用background背景实现border边框效果,需要的 ...

  3. 【代码笔记】Web-CSS-CSS Border(边框)

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  4. padding(内边框), border(边框), margin, 标准文档流, 块级元素和行内元素, 浮动 ,margin的用法

    盒模型 在CSS中,"box model"这一术语是用来设计和布局时使用,然后在网页中基本上都会显示一些方方正正的盒子.我们称为这种盒子叫盒模型. 盒模型有两种:标准模型和IE模型 ...

  5. CSS border边框属性教程(color style)

    CSS 边框即CSS border-border边框样式颜色.边框样式.边框宽度的语法结构与应用案例教程篇 一.CSS 边框基础知识 CSS 边框即CSS border是控制对象的边框边线宽度.颜色. ...

  6. CSS3——盒子模型 border(边框) 轮廓(outline)属性 margin外边距 padding填充

    盒子模型 包括——边距,边框,填充,和实际内容 Margin(外边距) - 清除边框外的区域,外边距是透明的. Border(边框) - 围绕在内边距和内容外的边框. Padding(内边距) - 清 ...

  7. padding(内边距)、margin(外边距)、border(边框)

    元素的 padding 控制元素内容 content和元素边框 border 之间的距离. 元素的外边距 margin 控制元素边框 border 和元素实际所占空间的距离,如果你将一个元素的 mar ...

  8. border边框的宽度/样式/颜色 全部值

    border 用emmet写border的时候, 缩写是:bd. 不是b, 也不是bdr: b会扩展成bottom, bdr 会扩展成 border-right, border的宽度: 1px 基本上 ...

  9. [CSS]border边框

    border: 1px solid #ccc;    /*1像素 实线 灰色*/可分割成:border-width:1px;border-style: solid; border-color: #00 ...

随机推荐

  1. 创建ResultUtils类

    1.在pom.xml中增加maven资源 <dependency> <groupId>com.alibaba</groupId> <artifactId> ...

  2. Swoole 网络通信协议,固定包头。

    网络通信过程中,可能会出现分包和合包的情况.具体情况如https://wiki.swoole.com/wiki/page/484.html文档所讲的.这里测试了下固定包头的协议.示例代码如下 1.解包 ...

  3. MySQL学习入门安装和启动及常见问题解决方法(一)

    1.下载MySQL 官网地址:https://www.mysql.com/downloads/ 2.个人学习使用,只有下面这个是免费的 3.下载之后解压到目录中,并加入环境变量,如下 创建MYSQL_ ...

  4. select标签操作

    //遍历select标签 WebElement select = driver.findElement(By.tagName("select")); List<WebElem ...

  5. ----constructor 与 object----

    CONSTRUCTOR constructor是一种特殊的object,同样是用来创建和声明一个类 语法规则: constructor([arguments]) { ... } 注意: 1.在类中,只 ...

  6. vue history模式 apache配置

    我的服务器apache 版本是2.4.6 看文档上面说加那些代码,但是加上去重启服务器就不能重启,显示代码错误,然后百度查开启mod_rewrite这个重写URL 弄了半天也不会,百度上面的不知道是不 ...

  7. Java:ConcurrentHashMap是弱一致的

    本文将用到Java内存模型的happens-before偏序关系(下文将简称为hb)以及ConcurrentHashMap的底层模型相关的知识.happens-before相关内容参见:JLS §17 ...

  8. 通过sqoop将hdfs数据导入MySQL

    简介:Sqoop是一款开源的工具,主要用于在Hadoop(Hive)与传统的数据库(mysql.postgresql...)间进行数据的传递,可以将一个关系型数据库(例如 : MySQL ,Oracl ...

  9. docker之tomcat简单部署

    将apache-tomcat-8.0.36.tar.gz及jdk-7u79-linux-x64.gz拷贝到创建的tomcat8目录下 在tomcat8目录下创建Dockerfile文件 在Docker ...

  10. 预装win8的笔记本用第三方分区软件分区后出现0x0000225错误的解决方法/同理win7

    最近为采用EFI分区的联想电脑分区,是通过第三方软件进行的,完成后重启,发现系统报错0x0000225,提示插入安装介质修复. 应该是EFI分区导致的 http://zhidao.baidu.com/ ...