Html 如何使用 CSS 使 TD 表现得像 TR(row)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6773862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:40:10  来源:igfitidea点击:

How to make TD behaving like TR(row) with CSS?

htmlcsshtml-table

提问by Bar?? Velio?lu

I have a component that create dynamically html table. According to my need, I need to show td tags line by line as a block element not like column. How to do that by using CSS ?

我有一个动态创建 html 表的组件。根据我的需要,我需要将 td 标签逐行显示为块元素,而不是列。如何通过使用 CSS 来做到这一点?

回答by thirtydot

You can do this by applying display: blockto the tds:

您可以通过应用display: blocktds来做到这一点:

http://jsfiddle.net/wYA9K/

http://jsfiddle.net/wYA9K/

That works in all modern browsers except IE9..

这适用于除 IE9 之外的所有现代浏览器。

Using float: left; width: 100%instead makes it also work in IE8/9:

使用float: left; width: 100%它也可以在 IE8/9 中工作:

http://jsfiddle.net/gvpzh/

http://jsfiddle.net/gvpzh/

Nothing will make it work in IE7.

没有什么可以使它在 IE7 中工作。

回答by Shef

Try this:

试试这个

td{
    display: table-row
}

回答by Mr.T.K

i am not sure this your expecting solution.

我不确定这是您期望的解决方案。

Please check this out : http://jsfiddle.net/thilakar/mPdd7/2/

请检查一下:http: //jsfiddle.net/thilakar/mPdd7/2/

回答by samy

You can use the display: blockcss property as shown in this fiddle

您可以使用此小提琴中display: block所示的css 属性

回答by Umut

you can use colspan attribute

您可以使用 colspan 属性

<tr>
<td colspan="2">some content</td>
</tr>

this will make a cell that spans two columns

这将制作一个跨越两列的单元格