SPAN and DIV attributes in CSS

Discussion in 'CSS' started by sshahnawaz, Nov 12, 2009.

  1. #1
    I need to know more about CSS, because I have learned a little bit CSS, not much to be proud of that. So my question is:
    What attributes can you change with CSS of a DIV and a SPAN tag of your HTML. What's the difference between them? :)
     
    sshahnawaz, Nov 12, 2009 IP
  2. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A div is a box that is displayed as a block. This means it will put it on it's own line. If you were to do the following code:

    
    This is <div id="test">a test</div> of block print.
    
    Code (markup):
    Your result would be:

    This is
    a test
    of block print

    Same result using span:

    
    This is <span id="test">a test</span> of block print.
    
    Code (markup):
    This is a test of block print.

    Does this help?
     
    LeetPCUser, Nov 12, 2009 IP
  3. sshahnawaz

    sshahnawaz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    This is helpful, but is more likely to be HTML, not CSS, what are the attributes for both these tags, how to customize them according to your needs using CSS?
     
    sshahnawaz, Nov 12, 2009 IP
  4. Rob B

    Rob B Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I use spans to directly effect text say for example not having it underlined when its a link which is called "text decoration"

    where as a div is used to create a box that you can put contents in.

    Here is an example of the CSS of a SPAN to alter a text link

    This will make the link appear blue and not underlined when you have visited that page allready and when you hover the mouse over the link, whereas without this it will appear blue and underlined and once that link has been visited it usuall goes purple:

    #state1 { color:##666666; }

    #state1 a:link { color:##666666; text-decoration:none; }

    #state1 a:visited { color:##666666; text-decoration:none; }

    #state1 a:hover { color:##666666; text-decoration:none; }

    then in the HTML you enter this to

    <span is="state1">enter the link name here</span>




    and heres the CSS for a div that will make and invisible box 900 pixels wide and 250 pixels high sit in the centre of the page that you can enter text into:

    #linkholder { margin-left:auto; margin-right:auto; width:900px; height:250px; }


    then in the HTML you put the div on the page you would enter
    <div id="linkholder">enter the text here that will go into the box</div>


    i hope this helps
     
    Rob B, Nov 13, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Generally you use DIV's for containers, and SPAN's just for altering small snippets of something e.g a line of text.

    They are like your all-purpose block and inline element and should only be used when there isn't an appropriate HTML element (not the deprecated ones) that should be used in it's place.

    You can alter them with CSS like normal, you just give them a class or an ID and refer to them in your stylesheet.
     
    wd_2k6, Nov 13, 2009 IP
  6. sshahnawaz

    sshahnawaz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    I have found very useful information by you guys... awesome... :)
     
    sshahnawaz, Nov 14, 2009 IP
  7. Rob B

    Rob B Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    sorry in my post it was meant to read

    <span id="state1">enter the link name here</span>
    not
    <span is="state1">enter the link name here</span>
     
    Rob B, Nov 14, 2009 IP