Creating a diagonal line/section/border with CSS

前端 未结 6 1799
离开以前
离开以前 2020-12-07 23:34

I am trying to create a diagonal line on a webpage, to act as a section/section break. This is essentially a split colour section. I cant use an image as if the page gets en

6条回答
  •  情歌与酒
    2020-12-08 00:04

    You can use CSS3 clip:

    .yellow {
      width: 100%;
      height: 90px;
      background: yellow;
      -webkit-clip-path: polygon(100% 0, 0 0, 0 100%);
      clip-path: polygon(100% 0, 0 0, 0 100%);
    }
    .black {
      width: 100%;
      height: 90px;
      background: black;
      -webkit-clip-path: polygon(100% 0, 0 100%, 100% 99%);
      clip-path: polygon(100% 0, 0 100%, 100% 99%);
      margin-top: -90px;
    }

    Demo: http://jsfiddle.net/zLkrfeev/2/

    It's not widely supported by the browsers: http://caniuse.com/#feat=css-clip-path

提交回复
热议问题