+ 1
When to use Div id and div class?
What are their difference?? can anyone explain much further.
2 Answers
+ 1
If you want to apply a certain (same) style to many different elements, use 'class'.
Otherwise, when you have a unique style that you want to give to just ONE element, use 'id'.
<head>
<style>
#wrapper {
width: 80%;
margin: 0 auto;
}
.green {
color: green;
}
</style>
</head>
<body>
<div id="wrapper">
<h1>Some Heading</h1>
<p>Lorem ipsum <span class="green">dolor</span> sit amet, consectetur adipiscing elit, sed do eiusmod <span class="green">tempor</span> incididunt ut labore et dolore magna aliqua.</p>
</div>
</body>
0
Class if for many, ID for one. Think that there are many kids in a 'class', but you can IDentify a single kid by their name.