css - Sass % 运算符

标签 css sass

<分区>

我工作的一位开发人员最近离开了,在查看他的 sass 代码时,我发现了这一点:

%centerAll {
  display: block;
  position: relative;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

我会说我对 sass 非常有经验,但我从未在 Sass 中看到任何使用模运算符的东西。更奇怪的是,这个“mixin”包含在代码中:

@extend %centerAll

据我所知,@extend 用于通过继承扩展类的属性。

有没有人见过这个?

最佳答案

这是一个 placeholder selector .

They are very similar to class selectors, but instead of using a period (.) at the start, the percent character (%) is used. Placeholder selectors have the additional property that they will not show up in the generated CSS, only the selectors that extend them will be included in the output.

关于css - Sass % 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33024998/

相关文章:

html - 使用内容 : ""; in SASS (not scss)

sass - 如何像在 React 中那样在 Preact 中简单导入样式?

FF 和 IE 中的 HTML 边框差异

javascript - CSS3 - 用可变数量的不同大小的矩形填充网页的最短方法

php - WordPress 发布缩略图大小调整问题

sass - 您可以使用 SCSS 模块定位/修改现有类吗?

css - Sass 错误 : no mixin named roboto-family Backtrace: src/pages/forms/forms. scss:5

css - 清除 CSS 过渡

html - 当我将我的背景大小设置为除了覆盖之外的任何内容时,每当图像调整大小时,我的 div 内的文本就会溢出。我该如何防止呢?

ruby-on-rails - 更新破坏 Sass 框架 - 不兼容的单元 : 'px' and 'em'