How can I show only corner borders?

后端 未结 16 1644
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 10:06

I\'m wondering if it\'s possible in CSS or jQuery to make a border but only for corner. Something like this:

****                         ****
*                     


        
16条回答
  •  盖世英雄少女心
    2020-11-22 10:36

    clip-path

    Using two div's on top of each other.
    And adding a clip-path to div that in the back you can create a border like effect.

    .wrapper {
      display: inline-block;
      background-color: black;
      line-height: 0px;
      -webkit-clip-path: polygon(0% 100%, 30% 100%, 30% 70%, 70% 70%, 70% 100%, 100% 100%, 100% 70%, 70% 70%, 70% 30%, 100% 30%, 100% 0%, 70% 0%, 70% 30%, 30% 30%, 30% 0%, 0% 0%, 0% 30%, 30% 30%, 30% 70%, 0% 70%);
        clip-path: polygon(0% 100%, 
                                 30% 100%, 
                                 30% 70%, 
                                 70% 70%, 
                                 70% 100%, 
                                 100% 100%, 
                                 100% 70%, 
                                 70% 70%,
                                 70% 30%,
                                 100% 30%,
                                 100% 0%,
                                 70% 0%,
                                 70% 30%,
                                 30% 30%,
                                 30% 0%,
                                 0% 0%,
                                 0% 30%,
                                 30% 30%,
                                 30% 70%,
                                 0% 70%);
    }
    .wrapper {} .wrapper div {
      display: inline-block;
      height: 150px;
      width: 150px;
      margin: 10px;
      background-color: white;
    }

    two pseudo elements

    Using two large pseudo elements you can create the border effect.

    .cut-border {
      position: relative;
      display: inline-block;
      border: 5px solid black;
      width: 150px;
      height: 150px;
    }
    .cut-border::before {
      content: "";
      position: absolute;
      height: calc(100% + 10px);
      width: 50%;
      background-color: white;
      top: -5px;
      left: 25%;
    }
    .cut-border::after {
      content: "";
      position: absolute;
      height: 50%;
      width: calc(100% + 10px);
      background-color: white;
      top: 25%;
      left: -5px;
    }

提交回复
热议问题