gpt4 book ai didi

css - HTML CSS 防止跨度容器间隙

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:42 26 4
gpt4 key购买 nike

我做了这个小例子来说明我的问题。我有几个跨度容器,如果两个在一列中,则跨度容器比只有一个跨度容器的容器长一点:

My JS Fiddle Example

<span class="times">
<span class="timeType cursorPointer">
<span>D</span>
</span>
<span>
09:00 - 12:00
</span>
</span>
<span class="times">
<span class="timeType cursorPointer">
<span>N</span>
</span>
<span>
14:00 - 17:00
</span>
</span>

有谁知道如何防止这种情况发生?所以这应该被阻止:

enter image description here

最佳答案

你可以设置一个 min-width 到 span,所以无论单个字符在 中,span 都将是相同的大小。

Inline-block 是允许大小调整所必需的。

.times {
padding: 2px;
margin-left: 2px;
border: 1px solid #ddd;
color: #000;
background-color: #fff;
display: inline-block;
}

span span {
display: inline-block;
min-width: 1em;
}

了解它来自使用的字符......

否则你可以使用另一个字体系列 ( W3C font-family: see monospace ) 而不会发生这种情况,例如 courier

注意 inline-block 的使用让每个框在流程中都表现为一个简单的片段/包装器。

.times {
padding: 2px;
margin-left: 2px;
border: 1px solid #ddd;
color: #000;
background-color: #fff;
display: inline-block;
text-align: center;
}
.times {
font-family: courier;
}
<table class="weekTable">
<tr>
<th></th>
<tr>
<td>
<span>
<span class="times">
<span class="timeType cursorPointer" ng-dblclick="vm.ScheduleIntervalContainerPropertiesModal(userScheduleManagementWeeksContainer, scheduleIntervalContainers, scheduleIntervalContainer)">
<span>D</span>
</span>
<span>
09:00 - 12:00
</span>
</span>
<span class="times">
<span class="timeType cursorPointer" ng-dblclick="vm.ScheduleIntervalContainerPropertiesModal(userScheduleManagementWeeksContainer, scheduleIntervalContainers, scheduleIntervalContainer)">
<span>N</span>
</span>
<span>
14:00 - 17:00
</span>
</span>
</span>
</td>
</tr>
<tr>
<td>
<span>
<span class="times">
<span class="timeType cursorPointer" ng-dblclick="vm.ScheduleIntervalContainerPropertiesModal(userScheduleManagementWeeksContainer, scheduleIntervalContainers, scheduleIntervalContainer)">
<span>M</span>
</span>
<span>
09:00 - 12:00
</span>
</span>
</span>
</td>
</tr>
</table>

https://jsfiddle.net/q3jgytoq/4/

关于css - HTML CSS 防止跨度容器间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35505198/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com