- This topic is empty.
-
AuthorPosts
-
May 23, 2012 at 4:55 am #38185doconlineMember
I was just wondering what people though was the best practice regarding css classes. Is it better to have lots of classes (padding, background colours, margins, borders etc) with a small number of definitions, and then style HTML elements with lots of different classes, or have a smaller number of classes but give more definition to these classes?
On a project I am currently working on, the team I am working with are choosing the former, and there are lots of styles, for example, the LI elements have a background colour, this is styled by assigning each LI a class, instead of assigning the colour in the CSS. It seems to me like this will bloat the HTML a lot more than a few extra lines of CSS.
Any thoughts?
May 23, 2012 at 8:15 am #103322Taufik NurrohmanParticipant@karlpcrowley My favorite classes:
.alignleft {}
.alignright {}
.aligncenter {}
.button {}
.button.small {}
.text-left {}
.text-right {}
.text-center {}
.tip {}
.alert {}
.download {}
.update {}
.demo {}
.try {}
.note {}
.netral {} /* for: border:none;outline:none;background:transparent;box-shadow:none; */
.full {}May 23, 2012 at 9:55 am #103326JohnnybMemberThis is one of the reasons preprocessors are gaining popularity. You can use a minimal number of classes but not end up with a huge CSS file. But if you’re not able to use one then I’d just be sensible about the number of classes used, like the guys above said; helper classes are very useful but don’t take it to the extreme and start adding classes for every attribute. It’s better for the 1 CSS file to be larger rather than for many HTML files to be bloated.
May 23, 2012 at 10:00 am #103327doconlineMemberThanks for the comments guys.
@andy_unleash – I agree with you. It is a very inefficient way of doing things. The LI was just an example. This is happening all over the site, but that is the way the in house developers want to proceed, so who I am to argue as a contractor, I am just here to help with more hands on deck, and adjust to their coding standards. Seems the wrong way to do it though. Ho hum, will be moving on to the next project soon, so not to worry :)
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.