width:-webkit-calc(100% - 150px);width:-moz-calc(100% - 150px); width:calc(100% - 150px);   Docume /*实现了 <em> 宽度 </em> 为父容器 <em> 宽度 </em> <em> 减去 </em> 固定的100 <em> 像素 </em> */ width:-webkit-calc(100% - 100px); width:-moz-calc(100% - 100px); width:calc(100% - 100px); 1.calc() 里面的公式可以加 <em> 减 </em> 乘除,而且支持rem,em算法 2. <em> 减 </em> 号的两边必须都有至少一个空格 <div class="desc ellipsis-online ellipsis-online-1"> 在编写 <em> css </em> 时,经常使用 <em> 百分比 </em> 响应适配,但是时常需要 <em> 减去 </em> 一部分达到目的,尤其是position:absolute时。所以需要在 <em> 百分比 </em> 的基础上 <em> 减去 </em> px。 <em> css </em> 3已有支持的方法: height: calc(100%-44px) 在继承父容器高度的同时 <em> 减去 </em> 44px的高度 <div class="desc ellipsis-online ellipsis-online-1"> 当我们给块级元素设置响应式高度的时候,例如给div设置height=50%,往往没能看到效果。 原因是 <em> 百分比 </em> 的大小是相对其父级元素宽高的大小,如最外层元素设置的 <em> 百分比 </em> 是对应屏幕而言的。 需要了解的是对于 <em> 宽度 </em> 来说,其父级元素无须确定 <em> 宽度 </em> 就能设置 <em> 百分比 </em> ,例如我们可以利用这个特性给未知 <em> 宽度 </em> 的块级元素设置水平居中效果: 父元素 <em> css </em> : position: relative/absolute; left: 50%; 子元素 <em> css </em> : position: relative; left: -50%; 但高度则不同,若某元素的父元素没有确定高度,则无法有效使用height=XX%的样式,我们可以这样解 </div> <div class="desc ellipsis-online ellipsis-online-1"> 在 <em> CSS </em> 中使用 <em> 百分比 </em> 来设置元素的 <em> 宽度 </em> 是一种常用的方式,而根据内容自动调节元素 <em> 宽度 </em> <em> 百分比 </em> 是一种更加智能化的设置方法。这可以通过 <em> CSS </em> 3中的Flexbox布局来实现。 Flexbox布局是一种可以自适应其容器尺寸的布局方式。在Flexbox布局中,可以使用flex-grow属性来设置元素的自动拉伸比例,让元素根据其内容的多少自动调节 <em> 宽度 </em> 。比如,当一个容器中有两个子元素时,可以在容器中设置display:flex属性,并设置子元素的flex-grow属性,让它们自动调节 <em> 宽度 </em> 。在这种情况下,如果第一个子元素的内容较少,而第二个子元素的内容较多,第二个子元素将会自动占据更多的空间。 另外,还可以使用 <em> css </em> 中的calc()函数来设置元素的 <em> 宽度 </em> 。比如,如果想让一个元素的 <em> 宽度 </em> 自适应其内容的多少,可以将元素的 <em> 宽度 </em> 设置为calc(100%/n),其中n为内容所占用的行数。这样,在元素中添加更多内容时,元素的 <em> 宽度 </em> 也会自动调节。 总之,根据内容自动调节元素 <em> 宽度 </em> <em> 百分比 </em> 是一种很实用的设置方法,在开发中可以根据实际需求选择不同的方法来实现。 </div> </div> <div class="sep10"></div> </div> </div> </div> <div class="topic_buttons"> <div class="fr gray f11" style="line-height: 12px; padding-top: 3px; text-shadow: 0px 1px 0px #fff;">   </div> </div> </div> <div class="sep5"></div> <div class="box"> <div class="cell"> <span class="gray">推荐文章</span> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/W1ivCAJO7z" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/W1ivCAJO7z">会开车的匕首</a>  ·  <a target="_blank" href="http://code.python88.com/l/lTtPZG3X2x">gitlab注册密码要求minimum-掘金</a> </span> <div class="sep5"></div> <span class="fade">9 月前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/POw4jZmGcM" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/POw4jZmGcM">无邪的单杠</a>  ·  <a target="_blank" href="http://code.python88.com/l/CKWqBx77XD">如何使用 T-SQL 計算年齡 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/xicZrXpoZ0" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/xicZrXpoZ0">风流的手术刀</a>  ·  <a target="_blank" href="http://code.python88.com/l/S8FGyRwzk5">ASP.NET Core 的 Razor 语法参考 | Microsoft Learn</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/FhByKHduMt" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/FhByKHduMt">从容的椰子</a>  ·  <a target="_blank" href="http://code.python88.com/l/Fe0N8S4YTP">SpringBoot——配置文件里的全局变量_springboot 全局变量_yeapT的博客-CSDN博客</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/gj4c1DO4IL" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/gj4c1DO4IL">开心的炒饭</a>  ·  <a target="_blank" href="http://code.python88.com/l/aPZdVjFpY2">RowMapper是什么?怎么用?_Fishsr的博客-CSDN博客</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> </div> <div class="sep5"></div> <div class="box"> <div class="cell"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- 普通广告(正在使用) --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-1837452791782084" data-ad-slot="6787195013" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="sep5"></div> </div> </div> <div class="c"></div> <div class="sep20"></div> </div> <div id="Bottom"> <div class="content footer"> <div class="inner"> <div class="sep10"></div> <div class="fr"> </div> <strong> <a href="http://www.jintiankansha.me/" class="dark" target="_blank">今天看啥</a>   <span class="snow">·</span>   <a href="http://www.python88.com/" class="dark" target="_blank">Py中国</a>   <span class="snow">·</span>   <a href="http://www.codingpro.cn/" class="dark" target="_blank">codingpro</a>   <span class="snow">·</span>   <a href="http://t.linkmax.top" class="dark" target="_blank">藏经阁</a>   <span class="snow">·</span>   <a href="http://baike.linkmax.top" class="dark" target="_blank">小百科</a>   <span class="snow">·</span>   <a href="http://www.linkmax.top" class="dark" target="_blank">link之家</a>   <span class="snow">·</span>   <a href="http://www.wolongai.cn" class="dark" target="_blank">卧龙AI搜索</a> </strong> <div class="sep10"></div> 删除内容请联系邮箱 2879853325@qq.com <div class="sep10"></div> Code - 代码工具平台 <div class="sep10"></div> <span class="f12 gray">© 2024 ~ <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow">沪ICP备11025650号</a></span> <div class="sep10"></div> </div> </div> </div> <script type="text/javascript" src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/highlight.js/9.2.0/highlight.min.js"></script> <script type="text/javascript" src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jqueryui/1.9.2/jquery-ui.min.js"></script> <script type="text/javascript" src="/static/js/site/base/common.js?v=97646d06e4a04b2bf43b7b467cfd321e"></script> <script type="text/javascript" src="/static/js/site/base/v2ex.js?v=d41d8cd98f00b204e9800998ecf8427e"></script> <script type="text/javascript" src="/static/js/site/base/base.js?v=4734e41dc8139093c113d6a48489a0f4"></script> <script> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?94b9935d8881b2e37490d19acfb0f6e4"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-P95KGR6D7D"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-P95KGR6D7D'); </script> <script> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <!-- 多条广告如下脚本只需引入一次 --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer"> </script> <script type="text/javascript" src="/static/js/site/post/post_common.js?v=8d0f2fe55813416f744bc961e1768685"></script> </body> </html>