如何制作 XHTML“表格” 带有流体表行
基本上我希望能够制作一个盒子网格,其中我可以在每个盒子的顶部中间和底部对齐文本,并且当其行上另一个盒子中的文本将其向下推时,同一行上的盒子会调整大小。
如果你看一下这个 HTML 4 代码,它实现了我想要做的事情,但我希望能够使用 XHTML 1.0 文档类型来实现这一点。
<style type="text/css">
<!--
#apDiv1 {
width:200px;
height:100%;
border:1px solid #000;
}
#apDiv1 table{
width:200px;
height:100%;
border:1px solid #000;
}
-->
</style>
<div id="apDiv1"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr><td height="100%">blah</td></tr>
<tr><td>blah</td></tr>
</table>
</td>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr>
<td height="100%"><p>blahfhfh</p>
<p>dfhdf</p>
<p>h</p>
<p>dfh</p>
<p>df</p>
<p>h</p>
<p> </p></td></tr>
<tr><td>blah</td></tr>
</table>
</td>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr><td height="100%">blah</td></tr>
<tr><td>blah</td></tr>
</table>
</td>
</tr>
<tr>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%"><p>blahfhfh</p>
<p>dfhdf </p>
<p> </p></td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
</tr>
</table>
</div>
Basically i want to be able to make a a grid of boxes, where i can align text at the top middle and bottom of each box, and have the boxes on the same row resize when text in another box on its row pushes it down.
If you look at this HTML 4 code, it achieves what i want to be able to do, but id like to be able to achieve this with the XHTML 1.0 doctype.
<style type="text/css">
<!--
#apDiv1 {
width:200px;
height:100%;
border:1px solid #000;
}
#apDiv1 table{
width:200px;
height:100%;
border:1px solid #000;
}
-->
</style>
<div id="apDiv1"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr><td height="100%">blah</td></tr>
<tr><td>blah</td></tr>
</table>
</td>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr>
<td height="100%"><p>blahfhfh</p>
<p>dfhdf</p>
<p>h</p>
<p>dfh</p>
<p>df</p>
<p>h</p>
<p> </p></td></tr>
<tr><td>blah</td></tr>
</table>
</td>
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>blah</td></tr>
<tr><td height="100%">blah</td></tr>
<tr><td>blah</td></tr>
</table>
</td>
</tr>
<tr>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%"><p>blahfhfh</p>
<p>dfhdf </p>
<p> </p></td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
<td><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>blah</td>
</tr>
<tr>
<td height="100%">blah</td>
</tr>
<tr>
<td>blah</td>
</tr>
</table></td>
</tr>
</table>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种使用 CSS 实现网格的跨浏览器方法 和
display:inline-block
,但是它可能没有您想要的那么灵活(如果您想支持 Firefox 2,代码会非常难看)。“XHTML”可能存在的问题是,没有模拟 IE5 错误的 CSS(当您不使用 DOCTYPE 或使用旧的/不完整的类型之一时会出现此错误)限制了您何时可以使用
height:100%< /代码>。
如果父元素具有自动高度,则以百分比表示的高度不起作用,并且默认情况下几乎每个 HTML 元素都具有自动高度。 您必须在表格的所有父元素上设置显式高度:
There's a cross-browser way to achieve grid using CSS with
display:inline-block
, however it may not be as flexible as you'd like (and code is pretty ugly if you want to support Firefox 2).The issue you might have with “XHTML” is that CSS without emulation of IE5 bugs (which you get when you don't use DOCTYPE or use one of old/incomplete ones) restricts when you can use
height:100%
.Height in percent doesn't work if parent element has
auto
height, and by default almost every HTML element has auto height. You have to set explicit height on all parent elements of the table:首先,使您的文档具有严格的 HTML 4.01 的 DOCTYPE 并首先使用 http://validator.w3.org 对其进行验证
然后,您可以将 DOCTYPE 更改为
,然后重新验证它。 如果有任何问题或行为不同,您可以在此处询问具体问题。
first, make your document have the DOCTYPE of HTML 4.01 strict and make it validated first, using http://validator.w3.org
then, you can change the DOCTYPE to
and then re-validate it. If there is any problem or things that behave differently, you can ask about the specific question here.