html - 重置或忽略 CSS 中的(最大)宽度
问题描述
我有以下代码(codepen)
/******* NO ACCESS ********************/
.container {border: 1px solid green;}
.container > div {border: 1px solid red;}
.container .header {max-width: 50%;}
/**************************************/
.container.reset-header .header {max-width: auto;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-4 picture">col-4</div>
<div class="col-4 header">col-4 modified to 50%</div>
</div>
<div class="container reset-header">
<div class="col-4 picture">col-4</div>
<div class="col-4 header">should be reset to col-4</div>
</div>
我无法修改无法访问的 css,但我想使用“重置”类重置 col-4 宽度。我试过了auto
,uset
或者inherit
,他们中的任何一个都没有给我33,33%
- 作为col-4
(或代码中设置的任何其他 html 属性)
.container.reset-header .header {max-width: auto; }
.container.reset-header .header {max-width: unset; }
.container.reset-header .header {max-width: inherit;}
但这没有帮助
解决方案
您可以使用相同的值col-4
来重置最大宽度。
像这样的东西很好用:
.container.reset-header .header {
max-width: 33.333333%; /* value of col-4 */
}
编辑:
您如何看待此解决方案,它有点棘手,但在视觉上您将获得正确的渲染:
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-4 picture">col-4</div>
<div class="col-4 header">col-4 modified to 50%</div>
</div>
<div class="container reset-header">
<div class="col-4">
<span class="picture">col-4</span>
<span class="header">should be reset to col-4</span>
</div>
</div>
/******* NO ACCESS ********************/
.container {border: 1px solid green;}
.container > div {border: 1px solid red;}
.container .header {max-width: 50%;}
/**************************************/
.container.reset-header > div{
border: none;
padding: 0;
}
.container.reset-header span{
display: block;
border: 1px solid red;
}
.container.reset-header .header {
max-width: 100%;
}
推荐阅读
- python - 为什么我会收到此错误?(object.__init__() 不带参数)
- pandas - 添加特定于行的时间增量(日期时间清洗)(日期时间)
- javascript - Javascript函数中的布尔返回
- python - 如何在不评估的情况下获取类属性?
- html - HTML 标头不显示
- javascript - Puppeteer - 自定义字体未加载到 pdf 中,但确实出现在屏幕截图中
- android - 连接webapp和android
- html - 如何在 diff. 解析度
- python - 如何使pygame中的对象旋转
- java - 获取 java.lang.ClassCastException:使用 FlatMap 时无法将类 lambda.Student 强制转换为类 java.lang.Comparable