[英]How to add a dotted line or add padding to td border
下圖已經接近我正在尋找的解決方案(請參閱我的代碼筆)。 唯一缺少的是<tbody>
或<thead>
的輪廓邊框與<td>
的邊框之間的填充/間隙
你可以看看codepen 上的代碼。 我的 CSS 方法是這樣的
table { width: 100%; } /** outline: 0.5pt solid; outline-color: black; border-spacing: .2em 0em; **/ thead, tbody { outline: 0.5pt solid; outline-color: black; } th.sgn { border-bottom: 1pt dotted blue; padding-top: 1ex;} td.sgn { border-bottom: 1pt dotted blue; padding-top: 1ex;}
<table> <colgroup> <col width="20%"> <col width="35%"> <col width="15%"> <col width="30%"> </colgroup> <thead> <tr> <th>Werkzeugnr:</th> <th class="sgn"> </th> <th>Index</td><th class="sgn"></th> </tr> <tr class="sml"> <th colspan="4"> </th> </tr> </thead> <tbody> <tr><th colspan="4"><h3>Bitte ausfüllen und abheften:</h3></th></tr> </tbody> <tbody> <tr> <td>Einbaudatum;</td><td class="sgn"> </td> <td>Name</td><td class="sgn">  :</td> </tr> <tr><td>Anlaufprobleme:</td><td><input type="checkbox"></td><td colspan="2">Bitte Grund angeben</td> </tr> </tbody> </table>
我將使用::before
和::after
偽類實現該間距。
.spaced
)。<td class="spaced sgn" colspan="3"> </td>
relative
值 position,這樣::before
和::after
就相對於它定位:.spaced {
position: relative;
}
::before
和::after
添加為您想要的width
作為空間,並分別向左和向右添加 position:.spaced::before,
.spaced::after {
content: "";
position: absolute;
width: 1rem;
height: 1rem;
background: white;
bottom: -0.5rem;
}
.spaced::before {
left: 0;
}
.spaced::after {
right: 0;
}
如果您必須創建類似於上圖的內容,您會采用什么方法?
CSS 偽元素非常適合這個用例。
.sgn::after {
content: '';
position: absolute;
border-bottom: 2px dotted blue;
width: 20%;
}
您可以根據自己的喜好進行調整,我無法弄清楚讓它工作的寬度,但我相信您可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.