Help understanding DIV

This is a discussion on "Help understanding DIV" within the Web Page Design section. This forum, and the thread "Help understanding DIV are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack (1) Thread Tools
  1 links from elsewhere to this Post. Click to view. #1  
Old Oct 6th, 2007, 16:17
MotorManiac's Avatar
Moderator
Join Date: Jul 2006
Location: USA
Posts: 120
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Help understanding DIV

i have a question. I need help understanding DIVs better. I thought i knew about them but now i know i dont. So i eget the div but what is the diffrence between these to code lines. <div id="footer"> or <div class="footer"> and how would each one be used and what would it look like in the style sheet
Last Blog Entry: Website critique (Apr 16th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 6th, 2007, 16:28
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,777
Thanks: 0
Thanked 16 Times in 16 Posts
Re: Help understanding DIV

Well in the stylesheet an id would be referanced with a '#' so for example:
Code: Select all
#footer {..}
and a class would be referanced the same although replacing the # with a '.' e.g.:
Code: Select all
.footer {..}
Hope that helps!
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 6th, 2007, 16:44
Highly Reputable Member
Join Date: Apr 2007
Location: Kent, England
Age: 38
Posts: 560
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

An ID is a unique identifier, so can only be used once on a page whereas a class can be used for different elements to which you want to apply the same styles.

Not sure if I've explained that well
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 6th, 2007, 16:46
MotorManiac's Avatar
Moderator
Join Date: Jul 2006
Location: USA
Posts: 120
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

so what would you use each one for?
Last Blog Entry: Website critique (Apr 16th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 6th, 2007, 16:50
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,777
Thanks: 0
Thanked 16 Times in 16 Posts
Re: Help understanding DIV

You can use an ID for whatever you want BUT you must only use it ONCE. You can use a class as much as you wish.

Please note you can use an ID as many times as you want as long as it isnt the same one e.g. id="footer" and id="footer".

Normally i use an ID for like a containing div, a header div and a navigation div (things that are only going to be used once on a page!).

Hopefully that clarifys this for you
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 6th, 2007, 17:20
MotorManiac's Avatar
Moderator
Join Date: Jul 2006
Location: USA
Posts: 120
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

i think so thanks
Last Blog Entry: Website critique (Apr 16th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 7th, 2007, 02:40
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

Usually ID are used for your main sections (for a lack of a better word right now) like: branding (header), navigation, content, site info (footer)

Other stuff like: thumbnails or advertising, etc.... I would use classes.

hth
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 7th, 2007, 02:53
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Help understanding DIV

IDs are also used in JavaScript to select an element with a particular ID. This is very useful!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 8th, 2007, 16:12
SuperMember

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

Generally I use id's for structural areas that you know will not be replicated on the page.

Last edited by JacobHaug; Oct 8th, 2007 at 16:25. Reason: No signature for at least 10 posts!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Oct 8th, 2007, 18:21
welshstew's Avatar
Site Admin

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,707
Blog Entries: 14
Thanks: 3
Thanked 33 Times in 31 Posts
Re: Help understanding DIV

The below is from smashing magazine

2.1. Technical Tips: IDs, Classes
  • 1 ID per page, many classes per page. “Check your IDs: Only one element in a document can have a certain value for the id attribute, while any number of elements can share the same class name. [..] Class and id names can only consist of the characters [A-Za-z0-9] and hyphen (-), and they cannot start with a hyphen or a digit (see CSS2 syntax and basic data types).” [Roger Johansson]
  • Element names in selectors are case sensitive. “Remember case sensitivity. When CSS is used with XHTML, element names in selectors are case sensitive. To avoid getting caught by this I recommend always using lowercase for element names in CSS selectors. Values of the class and id attributes are case sensitive in both HTML and XHTML, so avoid mixed case for class and id names.” [Roger Johansson]
  • CSS classes and IDs must be valid. “I.e. beginning with a letter, not a number or an underscore. IDs must be unique. Their names should be generic, describe functionality rather than appearance.” [CSS Best Practices]
  • You can assign multiple class names to a given element. “You can assign multiple class names to an element. This allows you to write several rules that define different properties, and only apply them as needed.” [Roger Johansson]
Hope it helps
__________________
WelshStew Site Admin
If you think I've helped, click the "Thanks"
tierney rides tboard - uk site | xtreme wales - extreme clothing
WebForumz - facebook | LinkedIn
Last Blog Entry: Phorm approved for UK rollout (Sep 17th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 8th, 2007, 20:00
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Help understanding DIV

To keep it simple:

use ID's for layout and Classes for elements that may need more than a single instance on any page.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Oct 12th, 2007, 00:20
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Help understanding DIV

I didn't know you could use more than one class on an element, thanks Welshstew
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Oct 12th, 2007, 02:38
Junior Member
Join Date: Sep 2007
Location: Huntington Beach
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Help understanding DIV

Something you may also find handy is you can add multiple classes to tags, so lets say you want a highlight (a different color) and want to increase the font size on the first sentence of a paragraph.

This can be done by having a separate class for the font size up, and the highlight in case you want to reuse the elements for other things also, but don't want them combined together, if that makes sense, hope this helps some people realise you can add as many classes as you like to a tag.

Example:
Code: Select all
.supersize {font-size:120%;}
.underline {text-decoration: underline;}
.highlight {color:#7FC240;}

<p class="supersize underline highlight">Now this sentence would be increased in font size, have a underline and be highlighted a green color.</p>
I just kind of wanted to let you know this method because it will save you time and come in handy, especially for images, you can make a "photo" class which pads your images and throw another class in there to either align it left or right, but you can make them all at once and always have them in your css, then you just have in the class="photo left" for example.

So in short, multiple classes will come in handy sooner or later.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://webforumz.com/web-page-design/60699-help-understanding-div.htm
Posted By For Type Date
70 Expert Ideas For Better CSS Coding | CSS | Smashing Magazine This thread Refback May 8th, 2008 03:12

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with understanding DOCTYPES in Dreamweaver! bellabella Web Page Design 1 May 16th, 2008 22:42
A little understanding would be useful (Flash, .flv and Websites) Phil Flash & Multimedia Forum 9 Sep 4th, 2007 15:41


All times are GMT. The time now is 06:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42