TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using Bootstrap the Semantic Way

83 pointsby harishchouhanabout 11 years ago

16 comments

ZeroGravitasabout 11 years ago
Still the most comprehensive rebuttal to this common (and I feel, badly mistaken) complaint:<p><i>&quot;About HTML semantics and front-end architecture&quot;</i> (from March 2012):<p><a href="http://nicolasgallagher.com/about-html-semantics-front-end-architecture/" rel="nofollow">http:&#x2F;&#x2F;nicolasgallagher.com&#x2F;about-html-semantics-front-end-a...</a><p>It&#x27;s all well worth reading, but the conclusion is particularly to the point:<p><i>&quot;The experience of many skilled developers, over many years, has led to a shift in how large-scale website and applications are developed. Despite this, for individuals weaned on an ideology where “semantic HTML” means using content-derived class names (and even then, only as a last resort), it usually requires you to work on a large application before you can become acutely aware of the impractical nature of that approach. You have to be prepared to disgard old ideas, look at alternatives, and even revisit ways that you may have previously dismissed.<p>...<p>When you choose to author HTML and CSS in a way that seeks to reduce the amount of time you spend writing and editing CSS, it involves accepting that you must instead spend more time changing HTML classes on elements if you want to change their styles. This turns out to be fairly practical, both for front-end and back-end developers – anyone can rearrange pre-built “lego blocks”; it turns out that no one can perform CSS-alchemy.&quot;</i>
评论 #7277129 未加载
droobabout 11 years ago
We need a better word for this than &quot;semantic&quot;. We&#x27;re just passing the complexity back and forth between the HTML and the CSS, and the only &quot;semantics&quot; or meaning that arise are to the author&#x2F;editor. Users don&#x27;t care, machines don&#x27;t care, and I&#x27;ve never, ever seen a large-scale site design that doesn&#x27;t involve some reworking of both the HTML and the CSS.
评论 #7277295 未加载
评论 #7278045 未加载
评论 #7279584 未加载
评论 #7277607 未加载
camus2about 11 years ago
The point of using bootstrap is a reusable set of classes. I really dont care wether class names are semantic or not,it doesnt change anything,except for pedantic people looking at your source code.<p>SEO doesnt care , users dont care, accessibility doesnt care either. Using new HTML5 tags is good enough and was designed for that specific purpose. If i want semantics I use nav,aside,section instead of div,and so on.<p>Not going to waste my time and wrap bootstrap mixins in more LESS mixins and loose theme portability and modularity,because semantics...<p>It&#x27;s like inobstrusive javascript, trends that make little sense today in the webapp era.
评论 #7276443 未加载
评论 #7276315 未加载
评论 #7276452 未加载
评论 #7278917 未加载
评论 #7277146 未加载
awhittyabout 11 years ago
I appreciate the comparison to the ancient Web, but this article doesn&#x27;t say much more that I can&#x27;t find in Bootstrap&#x27;s documentation.<p>Anyone who has used Bootstrap&#x27;s mixins with semantics in mind knows there are some bigger issues to address than the layout. Some questions off the top of my head:<p>* How do you build semantic forms with Bootstrap without going to markup fluff hell?<p>* How can you avoid the unsemantic class names for components that are tied too closely with child components (I&#x27;m looking at you, .panel)?<p>* What is the semantic purpose of a row element? It seems purely presentational to me.<p>* How do I add icons without peppering span.glyphicon.glyphicon-X&#x27;s all over my markup?<p>* How should I organize&#x2F;maintain all of my LESS files as my stylesheets scale? I&#x27;m not looking for any one &quot;right&quot; way, but suggestions are always nice.<p>* Are there any optimizations I can consider when I&#x27;m only using a bit of Bootstrap&#x27;s functionality?<p>* How can I extend Bootstrap&#x27;s mixins for my own needs?
评论 #7276760 未加载
评论 #7278389 未加载
blikerabout 11 years ago
I think this would be more semantic (with or without the classes)<p><pre><code> &lt;section&gt; &lt;main&gt; &lt;&#x2F;main&gt; &lt;aside&gt; &lt;&#x2F;aside&gt; &lt;section&gt;</code></pre>
评论 #7278404 未加载
评论 #7276291 未加载
Toucheabout 11 years ago
We do div soup because CSS is still not good enough to do all of your styling there. When you can trivially make an element 6 columns in CSS we&#x27;ll all stop treating Bootstrap like this. Maybe Flexbox version 6 (or whatever we are on now) finally fixes this but who can keep up and find out.
评论 #7276822 未加载
kh_hkabout 11 years ago
Be very wary, though, if you are using mixins to define these columns in a case-by-case basis, as this could lead to huge generated CSS (the properties of the column will be defined in each class the mixin has been used).
评论 #7276838 未加载
daigoba66about 11 years ago
I build web &quot;apps&quot;. I don&#x27;t treat HTML and CSS like a semantic document; it&#x27;s just a declarative layout engine. Yes, I often use HTML elements and structure to define layout instead of CSS classes. My CSS class names often have little &quot;semantic&quot; meaning outside their single purpose, that is to define layout and style. Am I doing something wrong? We don&#x27;t have these discussions when building native GUIs.<p>Perhaps if I were building a CMS or some other document-oriented site I would approach things differently.
iambatemanabout 11 years ago
Here is a LESS mixin that will go a long way in making semantic Bootstrap easy to actually do:<p>.make-column(@large, @medium, @small, @tiny: 12) { .make-xs-column(@tiny); .make-sm-column(@small); .make-md-column(@medium); .make-lg-column(@large); }<p>Then use it with: section#main-content { .make-column(8,8,9,12); }
rubiquityabout 11 years ago
I&#x27;ve used Bootstrap and been forced to use it on existing projects already engulfed in it. It isn&#x27;t pretty on a large project. I&#x27;ve sworn off using Bootstrap in any new project that isn&#x27;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&#x27;m very explicit in what code I pull in to use those.<p>Build the CSS for your next project using mixin libraries like Bourbon&#x2F;Neat or Compass&#x2F;Susy. You&#x27;ll be glad you did.
评论 #7277801 未加载
评论 #7278347 未加载
hugofirthabout 11 years ago
This is one of the main reasons I like AngularJS directives. If used properly (huge caveat) they allow your template markup to take on far more semantic meaning.<p>I also agree with the idea that we should use Mixins to allow for more semantic meaning in our plain HTML. As an added bonus, this can make things a lot more maintainable down the road.
ZeroGravitasabout 11 years ago
I just noticed that this article is laid out with a table, with a single td. Glasshouses, stones etc.
jbraithwaiteabout 11 years ago
One of the strengths of BS is mobile-first responsive design. You can chain classes like this: class-name=&quot;col-xs-6 col-md-3&quot;<p>If you try this with the method outlined by the OP, you&#x27;ll end up with a giant css file.
grakicabout 11 years ago
What are current options to optimize LESS files and remove unused mixins? And for the generated CSS, what are current options to merge shared rules and remove unused classes reported against a sample HTML?
评论 #7276411 未加载
评论 #7287824 未加载
hiphopyoabout 11 years ago
Related: <a href="https://news.ycombinator.com/item?id=7247054" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7247054</a>
cheriotabout 11 years ago
This increases the number of css styles dramatically, which affects page speed on large sites.
评论 #7279818 未加载