Hacker News new | ask | show | jobs
by harlanlewis 4859 days ago
Agreed, the templates are not exhibiting how to avoid presentational classes. This may be a case where small-scope examples are poorly suited to real-world implementation, but I'll take a quick stab at moving to more descriptive (dare I say semantic) class names.

------

EXAMPLE: http://foundation.zurb.com/page-templates4/blog.html

Line 45: <div class="large-9 columns">

CSS: .row .large-9 { position: relative; width: 75%; } .row .columns { position: relative; padding-left: 0.9375em; padding-right: 0.9375em; float: left; }

------

With 'the magic of Scss', you could replace multiple presentational classes with a single class that refers to the element's content or purpose, and then use @extend for the above-defined grid classes.

So our new HTML would look like:

<div class="article-content">

And the Scss:

.article-content { @extend .large-9; @extend .columns; }

------

Edit: formatting, also: there are plenty of debates to be had about writing classes this way. The subject merits its own lengthy discussion and (I think) the answer changes depending on what you're trying to do, so I ain't touchin it.

1 comments

The quick answer is (feel free to disagree!), this is a great way to style a blog or microsite, but quickly gets out of hand. Using presentational classes bloats your markup but the size of your CSS assets will remain relatively constant, while using semantic class names requires writing new CSS for each new piece of content. The return you get on sacrificing some legibility in your markup increases with the size of your site. Large applications (or multiple applications that share the same CSS codebase) can also quickly run into the 4095 selector limit in (older versions of?) internet explorer. Using presentational classes has the added benefit of not requiring back end developers to write CSS (nobody likes writing CSS). It's mostly a matter of taste, but I can tell you from personal experience that CSS bloat in a large web application is easy to avoid and a nightmare to fix.
Paul - any tips for avoiding stylesheet bloat? A project I'm currently working on has a rapidly expanding style sheet, and I'd like to invest in some ways to cut down on the cruft.