2016-11-23 47 views
-1

起初,我不能例如更改类名:我该如何左对齐一个表并右对齐使用相同类的另一个表?

<table class="firsttable"> This is the firstable that must be left align 
<tbody> 
    <tr> 
     <td> 

<table class="firsttable"> And this is the second table that must be center align 
<tbody> 
    <tr> 
     <td> 

如何在CSS代码呢?

+0

您是否试过选择器+或〜更新第二个表的CSS?如'.firsttable + .firsttable {text-alig:center}' –

+0

[在同一行上左右对齐两个内嵌块]的可能重复(http://stackoverflow.com/questions/10272605/align-two- inline-blocks-left-and-right-on-line) – user1983152

回答

0

第一个表CSS选择器:

.firsttable:first-of-type 

如果第二个表是最后:

.firsttable:last-of-type 

否则,第二个表CSS选择器是这样的:

.firsttable:nth-of-type(2) 
1

您可以使用下面的CSS ,它按预期工作

<style> 
.firsttable:nth-child(1) { text-align:left; } 
.firsttable:nth-child(2) { text-align:right; } 
</style> 

虽然是CSS3。

+0

谢谢你对我的工作。 –

0

我认为结合内联CSS会更简单。不要在你的类一致,而不是:

<table class="firsttable" style="text-align:left;"> This is the firstable that must be left align 
<tbody> 
    <tr> 
     <td> 

<table class="firsttable" style="text-align:right;"> And this is the second table that must be center align 
<tbody> 
    <tr> 
     <td> 

您也可以在课堂上对齐,如果它是有道理的,与此类大多数表,并在需要时刚好覆盖。

0

使用的ID:

HTML:

<table class="firsttable" id="table1"> 
... 
</table> 
<table class="firsttable" id="table2"> 
... 

CSS:

#table1 { 
    text-align:left; 
} 
#table2 { 
    text-align:right; 
} 

工作的呢?

-1

在这种情况下,它更好或从我的意义上说,我总是通过在表中添加内联样式来创建它,我认为他们不需要在CSS中为其创建任何其他样式。

<table class="firsttable" style="text-align:left"> This is the firstable that must be left align

,第二个表可以是文本对齐的另一个内嵌样式:中心

<table class="firsttable" style="text-align:center"> And this is the second table that must be center align

这是最好的办法。但是你可以也可以在这里创建一些不同的ID或

.firsttable:nth-child(1) { text-align:left; } 
.firsttable:nth-child(2) { text-align:center; } 

问题在这,如果你如果另一个表出现在该网页面积比它会出现一个问题,使用它即可。所以在这种情况下最好使用内联样式。

-1

如果您想将表格移动到左侧,并向右移动,请将以下内容添加到相应的表格中。

用于对齐。在开始标记<table>处添加。

style="float:right;"

对于褐藻胶留下相同的代码添加到完全相同的地方,但改变“左”“右”这取决于你希望它是。

要文字做,因为其他人已经分化。

J. Carter :)

相关问题