Home>

I wonder if it is possible to make a frame in CSS or jQuery, but only for corners.
Something like that:

**** ****
    * *
    * *
                 Content
    * *
    * *
    **** ****

free translation How Can I Show Only Corner Borders?from the participant @pierreaulemartin.

  • Answer # 1

    This is another excellent alternative, if you now want to start using vectors to provide greater responsiveness.

    <
    SVG ViewBox= "0 0 100 100" width= "50px" >
      ≪
    Path D= "M25.2 L2.2 L2.25" Fill= "None" Stroke= "Black" Stroke-width= "3" />
      ≪
    Path D= "M2.75 L2.98 L25.98" Fill= "None" Stroke= "Black" Stroke-width= "3" />
      ≪
    Path D= "M75.98 L98.98 L98.75" Fill= "None" Stroke= "Black" Stroke-Width= "3" />
      ≪
    Path D= "M98.25 L98.2 L75.2" Fill= "None" Stroke= "Black" Stroke-width= "3" />
    ≪
    /SVG >
    

    SVG is an excellent tool for use. Here are some of the advantages of using SVG in this case:

    • curve control
    • Pouring control (opacity, color)
    • stroke control (width, opacity, color)
    • quantity code
    • smaller time to increase and maintain the shape of the curve
    • scalable
    • no http query (if built-in, as in Example)

    free translation Answerfrom the participant @StewartSide

  • Answer # 2

    This is another excellent alternative, if you now want to start using vectors to provide greater responsiveness.

    <
    SVG ViewBox= "0 0 100 100" width= "50px" >
      ≪
    Path D= "M25.2 L2.2 L2.25" Fill= "None" Stroke= "Black" Stroke-width= "3" />
      ≪
    Path D= "M2.75 L2.98 L25.98" Fill= "None" Stroke= "Black" Stroke-width= "3" />
      ≪
    Path D= "M75.98 L98.98 L98.75" Fill= "None" Stroke= "Black" Stroke-Width= "3" />
      ≪
    Path D= "M98.25 L98.2 L75.2" Fill= "None" Stroke= "Black" Stroke-width= "3" />
    ≪
    /SVG >
    

    SVG is an excellent tool for use. Here are some of the advantages of using SVG in this case:

    • curve control
    • Pouring control (opacity, color)
    • stroke control (width, opacity, color)
    • quantity code
    • smaller time to increase and maintain the shape of the curve
    • scalable
    • no http query (if built-in, as in Example)

    free translation Answerfrom the participant @StewartSide

  • Answer # 3

    Here is the idea of ​​using the gradient and CSS variables, where you can easily control the shape of the border:

    .box {
      --B: 5px; /* Thickness of the Border * /
      --c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      Border: var (-b) Solid Transparent; /* Space for the border * /
      Background:
        Linear-gradient (var (-c), var (-c)) Top Left,
        Linear-gradient (var (-c), var (-c)) Top Left,
        Linear-Gradient (VAR (-C), VAR (-C)) Bottom Left,
        Linear-Gradient (VAR (-C), VAR (-C)) Bottom Left,
        Linear-gradient (var (-c), var (-c)) TOP RIGHT,
        Linear-gradient (var (-c), var (-c)) TOP RIGHT,
        Linear-gradient (VAR (-C), VAR (-C)) Bottom Right,
        LINEAR-GRADIENT (VAR (-C), VAR (-C)) BOTTOM RIGHT;
      Background-Size: var (-b) var (-w), var (-w) var (-b);
      Background-Origin: Border Box;
      Background-Repeat: No-Repeat;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: Blue; -W: 40px; -B: 2px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Green; -W: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Black; -W: 50%; -B: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Purple; -w: 10px; -B: 10px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Orange; -W: Calc (50% -10px); -B: 4px" >
    Some Content
    ≪
    /div >
    

    You can also get a challenging color if you align it with a mask:

    .box {
      --B: 5px; /* Thickness of the Border * /
      --c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      Padding: var (-b); /* Space for the border * /
      Position: relative;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    }
    .Box :: Before {
      Content: "";
      Position: Absolute;
      Top: 0;
      left: 0;
      Right: 0;
      Bottom: 0;
      Background: var (-C, RED);
      -Webkit-Mask:
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-Gradient (# FFF, # FFF) Bottom Right,
        Linear-gradient (# FFF, # FFF) Bottom Right;
      -Webkit-Mask-Size: var (-b) var (-w), var (-w) var (-b);
      -Webkit-Mask-Repeat: No-Repeat;
      Mask:
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-Gradient (# FFF, # FFF) Bottom Right,
        Linear-gradient (# FFF, # FFF) Bottom Right;
      Mask-Size: var (-b) var (-w), var (-w) var (-b);
      Mask-Repeat: No-Repeat;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: repeating-linear-gradient (45deg, Red, Blue); -w: 40px; -b: 2px" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: repeating-linear-gradient (90deg, # 000 0 5px, Transparent 5px 10px); -w: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Conic-gradient (Red, green, yellow); -w: 50%; -b: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Purple; -w: 10px; -B: 10px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Repeating-linear-gradient (45deg, Orange 0 5px, Blue 5PX 10px); -W: Calc (50% -10px); -B: 4px" >
    Some Content
    ≪
    /div >
    

    And why not with a radius:

    .box {--B: 5px; /* Thickness of the border * /--c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      --r: 25px; /* Radius * /
      Padding: var (-b); /* Space for the border * /
      Position: relative;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    }
    .Box :: Before {
      Content: "";
      Position: Absolute;
      Top: 0;
      left: 0;
      Right: 0;
      Bottom: 0;
      Background: var (-C, RED);
      Padding: var (-b);
      Border-Radius: var (-R);
      -Webkit-Mask:
        Linear-Gradient (# FFF, # FFF) TOP /CALC (100% -2 * VAR (-W)) VAR (-B),
        Linear-gradient (# FFF, # FFF) Bottom /Calc (100% -2 * Var (-w)) var (-b),
        Linear-gradient (# FFF, # FFF) Left /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-gradient (# FFF, # FFF) Right /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-Gradient (# FFF, # FFF) Content-Box,
        Linear-gradient (# FFF, # FFF);
      -WebKit-Mask-Composite: destination-out;
      -Webkit-Mask-Repeat: No-Repeat;
      Mask:
        Linear-Gradient (# FFF, # FFF) TOP /CALC (100% -2 * VAR (-W)) VAR (-B),
        Linear-gradient (# FFF, # FFF) Bottom /Calc (100% -2 * Var (-w)) var (-b),
        Linear-gradient (# FFF, # FFF) Left /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-gradient (# FFF, # FFF) Right /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-Gradient (# FFF, # FFF) Content-Box,
        Linear-gradient (# FFF, # FFF);
      Mask-Composite: EXCLUDE;
      Mask-Repeat: No-Repeat;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-c: repeating-linear-gradient (45deg, Red, Blue); -w: 40px; -B: 2px; -R: 40px;" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: repeating-linear-gradient (90deg, # 000 0 5px, Transparent 5px 10px); -w: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Conic-gradient (Red, green, yellow); -w: 50%; -b: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Purple; -w: 10px; -B: 10px; -R: 0px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: repeating-linear-gradient (45deg, Orange 0 5px, Blue 5PX 10px); -w: Calc (50% -10px); -B: 4px; -R: 10px ">
    Some Content
    ≪
    /div >
    

    free translation Answerfrom the participant @Temani AFIF..

  • Answer # 4

    Here is the idea of ​​using the gradient and CSS variables, where you can easily control the shape of the border:

    .box {
      --B: 5px; /* Thickness of the Border * /
      --c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      Border: var (-b) Solid Transparent; /* Space for the border * /
      Background:
        Linear-gradient (var (-c), var (-c)) Top Left,
        Linear-gradient (var (-c), var (-c)) Top Left,
        Linear-Gradient (VAR (-C), VAR (-C)) Bottom Left,
        Linear-Gradient (VAR (-C), VAR (-C)) Bottom Left,
        Linear-gradient (var (-c), var (-c)) TOP RIGHT,
        Linear-gradient (var (-c), var (-c)) TOP RIGHT,
        Linear-gradient (VAR (-C), VAR (-C)) Bottom Right,
        LINEAR-GRADIENT (VAR (-C), VAR (-C)) BOTTOM RIGHT;
      Background-Size: var (-b) var (-w), var (-w) var (-b);
      Background-Origin: Border Box;
      Background-Repeat: No-Repeat;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: Blue; -W: 40px; -B: 2px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Green; -W: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Black; -W: 50%; -B: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Purple; -w: 10px; -B: 10px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Orange; -W: Calc (50% -10px); -B: 4px" >
    Some Content
    ≪
    /div >
    

    You can also get a challenging color if you align it with a mask:

    .box {
      --B: 5px; /* Thickness of the Border * /
      --c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      Padding: var (-b); /* Space for the border * /
      Position: relative;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    }
    .Box :: Before {
      Content: "";
      Position: Absolute;
      Top: 0;
      left: 0;
      Right: 0;
      Bottom: 0;
      Background: var (-C, RED);
      -Webkit-Mask:
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-Gradient (# FFF, # FFF) Bottom Right,
        Linear-gradient (# FFF, # FFF) Bottom Right;
      -Webkit-Mask-Size: var (-b) var (-w), var (-w) var (-b);
      -Webkit-Mask-Repeat: No-Repeat;
      Mask:
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-gradient (# FFF, # FFF) Top Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-Gradient (# FFF, # FFF) Bottom Left,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-gradient (# FFF, # FFF) Top Right,
        Linear-Gradient (# FFF, # FFF) Bottom Right,
        Linear-gradient (# FFF, # FFF) Bottom Right;
      Mask-Size: var (-b) var (-w), var (-w) var (-b);
      Mask-Repeat: No-Repeat;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: repeating-linear-gradient (45deg, Red, Blue); -w: 40px; -b: 2px" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: repeating-linear-gradient (90deg, # 000 0 5px, Transparent 5px 10px); -w: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Conic-gradient (Red, green, yellow); -w: 50%; -b: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Purple; -w: 10px; -B: 10px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Repeating-linear-gradient (45deg, Orange 0 5px, Blue 5PX 10px); -W: Calc (50% -10px); -B: 4px" >
    Some Content
    ≪
    /div >
    

    And why not with a radius:

    .box {--B: 5px; /* Thickness of the border * /--c: red; /* Color of the Border * /
      --W: 20px; /* width of border * /
      --r: 25px; /* Radius * /
      Padding: var (-b); /* Space for the border * /
      Position: relative;
      /* IRRELEVANT CODE * /
      width: 200px;
      Height: 100px;
      BOX-SIZING: BORDER-BOX;
      margin: 5px;
      Display: INLINE-FLEX;
      Font-Size: 30px;
      Justify-Content: Center;
      Align-Items: Center;
      Line-Height: 90px;
    }
    .Box :: Before {
      Content: "";
      Position: Absolute;
      Top: 0;
      left: 0;
      Right: 0;
      Bottom: 0;
      Background: var (-C, RED);
      Padding: var (-b);
      Border-Radius: var (-R);
      -Webkit-Mask:
        Linear-Gradient (# FFF, # FFF) TOP /CALC (100% -2 * VAR (-W)) VAR (-B),
        Linear-gradient (# FFF, # FFF) Bottom /Calc (100% -2 * Var (-w)) var (-b),
        Linear-gradient (# FFF, # FFF) Left /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-gradient (# FFF, # FFF) Right /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-Gradient (# FFF, # FFF) Content-Box,
        Linear-gradient (# FFF, # FFF);
      -WebKit-Mask-Composite: destination-out;
      -Webkit-Mask-Repeat: No-Repeat;
      Mask:
        Linear-Gradient (# FFF, # FFF) TOP /CALC (100% -2 * VAR (-W)) VAR (-B),
        Linear-gradient (# FFF, # FFF) Bottom /Calc (100% -2 * Var (-w)) var (-b),
        Linear-gradient (# FFF, # FFF) Left /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-gradient (# FFF, # FFF) Right /Var (-B) Calc (100% -2 * Var (-W)),
        Linear-Gradient (# FFF, # FFF) Content-Box,
        Linear-gradient (# FFF, # FFF);
      Mask-Composite: EXCLUDE;
      Mask-Repeat: No-Repeat;
    } 
    <
    DIV Class= "Box" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-c: repeating-linear-gradient (45deg, Red, Blue); -w: 40px; -B: 2px; -R: 40px;" >
    Some Content
    ≪
    /div >
    ≪
    Div Class= "Box" style= "-C: repeating-linear-gradient (90deg, # 000 0 5px, Transparent 5px 10px); -w: 30%; -B: 8px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: Conic-gradient (Red, green, yellow); -w: 50%; -b: 3px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" Style= "-C: Purple; -w: 10px; -B: 10px; -R: 0px" >
    Some Content
    ≪
    /div >
    ≪
    DIV Class= "Box" style= "-C: repeating-linear-gradient (45deg, Orange 0 5px, Blue 5PX 10px); -w: Calc (50% -10px); -B: 4px; -R: 10px ">
    Some Content
    ≪
    /div >
    

    free translation Answerfrom the participant @Temani AFIF..