html - 开始隐藏(基于父元素)会用 Bootstrap 4 弄乱孩子的样式
问题描述
我想向影响许多内部元素的父 DIV 添加一个类。但是当我使用 Bootstrap 执行此操作时,样式会变得混乱。
此代码显示了 2 上的问题,您可以看到底部边框未对齐。如果我只是在元素上执行 .toggle(".second") ,它将起作用。
https://www.bootply.com/KOJ4VKNbOa
.second {
display: none;
}
.show-inner .second {
display: block;
}
<div id="outer">
<table class="table">
<thead>
<tr>
<th class="first">A</th>
<th class="second">B</th>
<th class="third">C</th>
</tr>
</thead>
<tbody>
<tr>
<td width="98%" class="first">1</td>
<td width="1%" class="second">2</td>
<td width="1%" class="third">3</td>
</tr>
</tbody>
</table>
</div>
<button onclick="$('#outer').toggleClass('show-inner');">Toggle .second</button>
在我的项目中,我希望有许多外部 DIV 类的依赖项,因此让它工作将为我节省大量代码。
解决方案
使用 display: table-cell 代替块。
.show-inner .second {
display: table-cell;
}
推荐阅读
- jenkins - 如何解决远程节点上的 Jenkins 的 java.nio.file.AccessDeniedException?
- sql-server - 在 sql 中,您如何循环遍历 xquery 中的单例值以获取 xml?
- css - 如何更改 Bootstrap 4 中类 .active 列表项的默认背景颜色?
- python - 需要 Python3 的帮助
- java - 为什么这个三元运算返回空指针异常?
- python - 有什么方法可以将 f 字符串合并到标识符中?
- javascript - 关闭后不显示引导模式
- python - wide to long with multiple header rows and merged cells
- python - 如何使用自定义度量(设置距离)构造成对距离矩阵?
- weka - 将 Weka Fiji 插件分段导出为 ROI