【问题标题】:Foundation 5: enable button radii (radiuses) globally基础 5:全局启用按钮半径(半径)
【发布时间】:2013-12-13 06:24:26
【问题描述】:

buttons 组件有这个 mixin,@mixin button-style($bg:$primary-color, $radius:false, $disabled:false) 被这样引用:

@include exports("button") {
  @if $include-html-button-classes {

    // Default styles applied outside of media query
    button, .button {
      @include button-base;
      @include button-size;
      @include button-style;
[...]

所以,元素是 or .button 永远不会有 $radius true 因为 mixin 是在没有任何参数的情况下调用的,因此设置了默认的false。 是否有一种我不知道的智能方法(也许在 SASS 中)可以在全球范围内启用它?

【问题讨论】:

    标签: css sass zurb-foundation


    【解决方案1】:

    在 SASS 中,您可以覆盖默认参数。所以要为按钮启用边框半径,你应该这样做:

    @include exports("button") {
      @if $include-html-button-classes {
    
        // Default styles applied outside of media query
        button, .button {
          @include button-base;
          @include button-size;
          @include button-style($radius: true);
    [...]
    

    按钮的默认边框半径设置为 3px

    //_buttons.scss
    
    [...]
    // We can control how much button radius us used.
    @if $radius == true { @include radius($button-radius); }  //$button-radius = $global-radius = 3px
    @else if $radius { @include radius($radius); }
    }
    [...]
    

    如果您想更改此边框半径,Foundation 建议取消注释 _settings.scss 文件中的这些行并将 3px 更改为所需的值:

    // Line 61
    // $global-radius: 3px;
    
    // Line 236
    // $button-radius: $global-radius;
    

    或者,如果您想为 $button-radius 设置一个不同于 $global-radius 的值(例如 5px),您只需更改 _settings.scss 这个:

    // Line 236
    // $button-radius: 5px
    

    另一种设置按钮边框半径的方法是

    @include exports("button") {
      @if $include-html-button-classes {
    
        // Default styles applied outside of media query
        button, .button {
          @include button-base;
          @include button-size;
          @include button-style($radius: 5px); // Replace 5px by the size that you want
    [...]
    

    我个人推荐第一种方法来维持有组织的结构

    【讨论】:

    • 对不起,亚历克斯,刚刚又偶然发现了这个,意识到我没有意识到你回答了。事情是:关于你的第一种方法,我不想覆盖那个混合调用,因为它是框架国家,我不能在这里改变任何东西。关于 SASS,我什么都清楚,但我不知道 Zurb 基金会的意图是什么……
    【解决方案2】:

    将此添加到您的app.scss:

    button, .button {
        @include button($radius:true);
    }
    

    它将使用_button.scss的mixin修改按钮输入和类。

    【讨论】:

    • 他们没有设置这个的全局变量。您可以提交补丁,修补您自己的版本,将半径类添加到所有按钮,或者有重复的代码。介于两者之间的是将$include-html-button-classes 设置为false 并将修改后的按钮构造函数添加到您的app.scss 文件中。升级不会为构造函数提供任何修复/功能,但会为 _buttons.scss 的其余部分提供。
    猜你喜欢
    • 1970-01-01
    • 2013-07-16
    • 2013-01-26
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 2016-10-15
    相关资源
    最近更新 更多