+ 1
Difference between <div>and <div class
I haven't understood how to differentiate between two elements. Please help
3 ответов
+ 2
A <div> element basically helps you group elements so that you can access all of them together from elsewhere like a JavaScript or CSS file.
But you can't identify which particular <div> you want to refer to unless you use a class or an id attribute.
For example:
HTML:
<div class='redText'>
<p>Sample</p>
<p>Text</p>
</div>
CSS:
.redText {
color: red;
}
Here, we have nested the two <p> elements in the <div> element and given it a class name. This class name is used in the CSS to address all elements within it.
Hope this heled :)
+ 1
<div> is an element
class is an attribute.
The difference is that you did not assign the class attribute to the first.
You would assign a class attribute to a div in order to style it or use
Javascript to grab it.
+ 1
Thanks so much