Border Corners: Triangle

前端 未结 3 1699
不知归路
不知归路 2021-01-20 04:44

Is it possible to get rid of the \"triangle\" shape in the border corners? (when using different color borders)

See this example:

http://jsfiddle.net/GLsqV/

3条回答
  •  暖寄归人
    2021-01-20 05:18

    One option using generated content:

    .borders {
        width:500px;
        height:500px;
        position: relative;
        background:#efefef;
        border-top:10px solid red;
        border-bottom:10px solid green;
    }
    
    .borders::before,
    .borders::after {
        content: '';
        position: absolute;
        width: 10px;
        top: 0;
        bottom: 0;
        background-color: #000;
    }
    
    .borders::before {
        left: 0;
    }
    
    .borders::after {
        right: 0;
    }
    

    JS Fiddle demo.

    Or with nested HTML (if you really must):

    ​ .borders { width:500px; height:500px; position: relative; background:#efefef; border-top:10px solid red; border-bottom:10px solid green; } .borders .innerBorder{ content: ''; position: absolute; width: 10px; top: 0; bottom: 0; background-color: #000; } .borders .left { left: 0; } .borders .right { right: 0; }

    JS Fiddle demo.

    And a single-nested-element solution in which the left, and right, border-color is the background-color of the wrapping element, and the width controlled by the margin of the descendant:

    CSS:

    .borders {
        width:500px;
        height:500px;
        background-color: #000;
        border-top:10px solid red;
        border-bottom:10px solid green;
    }
    
    .borders .inner {
        background-color: #efefef;
        height: 100%;
        margin: 0 10px;
    }
    

    JS Fiddle demo.​

提交回复
热议问题