Pixel Border and Percentage width in Proportion

后端 未结 7 1966
误落风尘
误落风尘 2021-02-08 14:30

I think I might already know the answer to this one but I need a sanity check!

Say I have

#gridtest{
width:590px;
}

I could change the

7条回答
  •  青春惊慌失措
    2021-02-08 14:42

    You could use CSS3 calc() function,

    .selector{
      border: 5px solid black;
      width: -moz-calc(50% - 10px);
      width: -webkit-calc(50% - 10px);
      width: calc(50% - 10px);
    }
    

    SASS mixin

    @mixin calc($property, $expression) {
      #{$property}: -moz-calc(#{$expression});
      #{$property}: -webkit-calc(#{$expression});
      #{$property}: calc(#{$expression});
    }
    article {
      border: 1px solid red;
      @include calc( width, '100% - 2px')
    }
    

提交回复
热议问题