Div references in CSS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wreed
    New Member
    • Jan 2007
    • 7

    Div references in CSS

    What is the difference between "#divname" and "div#divnam e"? When do you use which? I think I've seen "div.divnam e" too.

    Thank you.
  • temat
    New Member
    • Apr 2007
    • 5

    #2
    # <- when using reference by id
    . <- by class name

    ex:
    [HTML]div.#site {..} for <div id="site">...</div>
    div.box {...} for <div class="box">..</div>[/HTML]

    or box in site :
    [HTML]div.#site.box {..} for
    <div id="site"><div class="box">..</div></div>[/HTML]

    Comment

    • temat
      New Member
      • Apr 2007
      • 5

      #3
      # <- when using reference by id
      . <- by class name
      <- reference to tag name [div,tr,td,....]
      ex:
      [HTML]
      <style>
      // all div tags will have font size 80%;
      div { font-size:80%; }
      //object with id = site will have orange fonts
      #site { color:orange;}
      //object with class name=box will have blue backgrounds
      .box { background-color:blue; }
      //only .box in #site will have blue background
      #site.box { background-color:blue; }
      //only box in div tag will have blue background
      div.box { background-color:blue; }
      //only box in div tag and id=site will have blue background
      div.#site.box { background-color:blue; }
      </style>
      <div id="site">
      <div class="box">[something]</div>
      </div>
      <div class="box">[something else]</div>
      <span class="box">[text]</span>
      [/HTML]

      Comment

      • AricC
        Recognized Expert Top Contributor
        • Oct 2006
        • 1885

        #4
        You can use <div class="clsClass Name">...</div> as much as you want, but from my understanding id only once.

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          You can use 'div#idname' or '#name' whichever you prefer. Some people prefer the 'div' or other element prefix so they are reminded what type of element the id refers to. Same when using class names.

          Comment

          Working...