2017-10-12 17 views
-1

これは私のCSSファイルの一部です:HTMLの変更CSSのコンテンツ

.pricing .pricing-value .price:before { 
    position: absolute; 
    content: 'some text'; 
    top: 10px; 
    left: -35px; } 

私は私のhtmlファイルにスタイルを使用して別の何かに「テキスト」を変更したいと思います。それは可能ですか?つまり、

<span class="price" style='something_here'> 
+0

の内容を変更するためにcontent: attr(some-attribute)を使用することができます。 –

答えて

1

あなたは動的はい、HTML挿入スタイルが優先されます:pseudo要素

span:before { 
 
    content: attr(data-text); 
 
}
<span data-text="Append"> TEXT</span><br/> 
 
<span data-text="Another"> TEXT</span>

0

いいえ、それはありません。 ::beforepseudo-elementであり、style属性を使用して要素自体にスタイルを直接適用することはできません。しかし、擬似要素は、DOMの作成時には存在しません。DOMが構築されるときに追加されます。

ただし、別のクラスを追加してそこにテキストを変更することはできます。例。

.pricing .pricing-value .price.other-text::before { 
    content: 'other text'; 
} 

<span class="price other-text"> 
関連する問題