2016-08-18 8 views
0

私は、次のしている:すべての3つのカテゴリの1マージントップを使用することができますどのようにCSS:複数のクラスに1つのプロパティ

.category-2 .content aside {margin-top: 4px;} 
.category-3 .content aside {margin-top: 4px;} 
.category-4 .content aside {margin-top: 4px;} 

答えて

3

「」複数のセレクタにあなたの財産を共有するための文字を使用します。

.category-2 .content aside, 
.category-3 .content aside, 
.category-4 .content aside 
{ 
    margin-top: 4px; 
} 

@Aaronが示唆するようにCSSをフォーマットするこの方法は、カンマ区切りセレクタと呼ばれています。

使用できる
+2

これはカンマ区切りセレクタと呼ばれています。 – Aaron

1

div[class^="category"] { margin-top: 4px; } 
1

あなたはほど

.category-2 .content aside,.category-3 .content aside,.category-4 .content aside {margin-top: 4px;}

またはそれは例えば

#category aside { margin-top:4px;}
<div id ="category"> 
 
    <div class="category-2"> 
 
    <div class="content"> 
 
     <aside> 
 
     <p>blabla</p> 
 
     </aside> 
 
     </div> 
 
    </div> 
 
    <div class="category-3"> 
 
    <div class="content"> 
 
     <aside> 
 
     <p>blabla</p> 
 
     </aside> 
 
     </div> 
 
    </div> 
 
    <div class="category-4"> 
 
    <div class="content"> 
 
     <aside> 
 
     <p>blabla</p> 
 
     </aside> 
 
     </div> 
 
    </div> 
 
    </div>
のHTML構造の残りの部分に依存して書くのいずれか

関連する問題