CSS选择器来选择第一个和第二个表格单元格 [英] CSS Selector to select first and second table cells
本文介绍了CSS选择器来选择第一个和第二个表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此选项,当然会选择所有单元格:
table td {
width:50px;
}
我想要的是:
< table>
< tr>
< td style =width:50px>第一列中的数据< / td>
< td style =width:180px>第二栏数据< / td>
< / tr>
< tr>
< td style =width:50px>第一列中有更多数据< / td>
< td style =width:180px>更多数据在第二列< / td>
< / tr>
< / table>
我想将宽度指定放在样式表中,而不是为每个元素隐式地输入宽度标签。什么CSS选择器会让我适当地设置50px宽度和180px?
解决方案
是的。
td:first-child {
width:50px;
}
td:nth-child(2){
width:180px;
}
或者,如Brainslav编辑建议的那样:
td:nth-child(1){
width:50px;}
td:nth-child(2){
width:180px;}
Can someone help me figure what selectors I need to change the width of my columns globally on my two column table?
Using this, will of course select all cells:
table td {
width: 50px;
}
What I want is this:
<table>
<tr>
<td style="width: 50px">data in first column</td>
<td style="width: 180px">data in second column</td>
</tr>
<tr>
<td style="width: 50px">more data in first column</td>
<td style="width: 180px">more data in second column</td>
</tr>
</table>
I'd like to put the width specification in a style sheet rather then typing the width implicitly for each tag. What CSS selector will let me set the 50px width and 180px appropriately?
解决方案
Yep.
td:first-child{
width:50px;
}
td:nth-child(2){
width: 180px;
}
or, as suggested by Brainslav's edit:
td:nth-child(1) {
width: 50px;}
td:nth-child(2) {
width: 180px;}
这篇关于CSS选择器来选择第一个和第二个表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文