2013-02-07 84 views
1

下面的CSS似乎正在做我想要的。只是想知道它是否可以修剪,仍然做同樣的事情。有沒有辦法讓這個CSS更簡潔?

.qr-setup { 
    text-align: center ; 
    margin-left: auto ; 
    margin-right: auto ; 
    width:40% ;} 

.qr-setup table { 
    text-align: center ; 
    margin-left: auto ; 
    margin-right: auto ; 
    width:80% ; 
} 

.qr-setup table tr td { 
    border: none; 
    text-align: center ; 
    margin-left: auto ; 
    margin-right: auto ; 
    width:80% ; 
} 

回答

2
.qr-setup, .qr-setup table, .qr-setup tr td { 
    text-align: center ; 
    margin-left: auto ; 
    margin-right: auto ; 
    width: 80%;} 

.qr-setup { 
    width:40% ; 
} 

.qr-setup table tr td { 
border: none; 

}

+0

@ user1147171僅供參考,除非這些表格從其他地方獲得保證金,否則您不需要'margin:auto'因爲它默認爲自動。 – Leeish

+0

謝謝大家! @Leeish,值得記住。在這種情況下,邊際是必要的。 – user1147171

2

你只需要這樣:

.qr-setup { 
    width:40%; 
} 

.qr-setup table, .qr-setup table tr td { 
    width:80%; 
} 

.qr-setup table tr td { 
    border: none; 
} 

.qr-setup, .qr-setup table, .qr-setup table tr td { 
    text-align: center; 
    margin-left: auto; 
    margin-right: auto; 
} 

您可以使用逗號,重複的CSS爲所有的上市。

+0

我認爲他仍然需要在td上的寬度,因爲寬度不會被繼承。 – Leeish

+0

對不起固定那 – jackcogdill

+0

什麼? 「保證金」值不會這樣做:http://jsfiddle.net/kEkvm/1/ –

0

甚至還有

margin-left: auto; 
margin-right: auto; 

margin:0 auto; 

速記代碼設置上邊距和下邊距爲0,保證金左和保證金 - 對汽車。

相關問題