我添加了一個僞元素與:before
並將其絕對定位到其父,可以是表或div。爲了設計目的,父母還必須具有20px邊框。絕對定位:之前在表格與div
wwhy是firefox和IE不一致的,並且在表格中對待僞元素的定位是不同的?
請看看我的jsFiddle或下面的代碼。
測試與IE10,Chrome29和FF23。
HTML:
<div>i am a div</div>
<table>
<thead>
<tr><th>header 1</th><th>header 2</th></tr>
</thead>
<tbody>
<tr><td>entry 1</td><td>entry 2</td></tr>
</tbody>
</table>
CSS:
table,
div {
border: 20px solid yellow;
position: relative;
margin-bottom: 30px;
height: 50px;
}
table:before,
div:before {
background: red;
content: " ";
position: absolute;
display: block;
position: absolute;
top: 0;
left: 0;
width: 10px;
height: 10px;
}
絕對定位的元素可能不像你期望的那樣在FF中的表格元素內表現出來。 – Itay
不知道這是否適用於您的目的,但您可以嘗試輪廓而不是邊界元素。例如:大綱:20px純黃色; –
@ D.Alexander好主意,但不是,它必須是一個邊框,因爲我也應用邊框半徑:( – nerdess