css 实现边框渐变(完美兼容)

css 实现边框渐变(完美兼容)_第1张图片

方法很简单,创建一个大盒子,将其设置成渐变,然后在大盒子里设置一个小盒子,小盒子背景设置成白底。

首先创建一个父级盒子元素,给其设置渐变。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .stacked-linear {
            width: 500px;
            height: 500px;
            margin: auto;
            padding: 10px;
            border-radius: 10px;
            background:
                linear-gradient(217deg, rgba(255, 0, 0, .8), rgba(255, 0, 0, 0) 70.71%),
                linear-gradient(127deg, rgba(0, 255, 0, .8), rgba(0, 255, 0, 0) 70.71%),
                linear-gradient(336deg, rgba(0, 0, 255, .8), rgba(0, 0, 255, 0) 70.71%);
        }
      
    </style>
</head>

<body>
    <div class="stacked-linear">
       
    </div>
</body>

</html>

接下来在父类盒子里添加一个子盒子:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .stacked-linear {
            width: 500px;
            height: 500px;
            margin: auto;
            padding: 10px;
            border-radius: 10px;
            background:
                linear-gradient(217deg, rgba(255, 0, 0, .8), rgba(255, 0, 0, 0) 70.71%),
                linear-gradient(127deg, rgba(0, 255, 0, .8), rgba(0, 255, 0, 0) 70.71%),
                linear-gradient(336deg, rgba(0, 0, 255, .8), rgba(0, 0, 255, 0) 70.71%);
        }
        .blank{
            width: 100%;
            height: 100%;
            background: #fff;
        }
    </style>
</head>

<body>
    <div class="stacked-linear">
        <div class="blank"></div>
    </div>
</body>

</html>

你可能感兴趣的:(css,css,javascript,前端)