CSS value as mathematical expression

前端 未结 4 1152
一向
一向 2021-02-07 07:30

Is there anyway that I can write a css value as mathematical expression? Example:

div{
    height: 50% + 30px;
    width: 40em - 5px;
   }

If t

4条回答
  •  情深已故
    2021-02-07 07:51

    You can achieve this with css3 calc(). Write like this:

    div{
        width: 40%;
        width: -webkit-calc(40% - 5px);
        width: -moz-calc(40% - 5px);
        width: calc(40% - 5px);
        height:50%;
        height: -webkit-calc(50% + 50px);
        height: -moz-calc(50% + 50px);
        height: calc(50% + 50px);
        background: green;
        color: white;
        position:absolute;
    }
    

    Check this http://jsfiddle.net/3QUw6/

    Check this discussion for more Is it possible to make a div 50px less than 100% in CSS3?

提交回复
热议问题