2017-08-16 80 views
-2

您好我想添加在標題部分CSS在我的網頁是否可以將css添加到頁面的特定部分?

我在1頁

不同的部分,但我想在每個部分的字體和標題文本的顏色

,但不改變肯定該怎麼做

enter image description here

+0

你能不能每次添加要更改,然後寫自定義規則爲每個CSS類的部分一類? –

回答

0

可以使用樣式屬性 https://www.w3schools.com/tags/att_style.asp

<h1 style="color:blue;text-align:center">This is a header</h1> 
<p style="color:green">This is a paragraph.</p> 
+1

內聯css樣式不好。您應該閱讀[此問題]的答案(https://stackoverflow.com/q/2612483/5894241)。 – Nisarg

+0

如果您使用的是vanilla javascript和html,則在大型應用程序中管理它們將成爲一場噩夢。不過,使用React Native的情況並不是這樣,您可以使用React Native爲每個標籤注入樣式,也可以在組合中使用組件,而不是像material-ui那樣注入類衝突。 –

1

給每個部分一個類,然後將該樣式應用於該類的子項。例如:

.section-1 h2{ 
 
    color:#fff; 
 
} 
 
.section-1{ 
 
    background-color:orange; 
 
} 
 
.section-1 p{ 
 
    color:blue; 
 
} 
 
.section-2 h2{ 
 
    color:#fff; 
 
} 
 
.section-2{ 
 
    background-color:peachpuff; 
 
} 
 
.section-2 p{ 
 
    color:black; 
 
} 
 
.section-3 h2{ 
 
    color:#fff; 
 
} 
 
.section-3{ 
 
    background-color:pink; 
 
} 
 
.section-3 p{ 
 
    color:purple; 
 
}
<html> 
 
<head></head> 
 
<body> 
 
<div class="section-1"> 
 
    <h2>Section 1</h2> 
 
    <p>Filler paragraph text</p> 
 
</div> 
 
<div class="section-2"> 
 
    <h2>Section 2</h2> 
 
    <p>Filler paragraph text</p> 
 
</div> 
 

 
<div class="section-3"> 
 
    <h2>Section 3</h2> 
 
    <p>Filler paragraph text</p> 
 
</div> 
 

 
<div class="section-4"> 
 
    <h2>Section 4</h2> 
 
    <p>Filler paragraph text</p> 
 
</div> 
 

 
</body> 
 
</html>

相關問題