How can I show only corner borders?

后端 未结 16 1793
被撕碎了的回忆
被撕碎了的回忆 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:40

    I found this question, but I was not satisfied with the border-radius approach: As I was using more thick borders, the effect was not as good as I wanted to. I managed to create another solution, without images, and without any extra markup:

        .box {
            /* fake border */
            position: relative;
            overflow: hidden;
            box-shadow: inset 0px 0px 0px 10px green;
            padding: 1em;
        }
    
        .box:before {
            /* this element will hide the fake border on the top and bottom */
            content:'';         
            display: block;
            position: absolute;
            border-top:10px solid white;
            border-bottom:10px solid white;
            /* height = border-width x2 */
            height:calc(100% - 20px); 
            top:0;
            /* width = size of fake-border x2 */
            width: calc(100% - 36px);
            /* left = size of fake-border */
            left:18px;
        }
    
        .box:after {
            /* this element will hide the fake border on the left and right */
            /* the rules for width, heigth, top and left will be the opposite of the former element */
            display: block;
            position: absolute;
            content:'';
            border-right:10px solid white;
            border-left:10px solid white;
            height:calc(100% - 36px);
            width: calc(100% - 20px);
            top:18px;
            left: 0;
        }
    

    Here's a JSFiddle with this example: https://jsfiddle.net/t6dbmq3e/ Hope it helps.

提交回复
热议问题