如何在 Compass/Blueprint 中组织导入?

发布于 2024-10-16 12:12:26 字数 1113 浏览 1 评论 0原文

我已经分别研究了 SASS 和 Blueprint,并且认为我了解它们是如何工作的,并且我已经使用 compass CLI 工具设置了我的项目目录,但我不知道组织我的项目的正确方法。

使用

$ compass create my_project --using blueprint/semantic

...初始化我的项目后,我被告知将 HTML 中生成的 CSS 文件与这些行链接起来

<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
<link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />

...但是我应该将自己的特定于应用程序的 .scss 文件放在哪里以及应该如何放置包括适当的蓝图文件?

在我看来,我不应该将生成的 print.cssscreen.css 直接包含到我的 HTML 中,而是执行以下操作:

@import "screen";

body {
    @include container;
}

...然后使用 < em>仅在我的 HTML 中从上面生成的文件。否则为什么我们会在 screen.scss 中出现这样的一行?:

// Import all the default blueprint modules so that we can access their mixins.
@import "blueprint";

我不能在 HTML 中使用 mixin。

我发现这些文档非常模糊和矛盾,并且任何类型的简短示例说明了以下组合:

  1. HTML
  2. 从compass命令生成的
  3. SCSS文件,上面包含特定于站点的样式的SCSS文件

将对我和其他人非常有帮助。

I have researched SASS and Blueprint seperately, and think I understand how they work, and I have set up my project directory using the compass CLI tool, but I am at a loss as to the correct way to organize my project.

After initializing my project with

$ compass create my_project --using blueprint/semantic

...I was told to link the generated CSS files in my HTML with these lines

<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
<link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />

...but where should I put my own application-specific .scssfiles and how should I include the appropriate blueprint files?

It seems to me that I should not be including the generated print.css and screen.css directly into my HTML but instead doing something like:

@import "screen";

body {
    @include container;
}

...and then using only the file generated from the above in my HTML. Otherwise why would we have a line like this in screen.scss?:

// Import all the default blueprint modules so that we can access their mixins.
@import "blueprint";

I can't use mixins in my HTML.

I'm finding the docs to be very vague and contradictory, and any sort of short example illustrating the combination of:

  1. HTML
  2. SCSS files generated from compass command above
  3. SCSS files containing site-specific styling

would be very helpful for me and probably others.

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

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

发布评论

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

评论(1

最近可好 2024-10-23 12:12:26

“screen.scss”和“print.scss”文件没什么神奇的。这些只是为输出提供的示例文件名,您可以从 HTML 链接这些文件名,但您不必这样做:只需删除它们并创建您自己的文件(如果您愿意),或者将您自己的样式添加到他们。这两个文件的目的是分开组织样式问题:您可以添加“mobile.scss”,然后在 HTML 中链接所有这些文件,或者将它们一起导入到 @media 块。

我无法在 HTML 中使用 mixins。

Mixin 不适用于您的 HTML。它们是用于编写 SCSS 源代码的有用技术:编译后的 CSS 输出或 HTML 对它们一无所知。您应该使用 mixin 来利用 Sass。

我分别研究了SASS和Blueprint

首先了解 Blueprint 类的作用很重要,但是当您使用 Compass 时,可以采用不同的方法来应用 Blueprint 等框架:


1. 在整个 HTML 中使用 Blueprint 的原始非语义类名称

这是不被认为是最佳实践,但它是一种入门方法,尤其是在线框/脚手架时:

screen.scss

    @import "blueprint";

    // This outputs Blueprint's classes into your stylesheet:
    @include blueprint;

    #sidebar { background: $blue; }
    #main { background: $yellow; }

screen.css (compiled)

    .column { float: ... }
    .span-6 { width: ... }
    .span-12 {width: ... }
    /* ...etc., all of Blueprint's classes ... */
    #sidebar { background: #ccf; }
    #main { background: #ffc; }

index.html

    <div id="sidebar" class="column span-6">sidebar content</div>
    <div id="main" class="column span-12">main content</div>

结果与使用不带 Sass/Compass 的蓝图相同。您的 HTML 将包含表示类,这实际上与在元素上使用 style="width:120px" 没有太大区别:它只是使用类来完成。


2. 使用 Blueprint 作为您自己的语义类名称中的混入:

screen.scss

    @import "blueprint";
    // Do not output Blueprint's classes into your stylesheet.
    // Instead, write your own classes and mixin the functionality:
    #sidebar {
      @extend .column;
      @include span(6);
      background: $blue; }
    #main {
      @extend .column;
      @include span(12);
      background: $yellow; }

screen.css (compiled)

    .column, #sidebar, #main { float: left; ... }
    #sidebar { width: 240px; background: #ccf; }
    #main { width: 480px; background: #ffc; }

index.html

    <div id="sidebar">sidebar content</div>
    <div id="main">main content</div>

如您所见,第二种方法将 Blueprint 的表示逻辑从 HTML 移出并移入样式表。

明智地使用@extend(而不是@include)是一种优化,可以让您将常见样式分组在一起,例如,所有“列”元素都被定义为选择器列表;只是它们的不同宽度直接包含在每个元素中。

The "screen.scss" and "print.scss" files are nothing magical. These are just example filenames given to the output which you can link from your HTML, but you don't have to: just delete them and create your own files if you prefer, or add your own styles to them. The intent with these 2 files is to keep the style concerns organized separately: you could add a "mobile.scss" and then link all these in your HTML, or import them together into one master file under @media blocks.

I can't use mixins in my HTML.

Mixins don't apply to your HTML. They are a helpful technique used for writing your SCSS source code: the compiled CSS output or the HTML doesn't know anything about them. You should be using mixins to take advantage of Sass.

I have researched SASS and Blueprint seperately

It's important to understand what the Blueprint classes do first, but when you use Compass there are different approaches for how you apply frameworks like Blueprint:


1. Use Blueprint's original non-semantic class names throughout your HTML

This is not considered best-practice, but it's a way to get started especially when wireframing/scaffolding:

screen.scss

    @import "blueprint";

    // This outputs Blueprint's classes into your stylesheet:
    @include blueprint;

    #sidebar { background: $blue; }
    #main { background: $yellow; }

screen.css (compiled)

    .column { float: ... }
    .span-6 { width: ... }
    .span-12 {width: ... }
    /* ...etc., all of Blueprint's classes ... */
    #sidebar { background: #ccf; }
    #main { background: #ffc; }

index.html

    <div id="sidebar" class="column span-6">sidebar content</div>
    <div id="main" class="column span-12">main content</div>

The result is the same as using Blueprint without Sass/Compass. Your HTML would contain the presentational classes, which are really not too different from just using style="width:120px" on your elements: it's just done using classes instead.


2. Use Blueprint as mixins into your own semantic class names:

screen.scss

    @import "blueprint";
    // Do not output Blueprint's classes into your stylesheet.
    // Instead, write your own classes and mixin the functionality:
    #sidebar {
      @extend .column;
      @include span(6);
      background: $blue; }
    #main {
      @extend .column;
      @include span(12);
      background: $yellow; }

screen.css (compiled)

    .column, #sidebar, #main { float: left; ... }
    #sidebar { width: 240px; background: #ccf; }
    #main { width: 480px; background: #ffc; }

index.html

    <div id="sidebar">sidebar content</div>
    <div id="main">main content</div>

As you can see, the second method moves Blueprint's presentation logic out of the HTML and into the stylesheet.

The judicious use of @extend (instead of @include) is an optimization that lets you group common styles together, e.g. all the elements that are "columns" are defined once as a list of selectors; only their different widths are included directly into each element.

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