Fork me on GitHub

Just started using css and I am running into a validator err  Bottom

  • I have this CSS button i'd like to use to replace images when images are disabled. The erro I get is that the id is already defined once I use it the second time. The error makes sense however I have no idea how to apply the style I want to the div's without violating this rule. Can anyone point me in the right direction.

    Code

    <div id="sb-menu">
         <ul>
              <li>
    <a href="#" onclick="document.getElementById('MODIFYHIST<!--[$history.history_id]-->').submit();return false;" title="<!--[pnml name="_MODIFY]-->"><!--[pnml name="_MODIFY]--></a>
              </li>
         </ul>
    </div>

    Code

    #sb-menu ul
    {
    list-style: none;
    padding: 0;
    margin: 0;
    }

    #sb-menu li
    {
    float: left;
    margin: 0 0.15em;
    padding: 0;
    text-align: center
    }

    #sb-menu li a
    {
    background: url(../pnimages/background.gif) #fff bottom left repeat-x;
    height: 2em;
    line-height: 2em;
    float: left;
    width: 80px; /*9em*/
    display: block;
    border: 2px solid #dcdce9; /*0.1em solid #dcdce9;*/
    color: #0d2474;
    text-decoration: none;
    text-align: center;
    }

    /* Commented backslash hack hides rule from IE5-Mac \*/
    #sb-menu li a
    {
    float: none
    }
    /* End IE5-Mac hack */

    #sb-menu
    {
    text-align:left; /*overrides the centering from above*/
    width:80px; /*5 menu items at 135px width (8px padding + 2px border + 125px width)*/
    margin:0 auto; /*centers in compliant browsers*/
    }
  • Rather than use an id why not use a class? So your markup becomes
    ...
    and your CSS becomes .sb-menu rather than #sb-menu....

    -Mark

    --
    Visit My homepage and Zikula themes.
  • If I understand right, IDs can only be used once in a document, whereas classes can be used and re-used.
  • jediping

    If I understand right, IDs can only be used once in a document, whereas classes can be used and re-used.


    Spot on.... ID's are unique within a document and are ideal when combined with javascript to access the DOM. Think about accessing an element within the document via getElementByID if the ID wasn't unique.....

    If just applying styles then id's/classes are fairly inter-changeable aside from the uniqueness requirement of an id.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Ah ok so I need to look at classes. Man CSS is so cool the stuff I have learned in the last two days there is very little need for graphics in this application if I were to put some effort into the CSS.

This list is based on users active over the last 60 minutes.