2017-10-12 34 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

是,HTML插入樣式將優先內容。 –

回答

1

您可以使用content: attr(some-attribute)動態改變: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">