避免在内容和 :after 之间换行
Avoid line break between content and :after
我对 HTML 元素的内容和它的 :after 内容之间的换行符有疑问。
它是一个 sortable table 并且在 table 的头部是一个小箭头。
您可以在这张 fiddle http://jsfiddle.net/ceuwob93/ 或这张图片上看到它:
显然我不想在箭头前面换行。
table {
width: 300px;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
th.sort-down:after {
content: '';
float: right;
margin-top: 7px;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
http://jsfiddle.net/ceuwob93/1/
position:absolute !important;
只需将浮动更改为绝对位置。
与其浮动伪元素,不如尝试绝对定位。
table {
width: 300px;
vertical-align: top;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
.sort-down {
position: relative;
padding-right: 12px;
}
.sort-down:after {
content: '';
position: absolute;
bottom: 0;
right: 0;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
<table>
<thead>
<tr>
<th>Column 1</th>
<th class="sort-down">Problem</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some long long long Text</td>
<td>Yes</td>
<td>Some other long long long text</td>
</tr>
</tbody>
</table>
您可以按照建议操作并为您的列设置固定宽度,或者如果您想要更灵活的方法,您可以为您的 :after 元素使用定位。
table {
width: 300px;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
.sort-down {
padding-right: 1.5em;
position:relative;
}
.sort-down:after {
content: '';
position:absolute;
top:7px;
right:5px;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
<table>
<thead>
<tr>
<th>Column 1</th>
<th class="sort-down">Problem</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some long long long Text</td>
<td>Yes</td>
<td>Some other long long long text</td>
</tr>
</tbody>
</table>
我对 HTML 元素的内容和它的 :after 内容之间的换行符有疑问。 它是一个 sortable table 并且在 table 的头部是一个小箭头。
您可以在这张 fiddle http://jsfiddle.net/ceuwob93/ 或这张图片上看到它:
显然我不想在箭头前面换行。
table {
width: 300px;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
th.sort-down:after {
content: '';
float: right;
margin-top: 7px;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
http://jsfiddle.net/ceuwob93/1/
position:absolute !important;
只需将浮动更改为绝对位置。
与其浮动伪元素,不如尝试绝对定位。
table {
width: 300px;
vertical-align: top;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
.sort-down {
position: relative;
padding-right: 12px;
}
.sort-down:after {
content: '';
position: absolute;
bottom: 0;
right: 0;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
<table>
<thead>
<tr>
<th>Column 1</th>
<th class="sort-down">Problem</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some long long long Text</td>
<td>Yes</td>
<td>Some other long long long text</td>
</tr>
</tbody>
</table>
您可以按照建议操作并为您的列设置固定宽度,或者如果您想要更灵活的方法,您可以为您的 :after 元素使用定位。
table {
width: 300px;
}
thead {
background-color: #ddd;
border-bottom: 1px solid #bbb;
}
.sort-down {
padding-right: 1.5em;
position:relative;
}
.sort-down:after {
content: '';
position:absolute;
top:7px;
right:5px;
border-width: 0 4px 4px;
border-style: solid;
border-color: #404040 transparent;
}
<table>
<thead>
<tr>
<th>Column 1</th>
<th class="sort-down">Problem</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Some long long long Text</td>
<td>Yes</td>
<td>Some other long long long text</td>
</tr>
</tbody>
</table>