调整 Bootstrap 2.0 以实现语义标记

发布于 2025-01-01 01:26:54 字数 586 浏览 8 评论 0原文

Twitter“Bootstrap”UI 框架的第二版于今天发布。虽然我发现它非常方便,但我不喜欢它的非语义性。

我宁愿避免在 HTML 中设置像 .span6 .table-striped 这样的类。

由于 Bootstrap 是基于 less 构建的,所以我期望有一种好方法使用特定于项目的 less 表,它可以利用 mixin 将 bootstrap 定义的优点归因于良好的语义类名称。

我将 bootstrap.less 克隆到 myproject.less 中,并调整了 @import 行中的路径,然后在底部添加了以下内容:

#call-to-action {
    .span6;
}

但 lessc 对此感到窒息,并抱怨:

.span6 is undefined in

同样,尝试 .columns(6) 会产生相同的错误(“.columns 未定义”)。

其他混合,例如 .table、.table-bordered 等,似乎工作正常。

我缺少什么?使用引导程序同时将非语义类名排除在我的漂亮语义标记之外的最佳实践是什么?

Version 2 of Twitters "Bootstrap" UI framework was released today. While I find it very handy, I dislike how non-semantic it is.

I'd rather avoid setting classes like .span6 .table-striped in my HTML.

Since Bootstrap is built on less, I'm expecting that there's a good way use a project-specific less sheet that can leverage mixins to to ascribe bootstrap-defined goodness to nice semantic class names.

I cloned bootstrap.less into myproject.less, and adjusted the paths in the @import lines, then added the following at the bottom:

#call-to-action {
    .span6;
}

But lessc chokes on it, and complains that:

.span6 is undefined in

Similarly, trying .columns(6) produces the same error (".columns is undefined").

Other mix-ins, such as .table, .table-bordered, etc, seem to work fine.

What am I missing? What are the best practices for using bootstrap while keeping non-semantic class names out of my nice, semantic markup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

朦胧时间 2025-01-08 01:26:54

对于新的 Bootstrap 2.1(也许适用于 2.0):

.content{ .makeRow();
   .main-content{ .makeColumn(5,2);} // (size,offset)
   .sidebar{ .makeColumn(3); }
}

终于可以了!

For the new Bootstrap 2.1 (maybe works on 2.0):

.content{ .makeRow();
   .main-content{ .makeColumn(5,2);} // (size,offset)
   .sidebar{ .makeColumn(3); }
}

Finally works!

情深如许 2025-01-08 01:26:54

好吧,少一点,这就是我的想法。这是我能做的最好的事情,我不知道如何在语义上处理 .row,但是哦,好吧。

基本上我创建了一个 custom-mixins.less 并创建了一个名为 .col 的 mixin,变量是 @col。因此,当您编写选择器并执行类似 .col(3); 的操作时.col(4); .col(5);或类似的东西。它应该创建适当的宽度。我不知道这对于嵌套列如何起作用。

//custom-mixins.less
.col (@col) {
  #gridSystem > .gridColumn(@gridGutterWidth);
  #gridSystem > .columns(@gridGutterWidth, @gridColumnWidth, @gridRowWidth, @col);
}

//styles.less
.greetings {
  .col(3);
}

lessc 将在 styles.css 中生成以下内容

//styles.css
.greetings {
  float: left;
  margin-left: 20px;
  width: 220px;
}

ok in less, this is how I figured it out. Its the best I could do, and I couldn't figure out how to deal with .row semantically, but oh well.

Basically I created a custom-mixins.less and created a mixin called .col and the variable is @col. So when you write your selector and do something like .col(3); .col(4); .col(5); or something like that. It should create the proper width. I don't know how this would work for nested columns.

//custom-mixins.less
.col (@col) {
  #gridSystem > .gridColumn(@gridGutterWidth);
  #gridSystem > .columns(@gridGutterWidth, @gridColumnWidth, @gridRowWidth, @col);
}

//styles.less
.greetings {
  .col(3);
}

lessc will generate the following in styles.css

//styles.css
.greetings {
  float: left;
  margin-left: 20px;
  width: 220px;
}
伤痕我心 2025-01-08 01:26:54

这是一篇文章,引用了 git 中的 gist

本文试图更进一步 - 解决当您将类移出页面时 Bootstrap 中默认响应机制丢失的问题。

Bootstrap with Less

它使用自定义 mixin 来尝试创建不同断点页面宽度的类。

我想在这里发表我的意见,但我还没有完全决定它是什么:-/

Here's an article which refernces a gist in git.

This article is trying to go one step further - and solve the problem that the default responsive mechanisms in Bootstrap are lost when you move the classes out of your page.

Bootstrap with Less

It uses a custom mixin to try to create classes for different breakpoint page widths.

I'd like to give my opinion here but I haven't quite decided what it is yet :-/

八巷 2025-01-08 01:26:54

对我有用的是:创建一个 .less 文件。

转到 https://github.com/twitter/bootstrap/blob/ master/less/mixins.less 并将 .span*、.row、.offset* 等复制到您创建的文件中。然后使用这样的:

myfile.css.less:

...<snip>...
.span5 { #gridSystem > .columns(@gridGutterWidth, @gridColumnWidth, @gridRowWidth, 5); }
...<snip>...
.offset11 { #gridSystem > .offset(@gridColumnWidth, @gridGutterWidth, 11); }
...<snip>...

#page_footer {
    .about {
      .span4;
      .offset10;
    }
}

What worked for me: create a .less file.

Go to https://github.com/twitter/bootstrap/blob/master/less/mixins.less and copy the .span*, .row, .offset* etc. into the file you created. Then use the like this:

myfile.css.less:

...<snip>...
.span5 { #gridSystem > .columns(@gridGutterWidth, @gridColumnWidth, @gridRowWidth, 5); }
...<snip>...
.offset11 { #gridSystem > .offset(@gridColumnWidth, @gridGutterWidth, 11); }
...<snip>...

#page_footer {
    .about {
      .span4;
      .offset10;
    }
}
梨涡 2025-01-08 01:26:54

如果你使用rails,你可以使用 sass-bootstrap 然后你可以使用 mixins

if you using rails you could use sass-bootstrap you can then use mixins

魂牵梦绕锁你心扉 2025-01-08 01:26:54

Less 提供 mixins,这意味着如果您使用 Less 而不是 CSS 编写样式表,则可以在样式表中包含 Bootstrap 类而不是在你的 HTML 中。

请停止在 HTML 中嵌入 Bootstrap 类!

Less provides mixins, meaning that if you write your stylesheets in Less rather than CSS, you can include the Bootstrap classes in your stylesheet rather than in your HTML.

Please stop embedding Bootstrap classes in your HTML!

唐婉 2025-01-08 01:26:54

我正在使用 https://github.com/thomas-mcdonald/bootstrap-sass 使用@extend 功能。
但它的效果很糟糕:-(

.my-top {
    @extend .span4;
}
.left-top {
    @extend .span4;
}
.right-top {
    @extned .span4;
}

它甚至没有排成一行...

===

哦!我在这个页面找到了我的答案:
如何将 twitter bootstrap 与 bootstrap-sass 一起使用Rails 应用程序?

I'm using https://github.com/thomas-mcdonald/bootstrap-sass with the @extend feature.
but it works awful :-(

.my-top {
    @extend .span4;
}
.left-top {
    @extend .span4;
}
.right-top {
    @extned .span4;
}

it didn't even in one row ...

===

oh! I found my answer in this page:
How to use twitter bootstrap with bootstrap-sass in rails app?

卖梦商人 2025-01-08 01:26:54

不同意您应该“放弃”和“用简单的方法来做”的回应 - 在标记中操作类不是简单的方法。例如:当您的网站在手机上查看时,class="span4"是什么?

我使用 https://github.com/vwall/compass-twitter-bootstrap 因为它似乎是 Twitter Bootstrap 到 Sass 更新最频繁的端口。

这个库很棒,因为它带有前缀以避免 mixin 名称冲突。它很容易用于原型设计,然后您可以快速摆脱它 - 就像 bootstrap 的用途一样。

Disagree with the response that you should "just give up" and "do it the easy way" — manipulating classes in markup not the easy way. For example: When your site is viewed on a mobile phone, what is class="span4"?

I use https://github.com/vwall/compass-twitter-bootstrap because it seems to be the most frequently updated port of Twitter Bootstrap to Sass.

This library is great because it is prefixed to avoid mixin name conflict. It's easy to use for prototyping and then you can quickly grow out of it — just like bootstrap was meant to be used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文