Live data from Hacker News

Using Bootstrap the Semantic Way

ostraining.com

51–60 of 71 posts

Re: Using Bootstrap the Semantic Way

#51
post #24

Earlier quoted context omitted.

Nicer looking div soup is still div soup. != semantic.

no, but or are semantic, and there's no reason you couldn't use those instead of by using the features of LESS or SASS.

In my experience, really trying to be semantic ends up requiring gargantuan leaps of creativity trying to come up with semantic meaning for elements that are there purely for presentational reasons (wrapper classes, clearfixes, etc.)

Re: Using Bootstrap the Semantic Way

#52

I've used Bootstrap and been forced to use it on existing projects already engulfed in it. It isn't pretty on a large project. I've sworn off using Bootstrap in any new project that isn't a prototype for a hack day. The only things I borrow from Boostrap these days are some of the JavaScript niceties like modal, tooltip, and scrollspy. And when I do that I'm very explicit in what code I pull in to use those. Build th…

> I've sworn off using Bootstrap in any new project that isn't a prototype for a hack day.

I believe initially Bootstrap was intended for just this use case—make it easier to do a quick mock-up in markup. Once your design is relatively stable, you would naturally spend some time custom-fitting markup and stylesheets (enhancing source code readability, accounting for those who can't see, basic SEO optimization, etc.). This whole ‘front-end framework’ thing seems to me like a wrong direction to take.

Re: Using Bootstrap the Semantic Way

#53

Earlier quoted context omitted.

no, but or are semantic, and there's no reason you couldn't use those instead of by using the features of LESS or SASS.

In my experience, really trying to be semantic ends up requiring gargantuan leaps of creativity trying to come up with semantic meaning for elements that are there purely for presentational reasons (wrapper classes, clearfixes, etc.)

It is certainly hard, and impossible in some cases. But not as many as you would think. Wrappers can be a problem (although not as much as they used to be). Clearfix is not a problem at all, as it does not require an element only a css mixin[1]

Still, it's very possible to be almost entirely semantic with a few minor exceptions using a css preprocessor.

[1] http://compass-style.org/reference/compass/utilities/general...

Re: Using Bootstrap the Semantic Way

#54
post #36

We need a better word for this than "semantic". We're just passing the complexity back and forth between the HTML and the CSS, and the only "semantics" or meaning that arise are to the author/editor. Users don't care, machines don't care, and I've never, ever seen a large-scale site design that doesn't involve some reworking of both the HTML and the CSS.

That's because you aren't blind.

In this case we're not talking about ARIA or native elements vs. styled ones, though, we're talking about CSS classes.

Re: Using Bootstrap the Semantic Way

#55
post #36

We need a better word for this than "semantic". We're just passing the complexity back and forth between the HTML and the CSS, and the only "semantics" or meaning that arise are to the author/editor. Users don't care, machines don't care, and I've never, ever seen a large-scale site design that doesn't involve some reworking of both the HTML and the CSS.

Fair point. "Abstract" might be better. It embodies the information-/implementation-hiding goal of this technique.

Abstractions still require names, and the names should be meaningful (not easy: "naming things is one of the hardest things to do in software development"), at least to the development team (hate to keep rattling off platitudes, but "you should write code for humans first, computers second"). Rather than "semantic", "descriptive" seems to fit the bill.

"Abstract and descriptive". Doesn't quite roll off the tongue, but I tried :)

Re: Using Bootstrap the Semantic Way

#56
post #10
post #5

Earlier quoted context omitted.

Sure, but what if you have more than another section that should be styled differently? Classes can help differentiate same-name elements with different contexts, so you don't need unwieldy structure-specific CSS selectors like main > section > main just main.semantic-class

You'll also get major specificity issues when using element selectors with other class/id type selectors. My rule of thumb is classes and only classes for styling, it really makes life a lot easier. (Even if you have a unique element on the page, don't use the ID in your selector to style it.)

Totally agreed. And more generally, specificity is by far the most difficult challenge in large-scale CSS. Without discipline and some well-defined conventions for selector construction, you will end up with the equivalent of spaghetti code and late-nights deciphering unexpected cascading from other people's styles.

Since large projects will inevitably have to rely on non-semantic HTML and class names anyway (e.g. to differentiate between sibling

tags), a simple rule of thumb would be to only use class names in selector construction. HTML elements can still be semantic for other purposes, but the CSS should not care about it.

The other half of the specificity problem is nesting. I advocate strongly against the descendant combinator ` ` in favor of the child combinator `>`. E.g. `.body > .content` is much more robust than `.body .content`. However, an alternate approach would be:

    
        
        
    
Either way, don't leave it up to individual developers. This has to be adopted by the team.

Re: Using Bootstrap the Semantic Way

#57
post #5
post #2

I think this would be more semantic (with or without the classes)

Sure, but what if you have more than another section that should be styled differently? Classes can help differentiate same-name elements with different contexts, so you don't need unwieldy structure-specific CSS selectors like main > section > main just main.semantic-class

Agree that structure-specific CSS is unwieldy. However, it's robustness is still a worthy benefit. If you use a white-space sensitive CSS preprocessor, it is not unwieldy, and actually quite maintainable and elegant, since it's structure reflects nicely-formatted HTML. E.g.

  main
    > section
      > main
        text-decoration blink
Thus, things that are easy to change in HTML structure (cutting, pasting, and changing indentation) are similarly easy to change in CSS.

Re: Using Bootstrap the Semantic Way

#60

I've used Bootstrap and been forced to use it on existing projects already engulfed in it. It isn't pretty on a large project. I've sworn off using Bootstrap in any new project that isn't a prototype for a hack day. The only things I borrow from Boostrap these days are some of the JavaScript niceties like modal, tooltip, and scrollspy. And when I do that I'm very explicit in what code I pull in to use those. Build th…

Frontend is my bread and butter, and I used to be such an artiste that I shunned Bootstrap too.

But you know what's worse than Bootstrap? The hand-rolled framework that rises out of the muck on a large project. At least Bootstrap is always the same. It's a lingua franca, and a decent one at that.

Post reply on HN