Results 1 to 5 of 5

Thread: What's the difference between <div> and <span>

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240

    What's the difference between <div> and <span>

    I use <div> but never use <span>. Sometimes I've seen things where <span> was used where I'd have used a <div> and it looks really strange.

    Is it just a matter of preference?

    I'm a <div> kinda guy. How 'bout you? Join the <div> generation?

    cudabean

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    DIV is block level, SPAN is inline. That is the difference.

    For more on that, check with the W3C.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    WALDO
    Guest
    Originally posted by CiberTHuG
    DIV is block level, SPAN is inline. That is the difference.
    In simple terms, generally a div is a block-level element, meaning that a div will create a "block" around whatever it encapsulates. A span takes the shape of whatever it encapsulates. It doesn't create a "block".
    Code:
    <html>
      <body topmargin="0" leftmargin="0">
        <div style="background-color: gold;">This is my block<br/>I can put many things into it<p>note the color fills the whole "block"</p></div>
        <span style="background-color: pink;">This is my span<br/>I can put many things into it<p>note the color wraps around ("inline")</p></span>
      </body>
    </html>

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Note that CSS can determine whether a tag is block or inline (or neither), which really should make the div and span tags obsolete as we move towards XML.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    True that.

    But I'd like a generic tag that doesn't have a representative conitation (and isn't predefined in the XHTML DTD), so I can keep making invisible containers to help with layout.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width