【问题标题】:Special case heading sizes with Foundation 6Foundation 6 的特殊标题尺寸
【发布时间】:2017-06-25 19:45:20
【问题描述】:

TL;DR

相对于 Foundation 6 下的内置断点,添加不同字体大小的最佳方法是什么?

使用 Foundation 6,我可以调整 _settings.scss 下每个断点的六个标题的映射:

$header-styles: (
  small: (
    'h1': ('font-size': 39),
    'h2': ('font-size': 28),
    'h3': ('font-size': 22),
    'h4': ('font-size': 19),
    'h5': ('font-size': 16),
    'h6': ('font-size': 15),
  ),
  medium: (
    'h1': ('font-size': 39),
    'h2': ('font-size': 28),
    'h3': ('font-size': 22),
    'h4': ('font-size': 19),
    'h5': ('font-size': 16),
    'h6': ('font-size': 15),
  ),
);

这对于顶级标题是可以的,但是当我在结构标记中的页面上有多个 h1 时,我希望其他子部分中的 h1 具有不同的字体大小。例如。 19px 而不是上面看到的 39px。

<header>
  <h1>This is 39px by default. Cool.</h1>
</header>
<article>
  <h1>This should be smaller size in appearance e.g. 19px</h1>
  <p>Both h1's should follow and scale to the breakpoints small, medium, etc.<p>
</article>

编辑:

我了解到我可以在列表中添加一个类名并且它可以工作,但这似乎是一种不正确的做法,它假定辅助 h1 将始终具有类 .special:

$header-styles: (
  small: (
    'h1': ('font-size': 39),
    'h2': ('font-size': 28),
    'h3': ('font-size': 22),
    'h4': ('font-size': 19),
    'h5': ('font-size': 16),
    'h6': ('font-size': 15),
    '.special': ('font-size': 100),
  ),
  medium: (
    'h1': ('font-size': 39),
    'h2': ('font-size': 28),
    'h3': ('font-size': 22),
    'h4': ('font-size': 19),
    'h5': ('font-size': 16),
    'h6': ('font-size': 15),
    '.special': ('font-size': 200),
  ),
);

【问题讨论】:

    标签: html sass zurb-foundation font-size


    【解决方案1】:

    如果您可以在 HTML 中指定位置(例如在您的示例中):

    $header-styles: (
      small: (
        'h1': ('font-size': 39),
        'article > h1': ('font-size': 100), // target only h1 that are direct children of an article
        'h2': ('font-size': 28),
        'h3': ('font-size': 22),
        'h4': ('font-size': 19),
        'h5': ('font-size': 16),
        'h6': ('font-size': 15),
      ),
      medium: (
        'h1': ('font-size': 39),,
        'article > h1': ('font-size': 200), // target only h1 that are direct children of an article
        'h2': ('font-size': 28),
        'h3': ('font-size': 22),
        'h4': ('font-size': 19),
        'h5': ('font-size': 16),
        'h6': ('font-size': 15),
      ),
    );
    

    根据您的 HTML 结构,您可能还可以使用 pseudo selectors,如 last-of-typenth-child() 附加到元素类型以更广泛地定位。我一直发现特异性方法(上图)比伪选择器中的稍微分散的应用程序更安全。

    【讨论】:

    • 是的,这基本上就是我上面的内容,但我觉得这似乎有点脏,不是吗?我发现的唯一其他选项是在标题、段落等内部添加断点,该断点与 _settings.scss 下的 Foundation 断点变量相关联:h1 { @include breakpoint(small-up) { // styles } }
    • 是的,确实如此!我会担心意想不到的后果,它会在升级时被覆盖,但除了编写自己的 SASS / Map 和 / 或变量之外,这似乎是唯一的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2015-10-29
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多