css3 上锯齿边框只有半个

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .bg1 {
            /* width: 300px; */
            height: 50px;
            /* background: #caca8c; */
            background-image: -webkit-gradient(linear, 50% 0, 0 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f5f5f5), to(#f5f5f5)), -webkit-gradient(linear, 50% 0, 100% 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f5f5f5), to(#f5f5f5));
            background-size: 7px 5px;
            background-repeat: repeat-x;
            background-position: 0 100%;
        }
        
        .bg2 {
            height: 50px;
            /* background: #caca8c; */
            background-image: -webkit-gradient(linear, 50% 0, 0 100%, from(#f5f5f5), color-stop(.5, #f5f5f5), color-stop(.5, transparent), to(transparent)), -webkit-gradient(linear, 50% 0, 0 100%, from(#f5f5f5), color-stop(.5, #f5f5f5), color-stop(.5, transparent), to(transparent));
            background-size: 7px 5px;
            background-repeat: repeat-x;
            background-position: 0 0;
        }
        
        .gray {
            height: 24px;
            background: #f5f5f5;
        }
    </style>
</head>

<body>
    <div class="bg1"></div>
    <div class="gray"></div>
    <div class="bg2"></div>
</body>

</html>

bg2的上的锯齿如何变得完整,它只有半个,如何像bg1那样完整,但是他是在上边,bg1是在下边,麻烦大家帮我看一下是哪里出错了,谢谢

阅读 6.3k
3 个回答
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .bg1 {
            /* width: 300px; */
            height: 50px;
            /* background: #caca8c; */
            background-image: -webkit-gradient(linear, 50% 0, 0 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f5f5f5), to(#f5f5f5)), -webkit-gradient(linear, 50% 0, 100% 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f5f5f5), to(#f5f5f5));
            background-size: 7px 5px;
            background-repeat: repeat-x;
            background-position: 0 100%;
        }
        
        .bg2 {
               background-repeat: repeat-x;
            background-position: 0 100%;
               background-size: 7px 7px;
               height: 24px;
            background-image: -webkit-linear-gradient(45deg ,#fff 25% ,transparent 25%),
                              -webkit-linear-gradient(-45deg ,#fff 25% ,transparent 25%);
              background-image: linear-gradient(45deg ,#fff 25% ,transparent 25%),
            linear-gradient(-45deg ,#fff 25% ,transparent 25%);
            
        }
        
        .gray {
            height: 24px;
            background: #f5f5f5;
        }
    </style>
</head>

<body>
    <div class="bg1"></div>
    <div class="gray">
            <div class="bg2"></div>
    </div>
    
</body>

position-y 加上锯齿高度
background-position: 0 -5px;

我要是上一个写出来的,下一个直接翻转


        .bg2 {
            height: 50px;
            /* background: #caca8c; */
            background-image: -webkit-gradient(linear, 50% 0, 0 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f00), to(#f00)), -webkit-gradient(linear, 50% 0, 100% 100%, from(transparent), color-stop(.5, transparent), color-stop(.5, #f00), to(#f00));
            background-size: 7px 5px;
            background-repeat: repeat-x;
            background-position: 0 0;
            transform:rotate(180deg);
        }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
1 篇内容引用
推荐问题