How to create a border that fully covers the adjacent corners in CSS?

前端 未结 7 1890
闹比i
闹比i 2020-12-17 09:00

I have a div with a 1px border and I\'m trying to create a 3px border in another color to that div. I\'m using this code:

box {
  border: 1px solid #ffffd;
  b         


        
相关标签:
7条回答
  • 2020-12-17 09:11

    Use css :after pseudo-class, docs

    .box_big {
      border: 10px solid #ffffd;
      position:relative;
      z-index: 1;
    }
    .box_big:after{
        height: 10px;
        position: absolute;
        top:-10px; left:-10px; right:-10px;
        content: " ";
        z-index: 2;
        background: red;
    }
    .box {
      border: 1px solid #ffffd;
      position:relative;
      z-index: 1;
    }
    .box:after{
        height: 3px;
        position: absolute;
        top:-3px; left:-1px; right:-1px;
        content: " ";
        z-index: 2;
        background: red;
    }
    <div class="box_big">
        big box
    </div>
    <hr />
    <div class="box">
        your box
    </div>

    0 讨论(0)
  • 2020-12-17 09:17

    The question is a bit old but I thought I'd make a suggestion that worked for me in a similar situation.

    I just set border-width: 0; and that took away the mitered ends and made them nice and square for a button that I had a bottom-border applied.

    0 讨论(0)
  • 2020-12-17 09:18

    You could draw these with inset shadows and padding :

    div {
      padding:12px 5px 5px;
      width: 40%;
      height: 200px;
      box-shadow: inset 0 10px #3F9BD0, inset 4px 0 gray, inset -4px 0 gray, inset 0 -4px  gray
    }
    <div></div>

    or just an outset top shadow

    div {
     
      width: 40%;
      height: 200px;
      border:2px solid gray;
      border-top:none;
      box-shadow:  0 -10px #3F9BD0;
      margin-top:12px;
    }
    <div></div>

    else, background gradient could be used and even animated 2 examples : http://codepen.io/gc-nomade/pen/IGliC or http://codepen.io/gc-nomade/pen/pKwby

    0 讨论(0)
  • 2020-12-17 09:26

    Instead of border-top, try using the :after pseudo-element to recreate the effect you want.

    .box {
      width: 200px;
      height: 100px;
      border: 1px solid #ffffd;
      position: relative;
    }
    .box:after {
      position: absolute;
      content: "";
      width: 100%;
      height: 5px;
      top: -5px;
      background: dodgerblue;
      padding: 1px;
      left: -1px;
    }
    <div class="box"></div>

    Choice 2:

    Use linear-gradient().

    .box {
      width: 200px;
      height: 100px;
      border: 1px solid #ffffd;
      background: -webkit-linear-gradient(top, dodgerblue 5%, #fff 5%);
      background: -moz-linear-gradient(top, dodgerblue 5%, #fff 5%);
      background: -o-linear-gradient(top, dodgerblue 5%, #fff 5%);
      background: -ms-linear-gradient(top, dodgerblue 5%, #fff 5%);
      background: linear-gradient(top, dodgerblue 5%, #fff 5%);
    }
    <div class="box"></div>

    0 讨论(0)
  • 2020-12-17 09:28

    This also puts a line on top:

    .box1 {
      border: 10px solid #ffffd;
      border-top: 0;
      box-shadow: 0 -30px 0 #3F9BD0;
      float: left;
      width: 300px;
      height: 300px;
    }
    <div class="box1"></div>

    0 讨论(0)
  • 2020-12-17 09:29

    Try this:

    .box {
      outline: 2px solid #ffffd;
      margin-top: -2px;
      border-top: 10px solid #3F9BD0;
      min-width:100px;
      min-height:100px;
      float:left;
    }
    <div class="box"></div>

    0 讨论(0)
提交回复
热议问题