tags:

views:

49

answers:

3

Should we write css to each element or only for those elements which want to give style?

like for example

  <div id="first">
     <span class="one">
      <a href="#">content text</a>
     </span>
    </div>
<div id="second">
     <span class="two">
      <a href="#">content text</a>
     </span>
    </div>
<div id="third">
     <span class="three">
      <a href="#">content text</a>
     </span>
    </div>

I just want to show link text with a color.Should i write CSS for all elements

If i write css only for a (....) and nothing defines for #one and .two. will i can get any problem.

Can non styled HTML elements create any type of problem in document flow or any cross browser problem?

+2  A: 

If you only need to apply style to the link, then you only need to write css for the link. If the class is not defined for the span or the div, then nothing will technically go wrong.

Aaron
+1  A: 

In order to style the link, you do not need to style any other elements. You could simply use:

a { color: red }

or whatever style you want. However, you'll be styling all link elements in the entire document. If you want to style only some links, you'll need to include more context in the CSS definition as well. For instance:

#one .two a { color: red }

Will style only the links inside something with the class two inside something with the id one.

Emily
A: 

No that shouldnt be a problem. In general you should keep your rules as concise as possible given the css required to produce the visual layout you need. if all you need to do is defin a link color then a simple:

a:link, a:visited {color: /* color */} a:hover, a:active {color: /* color */}

should suffice.

prodigitalson