css border-width percentage

前端 未结 3 446
星月不相逢
星月不相逢 2020-12-10 18:53

I have one div wrapping another like so

Let\'s say the container

相关标签:
3条回答
  • 2020-12-10 19:06

    Short of manually calculating and specifying 50px as the border width, you can't. The border-width property only accepts lengths or the keywords thin, medium and thick.

    As Saad Imran suggests, you might be able to just use two divs with 50% width each.

    0 讨论(0)
  • 2020-12-10 19:14

    Just change px to vw like

    border-width: 10px;
    

    to

    border-width: 10vw;
    

    Its do whats percentage do....

    0 讨论(0)
  • 2020-12-10 19:27

    You can do what you are after, but using linear-gradients instead of borders.

    Use the following markup:

    <div class="box"></div>​
    

    And the following styles (example: http://jsfiddle.net/HxbnK/):

    .box {
        background-image: linear-gradient(154deg, red 50%, transparent 50%),
                          linear-gradient(26deg, red 50%, transparent 50%);
        background-position: 0 0, 100% 0;
        background-repeat: no-repeat;
        background-size: 50% 100%;
        height: 100px;
        width: 100px;
    }​
    

    Just keep in mind that the .box element needs to be a square for this to work correctly.

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