0

I cant find answer of my question. So I'm wondering what is better if we talk for performance - to have one common class or to have two different class names that do same thing but improve the code readability.

.some_ul{
margin:0;
padding:0;
}

OR

    .people_ul, .animals_ul{
margin:0;
padding:0;
}

Is there something like in the object oriented programming, so when you make more classes or objects you use more resources or in CSS there is nothing like that and there is not a problem to make the second aproach which helps me to read my code easily.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
cyrat
  • 628
  • 1
  • 11
  • 20
  • 1
    Why don't you do a benchmark and let us know? – cimmanon May 11 '13 at 16:50
  • initially it is fine to keep one common class i think. Name it appropriately so looking at it gives away a clue about what the class is for. If you then have to visually differentiate the two it makes more sense to create two separate classes. – Jerry Saravia May 11 '13 at 17:40

3 Answers3

3

The subject of css selector performance was a hot issue last year. Since there everyone has calmed down. Looking at the facts –- the statistics -- It's really a non-issue. Go for readability. The difference is so negligible. If you are really concerned about front-end performance you should focus your efforts else where.

Check out this link that talks about the subject in more depth: Assign a class name to <img> tag instead of write it in css file?

Community
  • 1
  • 1
Timidfriendly
  • 3,224
  • 4
  • 27
  • 36
  • Thanks for the explanation! I also think that the readability is most important, but I wasn't able to find articles for the performance side of the whole picture, but your answer tells enough :) – cyrat May 11 '13 at 18:37
1

It depends on the definition of "the same thing".

If you have two elements that share common semantics, you should use one class for both. If you have two elements that have different semantics but just happen to share some visual properties, then use two separate classes.

Being consistent in this goes a long way in ensuring that maintaining and evolving your website will be straightforward instead of painful.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • I missed to tell that I get to this question because I was having two elements with different semantics, but with equal CSS properties and values. And thanks for the answer, I also think that giving proper names will boost the time to maintenance my website. – cyrat May 11 '13 at 18:40
-2

css is stand for reducing the file size of website. It is good practice to use common class

dsfg
  • 130
  • 9