2016-11-23 46 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 :)

相關問題