Reputation: 166
I'm confused about the class and id selection with css if i have multiple divs with same ID changeing ID to Class does not have any effect on the result
style
<style>
#main-div
{
width:300px;
height:300px;
background-color:red;
margin:10px;
}
</style>
<div id="main-div"></div>
<div id="main-div"></div>
<div id="main-div"></div>
<div id="main-div"></div>
Upvotes: 1
Views: 2115
Reputation: 5224
First of all, using multiple times the same id is invalid. Never do it.
Then, in css selectors, you need to use
Here is an example.
<!-- in HTML -->
<div id="identifier1"></div>
<div class="class1"></div>
<div class="class1"></div>
/* In css */
#identifier1 { /* This targets the first div */ };
.class1 { /* This targets the second and third div */ };
Upvotes: 1