大网数据广告活动
Web 标准与前端开发

CSS custom functions and mixins

· 52CE 我爱测

The **CSS custom functions and mixins** module allows developers to create reusable blocks of CSS code that can accept arguments, contain complex logic (defined using features such as CSS if() functions and @media at-rules), and return values based on that logic.

The CSS custom functions and mixins module allows developers to create reusable blocks of CSS code that can accept arguments, contain complex logic (defined using features such as CSS if() functions and @media at-rules), and return values based on that logic.

CSS custom functions are defined in @function at-rules and called using <dashed-function> syntax, which looks very similar to CSS custom property syntax except that it includes parentheses at the end containing arguments (for example, --my-function(30px, 3)). CSS custom functions can be called within any property value, and will return a value based on the arguments passed into the function and the logic inside it.

CSS mixins are defined in @mixin at-rules and applied using @apply at-rules nested inside rulesets. CSS mixins define a set of properties that can be reused inside multiple rulesets and customized with arguments and logic.

CSS custom functions and mixins can be assigned optional data types for their arguments and return values, to restrict the values passed into them and returned from them.

[!NOTE] Currently, only CSS custom functions have browser support. CSS mixins are not currently supported in any browser.

Reference

At-rules and descriptors

  • @function
    • @function#result

The CSS custom functions and mixins module also introduces the @mixin, @apply, @contents, and @env at-rules. Currently, no browsers support these features.

Data types and values

  • dashed-function

Functions

  • type

Interfaces

  • CSSFunctionRule
  • CSSFunctionDeclarations
  • CSSFunctionDescriptors

Guides

Related concepts

CSS values and units

  • abs()
  • acos()
  • asin()
  • atan()
  • atan2()
  • calc()
  • clamp()
  • cos()
  • exp()
  • log()
  • max()
  • min()
  • mod()
  • pow()
  • rem()
  • round()
  • sign()
  • sin()
  • sqrt()
  • tan()

Specifications

See also

  • if()
  • @media

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。