将元素宽度指定为像素百分比的方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将元素宽度指定为像素百分比的方法相关的知识,希望对你有一定的参考价值。

  1. /*
  2.  
  3. Based on Stu Nicols demo at http://www.cssplay.co.uk/boxes/outside.html
  4.  
  5. Set the percentage width on the out element and the extra pixels-based width extension on the inner using negative margins
  6.  
  7. */
  8.  
  9. .outside {
  10. position: relative;
  11. width: 25%;
  12. background: #9caf9c;
  13. color: #fff;
  14. margin: 1em auto;
  15. }
  16. .inside {
  17. display: block;
  18. position: relative;
  19. color: #000;
  20. margin: 0 -50px;
  21. background: #c4c4c4;
  22. color: #000;
  23. }
  24.  

以上是关于将元素宽度指定为像素百分比的方法的主要内容,如果未能解决你的问题,请参考以下文章