Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Bootstrap whilst maintaining semantic HTML markup?

Tags:

Bootstrap provides classes such as text-left (Alignment classes), text-lowercase (Transformation classes) etc, which is the same as defining inline-styles (not technically, but logically).

In an alternative methodology such as bem, it imposes that classes should reflect 'physical' blocks and elements, and their modifier (or the state of the element, such as active, current), and any styles should be applied purely in the CSS.

The Bootstrap approach seems like a poor separation of concern between structure and presentation, and goes against this W3C Tip for Webmasters.

This issue is echoed by many:

  1. Niko Sams - Why I don't like Twitter Bootstrap
  2. Paradax - Bootstrap The good, the bad and the ugly
  3. bvision - Please stop embedding Bootstrap classes in your HTML!

How does one use Bootstrap while still keeping the HTML markup semantic?

like image 993
d4nyll Avatar asked Mar 03 '15 05:03

d4nyll


People also ask

Is bootstrap semantic?

Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. On the other hand, Semantic UI is detailed as "A UI Component library implemented using a set of specifications designed around natural language".

Should I use HTML5 semantic markup?

One of the most important features of HTML5 is its semantics. Semantic HTML refers to syntax that makes the HTML more comprehensible by better defining the different sections and layout of web pages. It makes web pages more informative and adaptable, allowing browsers and search engines to better interpret content.

Can you use div in semantic HTML?

Certainly: you can still use <div> ! Despite HTML 5 bringing us new elements like <article> , <section> , and <aside> , the <div> element still has its place.

Is semantic HTML good for SEO?

So some amount of semantic HTML definitely makes sense for SEO. It definitely makes sense for usability and for compatibility across different browser types, all of that as well.


1 Answers

Bootstrap provides mixins which you can use. So instead of adding classes like col-xs-12 in the HTML, you'd use @include make-xs-column(12) inside the selector block for the element. To add a row, there's the @mixin make-row.

Referring to an answer by Alexey Morashko, instead of this unsemantic markup:

<div class="items-list row">     <div class="item col-xs-12 col-sm-6 col-md-4">         <div class="item-name">Product first</div>         <div class="item-description">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>     </div>     <div class="item col-xs-12 col-sm-6 col-md-4">         <div class="item-name">Product second</div>         <div class="item-description">Ratione, ullam, reprehenderit aliquid saepe ab harum.</div>     </div>     <div class="item col-xs-12 col-sm-6 col-md-4">         <div class="item-name">Product third</div>         <div class="item-description"> totam repudiandae velit eum accusantium veritatis.</div>     </div> </div> 

You can instead use:

HTML

<div class="items-list">     <div class="item">         <div class="item-name">Product first</div>         <div class="item-description">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>     </div>     <div class="item">         <div class="item-name">Product second</div>         <div class="item-description">Ratione, ullam, reprehenderit aliquid saepe ab harum.</div>     </div>     <div class="item">         <div class="item-name">Product third</div>         <div class="item-description"> totam repudiandae velit eum accusantium veritatis.</div>     </div> </div> 

CSS

.items-list {     @include make-row();          .item          @include make-xs-column(12);         @include make-sm-column(6);         @include make-md-column(4);     } } 

You can find more examples of Bootstrap mixins in the Sitepoint article - 5 Useful Sass Mixins in Bootstrap.

like image 138
d4nyll Avatar answered Nov 18 '22 15:11

d4nyll