我用CSS設計表格時遇到問題。我使用div來包裝一個表格元素。當我將一個img標籤插入一個單元格時出現問題。 IT的高度發生變化。我試圖設置行元素的高度,但沒有運氣。這裏是example。我的目標是 添加圖像以適應所有單元格空間而不更改其大小。感謝所有幫助1高度行不匹配,因爲img標籤的存在
注意:所有行必須具有相同的高度,大小必須以百分比表示。
HTML
<div id="client">
<table>
<col id="col1" />
<col id="col2" />
<col id="col3" />
<tr>
<td rowspan="3">
<img id="profilePhoto" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTjelu9edzZ0fit_oqWGlHKS8koq1Vc56_u0XiYJynYbQmKSuQTCA" />
</td>
<td>2a</td>
<td>3a</td>
</tr>
<tr>
<td colspan="2">2b</td>
</tr>
<tr>
<td colspan="2" class="row">2c</td>
</tr>
<tr>
<td>1d</td>
<td colspan="2">2d</td>
</tr>
</table>
CSS
html {
height: 100%;
padding: 0;
margin: 0;
}
body {
height: 100%;
padding: 0;
margin: 0;
}
body #client {
outline:solid 1px;
width: 75%;
height: 25%;
overflow: hidden;
}
table {
width: 70%;
height:100%;
table-layout:fixed;
}
td {
text-align: center;
border: solid thin;
overflow: hidden;
}
#profilePhoto {
height:100%;
width:100%;
}
我不太清楚你的要求。你的意思是你想要圖像保持其自然大小,或者細胞保持其自然大小,還是其他的東西? – metadept
無論圖像@metadept如何,單元格都必須保持其大小。 – ajorquera