Jump to content


CSS Divs


7 replies to this topic

#1 Bouzy210

    Jedi In Training

  • Members
  • PipPip
  • 434 posts
  • Gender:Male

Posted 01 July 2007 - 09:13 PM

This is a question that i am sure some of you can answer quickly, but anway. I have been learning how to code useing Xhtml and CSS. I am confused about some CSS properties.

I know classes and ids are for styling certain elements like <p> and such, but what is the difference between that and <div> and <span> both allow you to name sections of your code, and for both you can set style like background image, text color and stuff like that.

Bassically what I am trying to do hear is code a layout. It's supposed to be a simple 2 collum one. So say I have an image of what I want to be the content backround. Do I use classes, ids, divs, or spans? What about the navigation sidebar thing? Spans Divs ahhhh its so confusing :censored: :bashhead: :rolleyes: :D

Edited by Bouzy210, 01 July 2007 - 09:14 PM.


#2 Archangel

    P2L Jedi

  • Members
  • PipPipPip
  • 988 posts
  • Gender:Male
  • Location:Indiana
  • Interests:Reading (mainly fantasy books), Gaming (Xbox 360, Wii &amp; PS3), Sports, Outdoor Recreation, Watching/Collecting Movies

Posted 01 July 2007 - 09:20 PM

The difference between Classes and IDs is that classes can be used multiple times on a page whereas an ID should only be used once.

Some Reading Material

#3 Bouzy210

    Jedi In Training

  • Members
  • PipPip
  • 434 posts
  • Gender:Male

Posted 01 July 2007 - 09:42 PM

Right i know that, but when can you tell whether to use classes and ids verses divs and spans. Don't they bassically do the same thing? What about like above like I said for a 2 collum layout, but mainly...

when can you tell whether to use classes and ids verses divs and spans. Don't they bassically do the same thing?

#4 _*Creative Insanity_*

  • Guests

Posted 01 July 2007 - 10:44 PM

Span I hardly use.. no need for them really.

An ID (#selector_name) for items that will only be used once on a document. For example wrappers, headers, panels and content. Use a class (.selector_name) if you want to use it multipul times. Like images, dynamic divs where they are needed many times in one document.

#5 Bouzy210

    Jedi In Training

  • Members
  • PipPip
  • 434 posts
  • Gender:Male

Posted 01 July 2007 - 11:06 PM

ok thanks I think I get it.

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 01 July 2007 - 11:41 PM

A div takes up the full width of it's parent element thus causing anything added after it (and outside of it) to automatically break to a new line. They are ment to hold basically anything.

Spans are just spans. Usually the are used to change something across a "span" of words. But i'm sure people have come up with other uses for them.

#7 Archangel

    P2L Jedi

  • Members
  • PipPipPip
  • 988 posts
  • Gender:Male
  • Location:Indiana
  • Interests:Reading (mainly fantasy books), Gaming (Xbox 360, Wii &amp; PS3), Sports, Outdoor Recreation, Watching/Collecting Movies

Posted 02 July 2007 - 06:38 AM

Classes and IDs are used inside divs, paragraphs, spans, etc. so you just need to determine when to use them based off of what rc69 said.

When it comes down to using a div vs. paragraph for formatting if you have a class or id linked with that div or paragraph it doesn't really matter which...more just personal preference I think.

I know that when I'm doing coding I'll generally use divs over paragraphs and then if I want to add some quick space around a section w/o giving it a class or id that's when I'll bust out a paragraph. If I'm working on layout and not content I will always use divs...I never use paragraphs to help form the layout of the webpage.

We help you understand anymore at all?

#8 Bouzy210

    Jedi In Training

  • Members
  • PipPip
  • 434 posts
  • Gender:Male

Posted 02 July 2007 - 02:26 PM

Your last post explained it perfectly thanks. everyone.

One more question and I promise I will be done for a week at least (I didn't want to start a new thread)

anyway...


I am making a layout and the content box is acting weird. The text is going outside the box even though I have the padding set. The margin is zero. Hear is what it looks like... http://i93.photobucket.com/albums/l7...Bouzy/ggmf.jpg

Hear is some of my code.


#content {

height: 518px;
width: 505px;
background-image: url(images/content.jpg);
background-repeat: no-repeat;
line height: .8em;
padding-left: 38px;
padding-right: 38px;
padding-top: 46px;
padding-bottom: 46px;
margin-top: 20px;
margin-bottom: 20px;


}


<div id="content">
<h2>Home</h2>
<p id="home">
Blallasd;ldsjf;lasjdf;laskjdf;lasjkdfla;jksdf;lask jdf;lajsdl;fjasdlfjkasdl;kfjas;ldjfk;lsadjflasdjfa
asdlkjfa;lsdkjf;laksdjf;lajsdlkfjafds

</p>

</div>

Edited by Bouzy210, 02 July 2007 - 04:11 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users