Difference Between <DIV> Tags?

St4nley

Member
Apr 13, 2013
469
76
Hey so for a while now thanks to devbest i have been inspired to start coding. throughout my learning i have viewed many sources of code and i have come up with this question that i can not seem to understand.
I understand that div's are all linked to style sheets, but what i don't understand is the difference bettwen <div id> and <div class> and if there are any other ones may you please explain. Thank You!
 

Sysode

Front-End Developer
Dec 11, 2012
1,673
848
Sorry if I don't explain this in depth, it's early and I'm on my phone.

Anyway, div id looks like this in a stylesheet - #element
Where as, a div class would look like this - .element

Notice how ids use hashtags and classes use .
 

Sean

‫‫‫‫‫‫  ‫  Don't Worry, Be Happy
Dec 12, 2011
1,121
405
You use div's to create new elements and you use classes to add extra styling to the elements, or other HTML tags

Example: <div id="box"> starts a new element box that will have a box style to it, then you can use a class to change it's color

<div id="box" class="red">
<div id="box" class="blue">

etc.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,398
962
You use div's to create new elements and you use classes to add extra styling to the elements, or other HTML tags

Example: <div id="box"> starts a new element box that will have a box style to it, then you can use a class to change it's color

<div id="box" class="red">
<div id="box" class="blue">

etc.

To expand on this:
id's are unique, classes are not. For example, you should only use id of "box" once per page. id's also take precedence over classes because of specificity ( ).

Here's how somehow explained it to me a long time ago (think of it as school)
<div id="JohnSmith" class="Math">
<div id="JaneDie" class="Math>

Each student has their own ID, but they can share classes with each other. No student would have the same ID.

Easiest way is to read the documentation:
 

St4nley

Member
Apr 13, 2013
469
76
Thank's to everyone i understand how it works now!, but in what instance this may be used is i will spend some time thinking about it, anyways i greatly appreciate all of your help, this has been on my mind for some time now!



Thank You All, this means a lot!:)

Edit: after reading this i looked at my code that im making to increase my skills and i thought of something

<div id="Container">
<div id="Logo">
<div id="Input">
<p> Welcome To Index Please Log In Or Register Here! <a href="register.html">Registration</a>
<form>
Username: <input type="text" name="Username"><br><br>
&nbsp;Password: <input type="text" name="Password">
</form>
</p>
</div>
</div>
</div>
since logo, and the input go into the Container would container be considered a class? Thank You!
 

Users who are viewing this thread

Top