tags:

views:

59

answers:

3

Hello.

I have a huge amount of elements in my website... And since I added the following css... Some elements inherit from these css styles... While they don't have anything to do with it: other scope, no direct definition to the css style etc... What am I doing wrong?

#InformationForDiv
{
    width: 205px;
    height: 180px;
    background: #FFFFFF;
    clear: both;
    float: left;
    margin: 0 35px 0 35px;
    text-align: center;
}

#InformationForDiv ul
{
    text-align: left;
    padding: 0px;
    display:block;
}

#InformationForDiv li
{
    border-bottom: solid 1px #D6D6D6;
    padding: 0px;
    list-style: none;
    line-height: 20px;
    display: block;
}

#InformationForDiv p
{
     display:inline;
     float:right;
     margin:0;
     text-align:right;
     font-size: 16px;
     color: #B02229;
}


#InformationForDiv li a:link, a:visited
{
    color: #544B42;
    text-decoration: none;
    font-size: 12px;
    width:100%;
    display:block;
}

#InformationForDiv li a:hover
{
   color: #544B42;
   border-bottom: 1px solid #544B42;
   font-size: 12px;
}

#InformationForDiv li a:visited
{
   color: #544B42;
   text-decoration: none;
   font-size: 12px;
}

#InformationForDiv img
{
    margin: 10px 0 5px 0;
}
+2  A: 

At least this one:

#InformationForDiv li a:link, a:visited

will select all a:visited elements and it doesn't look like your intention.

Michael Krelin - hacker
A: 

Perhaps because those elements have an ancestor in the HTML document in which they exist that has the ID "InformationForDiv".

Its generally not a good idea to include in an external css selectors the use of specific element IDs. External CSS ought to rely on class names to select appropriate elements.

AnthonyWJones
why? (the downvote is not mine;-))
Michael Krelin - hacker
There are many key reasons why a web developer would give an element an ID. There is only one key reason to place a class name on an element. An external css can expect to be shared by multiple pages. A developer of one those pages shouldn't have to worry about IDs already used by other pages that are then styled by the css using # in selectors. An should be ID is unique in a document by allowing selectors in shared css to use them then those ID gain a greater possibly unintended wider scope.
AnthonyWJones
That may mean two things - you suggest not to style based on id or embed styles with id-based selectors in the page. Which is yours? While what you're saying does apply to some sitewide stylesheets I see absolutely no reason to be dogmatic about it — to me it's just one of those universal rules that are all wrong (including the one I've just declared).
Michael Krelin - hacker
@Hacker: Many specification documents use two similar but different terms "SHOULD" and "MUST". I used the term "SHOULD". In my actual answer I use the terms "generally" and "ought". I can't see why you see that as "dogmatic". A website wide CSS is implied in the language of the OP question and that was what I was addressing.
AnthonyWJones
AnthonyWJones, Perhaps I perceived it as a stronger statement because it struck me a bit out place as an answer to original question. But indeed, upon closer inspection I have to admit your wording is not half as strong as I've thought it is.
Michael Krelin - hacker