我正在开发一些同时使用 div 和表来呈现数据块的代码。表格元素按预期呈现,但 div 超出了页面的宽度。下面的示例代码是我的项目中产生问题的代码的最小选择。如您所见,两个元素都使用同一个类“contentblock”来指定 100% 宽度。Chromium 版本 25.0.1364.160 Ubuntu 12.04 (25.0.1364.160-0ubuntu0.12.04.1)。
<html><body>
<style>
.contentblock {
width: 100%;
border: 1px solid #000;
padding: .5em;
}
p {
margin-bottom: 1em;
}
</style>
<div class="contentblock">
<p><span class="label">LOREM IPSUM SIC DOLOR</span></p>
<p>Praesent aliquam varius dolor. Vestibulum at sem sed augue interdum condimentum eget ornare urna. Nullam blandit auctor bibendum. Cras hendrerit iaculis venenatis. Curabitur interdum, lorem quis feugiat interdum, urna sapien ultricies nisl, in pretium diam arcu ac eros. Fusce elit tellus, euismod at aliquet non, pulvinar at sapien. Aliquam molestie ante in augue convallis a malesuada nulla posuere. Aliquam blandit massa a eros viverra semper. </p>
</div>
<table class="contentblock">
<tr>
<th class="label"><span class="label">Lorem</span></th>
<th class="checkbox"><span class="label">Ipsum</span></th>
<th class="checkbox"><span class="label">Dolor</span></th>
<th class="checkbox"><span class="label">Aliquam</span></th>
<th class="initialbox"><span class="label">Dictum</span></th>
</tr>
</table>
</body></html>