Reputation: 235
I am writing a long html file consisting of several blocks. I want to change the background color of some blocks. How should I complete this? I am trying to add code like this:
<style type="text/css">
body { background: navy; }
</style>
However, it will change all the background. So how should I change the background color of several parts? Thanks!
Upvotes: 0
Views: 1273
Reputation: 432
By default your blocks (divs or sections) will have no color attribute if you put color on the body you basically "see through" them to the color behind. As national holiday suggested you can add a class to the divs and target them.
.sample {
background-color: magenta;
}
body {
background-color: cyan;
}
<body>
<div class="sample">
I've added color to the background of this div through class targeting in css.
</div>
<div class="somethingElse">
This would have the body color because I'm not applying a style to it.
</div>
</body>
Upvotes: 2
Reputation:
Give the blocks a name, like
<div class="name">content</div>
after that, go to your css file and write
.name {background-color:#eee}
Upvotes: 3
Reputation:
You have to create a special class in the css file, declare desirable properties and then pass them on the element in HTML document. It's a very foundations and I strongly recommend you attend at least basic course - http://www.w3schools.com/css/- before proceeding. Good luck.
Upvotes: 0