I'm doing my best to remove as many Bootstrap' "classes" markup style from my HTML as I can, and use semantic tags where useful, but so far it only works in simple cases.
When the original classes features a lot of nested rules, it becomes a nightmare. For instance, in the following example from the docs (with added sizing rules):
<div class="row">
<div class="col-lg-6">
<div class="input-group input-group-lg">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
<input type="text" class="form-control">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="input-group input-group-lg">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
Rules like this works like a charm:
div:first-child {
.make-row();
& > div {
make-lg-column(6);
}
}
So these column classes can be removed from HTML. However, trying to do the same to buttons and form-controls doesn't work so well, because there's a lot of nested rules to style those elements. Everytime I remove a class from HTML, for instance with
input {
.form-control;
}
That input loses every styling based on several Bootstrap's rules like
.input-group .form-control:last-child,
.input-group-addon:last-child,
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .btn-group > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child),
.input-group-btn:first-child > .btn-group:not(:first-child) > .btn
The following can be done, but IMHO it's unproductive to keep track of every little rule to every little detail BS pulls off:
input {
.form-control;
input-group .form-control;
input-group .form-control:last-child;
}
LESS' :extend(* all)
sometimes can be used, but I have only basic experience using it and so far I haven't been able to figure how to make the following "logic" works, or even if it's feasible:
div:first-child {
.make-row();
& > div {
make-lg-column(6);
div {
&:extend(.input-group all);
&:extend(.input-group-lg all);
/* ... and so on */
}
}
But all those extend()
still can't replicate every nested rule.
Am I missing any fundamental logic using LESS' extend()
here? Is this even a worthy goal? So far I've limited what Bootstrap classes I'm removing, but I'm not sure if this is the proper way to go. These kind of problems arise a lot when dealing with common page elements in Bootstrap (nav headers, dropdowns, forms, ...).