2016-05-20 17 views
2

CSS コンテンツの値を持つアイコンを別のクラスに追加しようとしています。マークアップの中には複数のクラスがあるものもあります。この場合、テキストの後ろに複数のアイコンが必要です。問題は、複数のコンテンツを同じクラスに追加することができるかどうかはわかりません。複数のクラスを含むマークアップ用の複数のCSSコンテンツ

例:クラスは、例えば、ある場合には

.entry-header::after {font-family: FontAwesome; font-size: 15px; /*float: right;*/} 

.status-private > .entry-header::after { 
    content: " \f023" 
} 
.format-standard > .entry-header::after { 
    content: " \f040" 
} 
.format-video > .entry-header::after { 
    content: " \f03d" 
} 

.status-privateロゴが表示されますが、マークアップにの2つのクラスがある場合はどうなりますか?のような.status-private .format-standard?どうすれば2つのアイコンを表示できますか?

可能であれば、私はこれらの3つのクラスのすべての可能な組み合わせに対してCSSを作成する必要はありません。

私の現在のマークアップ:

<article id="post-1713" class="post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video"> 
    <header class="entry-header"> 

     <div class="entry-date"> 
      May 20, 2016 
     </div> 

     <div class="entry-title post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video"> 
      Private: Private: This is a video post 
     </div> 

    </header><!-- .entry-header --> 

    <div class="entry-content" data-did-load="true" style="display: none;"> 
     <p> 
      The format of this post is video, but the video has not yet been added 
     </p> 
    </div><!-- .entry-content --> 
</article> 

は、私がプライベート後にアイコンを表示したい:これは、あなたが同じ要素に複数の擬似要素を持つことができませんビデオのポスト

+0

表示したい場合は* 2つの*クラスがある場合、あなたは残念ながら、新しいセレクタでそれを指定する必要があります異なる*内容* HTMLコード – keziah

+0

をご提示ください。 – TylerH

答えて

4

です。可能であれば、元の回答に記載されているように、ちょうど::after::afterを持っていても、重複を避けることはできません。

これは私が純度よりも実用性を好む場所です。例:私はちょうど::afterなど

アップデート1でまだCSSでこれらをCSS class ESのそれぞれと各ステータスの空spanを追加し、ターゲットにしたい

.entry-header > .icon::after {font-family: FontAwesome; font-size: 15px; /*float: right;*/} 
 

 
.entry-header > .icon-status-private::after { 
 
    content: " \f023" 
 
} 
 

 
.entry-header > .icon-format-standard::after { 
 
    content: " \f040" 
 
} 
 
.entry-header > .icon-format-video::after { 
 
    content: " \f03d" 
 
}
<!-- To show icons --> 
 
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" /> 
 

 

 
<div class="status-private"> 
 
    <div class="entry-header"> 
 
    <span class="icon icon-status-private"></span> 
 
    Private 
 
    </div> 
 
</div> 
 

 
<div class="status-private"> 
 
    <div class="entry-header"> 
 
    <span class="icon icon-status-private"></span> 
 
    <span class="icon icon-format-standard"></span> 
 
    Private Article 
 
    </div> 
 
</div> 
 

 
<div class="status-private"> 
 
    <div class="entry-header"> 
 
    <span class="icon icon-status-private"></span> 
 
    <span class="icon icon-format-standard"></span> 
 
    <span class="icon icon-format-video"></span> 
 
    Private Video Article 
 
    </div> 
 
</div>

注:[class=*'icon-']に最初のCSSラインの.iconを変更し、冗長を削除することができますのクラス。

プログラミング言語(ServersideまたはJavaScript)を使用している場合は、プログラミングチェックを使用して、それぞれspanをHTMLに書き込むことができます。

アップデート2:あなたは本当に-があるとしてHTMLを維持する必要がある場合は、HTMLの変更

を回避します。私は恐れているセレクタを複製する必要があります。

あなたの特定の状況では、実際にはそれほど悪くはありません。ここにあなたの更新の質問HTMLからの完全な例です:

.entry-header::after { 
 
    font-family: FontAwesome; 
 
    font-size: 15px; 
 
    float: right; 
 
} 
 

 
.format-standard > .entry-header::after { 
 
    content: " \f040"; 
 
} 
 
.status-private.format-standard > .entry-header::after { 
 
    /*Had to put 2 spaces to make the icons separate */ 
 
    content: " \f023 \f040"; 
 
} 
 

 
.format-video > .entry-header::after { 
 
    content: " \f03d"; 
 
} 
 
.status-private.format-video > .entry-header::after { 
 
    /*Had to put 2 spaces to make the icons separate */ 
 
    content: " \f023 \f03d"; 
 
} 
 

 
/* Might not be needed now */ 
 
.status-private > .entry-header::after { 
 
    content: " \f023"; 
 
}
<!-- To show icons --> 
 
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" /> 
 

 

 
<article id="post-1713" class="post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video"> 
 
    <header class="entry-header"> 
 

 
     <div class="entry-date"> 
 
      May 20, 2016 
 
     </div> 
 

 
     <div class="entry-title post-1713 post type-post status-private format-video hentry category-uncategorized post_format-post-format-video"> 
 
      Private: Private: This is a video post 
 
     </div> 
 

 
    </header><!-- .entry-header --> 
 

 
    <div class="entry-content" data-did-load="true" style="display: none;"> 
 
     <p> 
 
      The format of this post is video, but the video has not yet been added 
 
     </p> 
 
    </div><!-- .entry-content --> 
 
</article>

+0

私はあなたが意味するものを得ると思います。しかし、私はこれで少し緑色です。ごめんなさい。例を挙げてください。 – Arete

+0

質問に今追加しました。このアプローチは少し複雑です(HTMLを変更する必要があります)が、それはセレクタを繰り返すことです(あなたのケースではあまり正直ではありません)。 – Meligy

+0

ありがとうございます。私はあなたが私に与えたものに取り組もうとしました。しかし、私は別のマークアップを持っているので、私はかなり素早く失われました。私はまた、Wordpressの各ポストフォーマットに1つの「span」を追加する方法を見つけることができませんでした。可能であれば、マークアップを反映するために例を更新してください。もしあなたがしたら、私は永遠に感謝しています。再度、感謝します! – Arete

0

も、このように複数のコンテンツを追加することができます。

div::after{ 
 
    font-family: FontAwesome; 
 
} 
 
.icon::after{ 
 
    content: "\f03d"; 
 
    font-size: 30px; 
 
} 
 
.icon.icon2::after{ 
 
    content: "\f023 \f03d \f023"; 
 
    font-size: 30px; 
 
}
<head> 
 
    <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"> 
 
</head> 
 

 
<div class="icon"></div> 
 
<div class="icon icon2"></div>

+1

質問には、クラスに含まれるクラスに応じて1,2、または3の異なるクラスがあり、1,2、または3のcontent値を持つ可能性があります。 OPは、2クラスの組み合わせと3クラスの組み合わせごとに異なるセレクタを書きたいとは思わない。これはどのようにして解決しますか? – Meligy

+0

"マークアップの中には複数のクラスがあるかもしれませんが、テキストの後ろに複数のアイコンが必要です。問題は、複数のコンテンツ値を同じクラスに追加できるかどうかわかりません。 "クラスがたとえば.status-privateの場合、ロゴが表示されますが、マークアップに2つのクラスがある場合はどうなりますか?たとえば.status-private .format-standard?2つのアイコンを表示するにはどうすればよいですか? –

+0

彼は言う、クラスに応じてより多くのコンテンツを追加します。彼はclass .status-private.format-standardに2つのアイコンを追加したいかもしれません。ですから、私の例では2つの値を持つ.icon.icon2があります。たぶん私は別の質問を読んでいるかもしれませんが、私がこの1つを読んだとき、彼は "内容"に複数の価値を加える必要があります。 –

関連する問題