search

Home  >  Q&A  >  body text

stackoverflow - Css3 calc()定制自适应宽度

casperOne:我想用CSS设置一个50px的 p ,不能超过100%宽度,也不用JavaScript。如何实现?

伊谢尔伦伊谢尔伦2864 days ago674

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 11:06:13

    Derek: can be implemented, but you don’t need to use IE’s expression(), but use Calc() in CSS3.

    p {
        width: 100%;
        width: -webkit-calc(100% - 50px);
        width: -moz-calc(100% - 50px);
        width: calc(100% - 50px);
    }

    Demo: http://jsfiddle.net/thirtydot/Nw3yd/66/

    This is very convenient, but it should be noted that there are currently only 3 browsers that support CSS3: Firefox, Google Chrome (WebKit) and IE9

    Detailed explanation of Calc attribute: https://developer.mozilla.org/zh-CN/docs/CSS/calc

    reply
    0
  • Cancelreply