【问题标题】:specifying existence of border or not in Sass在 Sass 中指定边界是否存在
【发布时间】:2012-06-21 11:40:32
【问题描述】:

我正在使用 Rails 3.1 并希望有一个可以设置的 Sass 变量(或其他技术)

$show_border: border: 1px solid black;

在布局中

.info{
  $show_border
  width: 600px;
  display:inline-block;
  float:left;
}

这样我就可以看到布局并集中打开和关闭它。我不能只将边框设置为 0,因为它不能跨浏览器工作。有没有简单的方法来做到这一点?

谢谢

【问题讨论】:

    标签: ruby-on-rails sass


    【解决方案1】:

    如果你愿意,你可以把它当作一个 mixin:

    @mixin show_border {
      border: 1px solid black;
    }
    
    .info {
      @include show_border;
    }
    

    或者您可以在 JavaScript 中执行此操作(即从书签中):

    $(".info").css({ border: "1px solid black" }); // with jQuery
    
    // Without jQuery (in modern browsers)
    Array.prototype.slice.call(document.getElementsByClassName("info"), 0).forEach(function (element) {
      element.style.border = "1px solid black";
    });
    

    【讨论】:

      猜你喜欢
      • 2013-08-20
      • 2014-02-07
      • 1970-01-01
      • 2014-11-08
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 2018-07-21
      • 2015-09-26
      相关资源
      最近更新 更多