2017-08-16 149 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>

相关问题