我正在尝试使用 Less 或 Sass 使我的 bootstrap 2.1 标记更具语义。考虑 Bootstrap 标准导航栏的以下标记:
<header id="main-nav" class="navbar navbar-static-top" role="banner">
<nav class="navbar-inner" role="navigation">
<div class="container">
<!-- Collapse nav button -->
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Nav -->
<nav id="navlinks" class="nav-collapse collapse pull-right">
<ul class="nav nav-pills">
<li class="active">@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
</nav>
</header>
显然,将 DIV 更改为更具语义的 HTML 5 标记很容易,但从标记中删除类链则更加困难。如果您要使用 mixin,例如:
header #main-nav {
.navbar;
.navbar-static-top;
}
以下定义不起作用,因为复合类不受影响:
.navbar .btn-navbar {
display: none; // hide button in full width (Why a compound class? Redundant?)
}
理想情况下,如果 less 或 sass 有这样的语法会很好:
header#main-nav $= .navbar; // copy .navbar definitions using #main-nav as the name
或者
header#main-nav @= .navbar; // rename .navbar definitions to #main-nav
这可以做到吗?如果没有,我怎样才能实现语义标记?