linear-gradient

  1. linear-gradient是CSS3中新增的样式,主要用于颜色的渐变效果。MDN地址
  2. linear-gradient在不同内核下使用方式不同,详细内容可参考w3cplus

实用栗子(在Chrome下)

  1. 缺角效果
    先看效果图

    <div class="div1">
    这是内容
    </div>
    .div1 {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background:linear-gradient(-135deg, transparent 15px, #162e48 0);
    color: #fff;
    padding: 5px 15px;
    text-align: center;
    margin-bottom: 30px;
    }
  2. 补角效果
    先看效果图

    <div class="div2">
    这是内容
    </div>
    .div2 {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background:linear-gradient(-135deg, #f00 15px, #162e48 0);
    color: #fff;
    padding: 5px 15px;
    text-align: center;
    margin-bottom: 30px;
    }

    只是在栗子1的基础上修改了linear-gradient,将transparent修改为#f00

  3. 带边框的效果
    先看效果图

    <div class="div3">
    这是内容
    </div>
    .div3 {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background:linear-gradient(-135deg, #f00 15px, #162e48 0);
    color: #fff;
    padding: 5px 15px;
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 0 1px 1px #fff inset;
    }

    在栗子2的基础上增加了box-shadow,当然加边框可以有多种方式,可自行选择。

  4. 开关效果
    效果图

    <div class="div4">
    <div class="div4-1">OFF</div>
    <div class="div4-2 active">ON</div>
    </div>
    .div4 {
    width: 144px;
    height: 30px;
    line-height: 30px;
    background: #162e48;
    color: #FFF;
    text-align: center;
    margin-bottom: 30px;
    }
    .div4-1, .div4-2 {
    width: 86px;
    float: left;
    }
    .div4-1.active {
    margin-right: -28px;
    background:linear-gradient(-135deg, transparent 20px, #f00 0);
    }
    .div4-2.active {
    margin-left: -28px;
    background:linear-gradient(45deg, transparent 20px, #f00 0);
    }

    最终效果可根据需要自行调整

  5. 在栗子3的基础上做到以下效果,单纯使用linear-gradient没有找到解决方法,如有方案,请在评论下给出方案。以下是其中一种解决方式
    效果图

    .div5 {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background:linear-gradient(-135deg, #fff 15px, #162e48 0);
    color: #fff;
    padding: 5px 15px;
    text-align: center;
    box-shadow: 0 0 1px 1px #fff;
    margin-bottom: 30px;
    position: relative;
    }
    .div5:after {
    content: ' ';
    border: solid transparent;
    position: absolute;
    border-width: 15px;
    border-top-color: #000;
    border-right-color: #000;
    top: -1px;
    right: -1px;
    }
  6. 考虑到兼容性问题,可以通过:before:after实现同样的效果,给出一个栗子

    .div6 {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background:#162e48;
    color: #fff;
    padding: 5px 15px;
    text-align: center;
    position: relative;
    border: 1px solid #fff;
    margin-bottom: 30px;
    }
    .div6:before {
    content: ' ';
    border: solid transparent;
    position: absolute;
    border-width: 15px;
    border-top-color: #fff;
    border-right-color: #fff;
    right: 0px;
    top: 0px;
    }
    .div6:after {
    content: ' ';
    border: solid transparent;
    position: absolute;
    border-width: 15px;
    border-top-color: #000;
    border-right-color: #000;
    top: -1px;
    right: -1px;
    }
 
 

CSS3样式linear-gradient的使用(切角效果)的更多相关文章

  1. 怎样使用CSS3实现书页(书本)卷角效果

    我们有时候想在页面显示一个公告或用户提示信息. 一个经常使用设计是使用书签形状. 我们能够给书签加入卷角效果.以使其更为逼真.所谓的"卷角"实际上能够用小角度倾斜的阴影效果来模拟. ...

  2. css实现切角效果

    1. 一个切角 思路:如果我们要得到有一个切角的元素,我们只需要使用一个径向渐变就可以达到这个目标,这个渐变需要把一个透明色标放在切角处,然后再相同的位置设置另一个色标,并且把它的颜色设置成我们想要的 ...

  3. css 折角效果/切角效果

    首先我们先创建一个图案为100像素的斜面切角的图案 html <div class="one">12345</div> css .one{ width: 1 ...

  4. 用css实现网站切角效果 使用css3属性:渐变

     都是大量的练习,老师练习乒乓球花了大量时间,十万次一个动作的重复,高中班主任说过,世上没有天才,只是重复的次数多了,自然被认作了天才,小小班的学生之所以厉害是因为他们重复一个知识点次数多,所以没有一 ...

  5. css切角效果,折角效果

    html <div class="one">12345</div> <div class="two">abcde</d ...

  6. CSS奇思妙想图形(心形、气泡三角形、切角、梯形、饼图等)

    今天看到一篇不错文章,在原来CSS3图形创建基础上扩展了很多. 这里记录总结下 心形 原理:利用 圆形 和 正方形实现 HTML: <div class="heartShaped&qu ...

  7. Css-深入学习之弧形切角矩形

    本文是作者从别的网站和文章学习了解的知识,简单做了个笔记,想要学习更多的可以参考这里:[css进阶]伪元素的妙用--单标签之美,奇思妙想 (弧形切角矩形) 代码: width: 180px; heig ...

  8. Css--深入学习之切角

    本文是作者从别的网站和文章学习了解的知识,简单做了个笔记,想要学习更多的可以参考这里:[css进阶]伪元素的妙用--单标签之美,奇思妙想 带切角的矩形: 该图来源于(奇思妙想) Css代码: .not ...

  9. CSS3中渐变gradient详解

    这几天看了一本HTML5的书,里面对于页面的背景使用了大量的渐变效果,因此在这里写一些关于渐变Gradient的东西. CSS3中的Gradient有两种,分别是线性渐变(linear-gradien ...

随机推荐

  1. Viewpager实现网络图片的轮播

    //主意:里面用到了第三方的Xutils.jar包和Imageloader.jar包还用到了访问网络,所以要加网络权限 <uses-permission android:name="a ...

  2. 直接在script里面换样式IE6,7,8不兼容

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  3. java 网络编程Socket编程

    Server.java import java.io.*; import java.net.*; public class Server { public static void main(Strin ...

  4. asp 正则替换函数

    Function RegExpTest(patrn,str1,strng) Dim regEx',str1 ' 建立变量 'str1 = "The quick brown fox jumpe ...

  5. Chapter 1 First Sight——21

    They were sitting in the corner of the cafeteria, as far away from where I sat as possible in the lo ...

  6. PAT1001

    时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output the sum in standard format 计算a+b ...

  7. 初学HTML5的一点理解

    刚接触了一点点用h5移动端的一点知识,用自己最浅薄的理解来看解决自适应屏幕尺寸问题和适应屏幕尺寸的布局问题.这里,为了解决自适应屏幕尺寸问题大概需要做的就是把HTML中的元素的尺寸尽可能的用百分比表示 ...

  8. 【dp】 poj 1953

    用n个数字0或者1组成一个排列,要求每两个1不相邻,问有多少种排法 dp[n][0]记录n个连续数,结尾为0的不同排列数dp[n][1]记录第n个连续数,结尾为1的不同排列数 DP公式: dp[i][ ...

  9. 2016大连网络赛 Different GCD Subarray Query

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  10. Counting Islands II

    Counting Islands II 描述 Country H is going to carry out a huge artificial islands project. The projec ...