jquery - 为什么内联元素在html中占用更多宽度
问题描述
你能告诉我为什么内联元素需要更多宽度吗
这是我的代码 https://jsbin.com/jawoyutuhi/1/edit?html ,输出
为什么要占用这个空间。
<html>
<style>
.red {
color: red;
}
.mb-0 {
margin-bottom: 0;
}
.inlineBlock {
display:inline-block
}
.customInput {
border: none;
outline: none;
border-bottom: 1px solid black;
width: 100%;
}
.customInputContainer {
font-size: 10px;
padding-top: 4px;
}
.customGridCell {
border: 1px solid black;
height: 25px;
width: 25px;
}
</style>
<head> </head>
<body>
<div style="width: 700px;height: 842px;padding: 15px">
<div>
<div class="customInputContainer inlineBlock">
<div class="inlineBlock red">
<label>
<b>
Mobile Number Alloted
<sup>*</sup>
</b>
</label>
</div>
<div class="inlineBlock" style=" width: 45%;
margin-left: 4px; padding: 0px;
vertical-align: sub;">
<table style="border-spacing: 1px;">
<tr>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
解决方案
您在.inlineBlock中有 45% 的宽度,这就是为什么宽度不是您所期望的。
您可以将其删除并将单个.customGridCell的宽度更改为您想要的任何内容:
<html>
<style>
.red {
color: red;
}
.mb-0 {
margin-bottom: 0;
}
.inlineBlock {
display:inline-block
}
.customInput {
border: none;
outline: none;
border-bottom: 1px solid black;
width: 100%;
}
.customInputContainer {
font-size: 10px;
padding-top: 4px;
}
.customGridCell {
border: 1px solid black;
height: 25px;
width: 15px;
}
</style>
<head> </head>
<body>
<div style="width: 700px;height: 842px;padding: 15px">
<div>
<div class="customInputContainer inlineBlock">
<div class="inlineBlock red">
<label>
<b>
Mobile Number Alloted
<sup>*</sup>
</b>
</label>
</div>
<div class="inlineBlock" style="
margin-left: 4px; padding: 0px;
vertical-align: sub;">
<table style="border-spacing: 1px;">
<tr>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
<td class="customGridCell"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
我刚刚删除了.inlineBlock中指定的宽度并减小了.customGridcell的宽度,你可以放任何你想要的。
请参阅JSFiddle。
推荐阅读
- python - Django:一个测试失败后所有后续测试都失败
- javascript - Mongoose 查找和查找
- mockito - 如果我们在方法内部调用私有方法,如何模拟或准备测试方法?
- sql - 如何根据 SQL 中涉及另一个表的条件对一个表中的值进行平均?
- javascript - 如何防止 Javascript 在其范围之外更改参数值?
- css - 响应较小屏幕的卡片 img 被剪切
- python - 在 Python 中对固定效应模型执行中介分析
- sql-server - 使用 INSERT 中的值插入触发器之后
- swift - SwiftUI Segmented Picker 在点击时不会切换
- postgresql - 我可以使用特殊字符来拆分聚合吗?PostgreSQL