How to create an triangle shape (fixed height, width=100%) with background

后端 未结 5 1293
你的背包
你的背包 2021-01-15 15:10

I have a graphic background, and I need to display a colored triangle in the top left corner (independing the resolution).

Can I create a triangle shaped element us

5条回答
  •  半阙折子戏
    2021-01-15 15:55

    To expand on web-tiki's answer, I think this is actually what you're going for:

    $(document).ready(function() {
      function triangle() {
        $("#wrap .tr").css({
          "border-left": $('#wrap').width() + "px solid #fff",
          "border-bottom": "200px solid transparent"
        });
      }
      triangle();
    
      $(window).on('resize', triangle);
    });
    body {
      background: #fff;
    }
    #wrap {
      position: relative;
      min-height: 500px;
      background: teal;
    }
    .tr {
      position: absolute;
      left: 0;
      top: 0;
    }
    
    

提交回复
热议问题