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

`<dashed-function>` CSS type

· 52CE 我爱测

The **`<dashed-function>`** CSS data type represents the syntax used to call CSS custom functions, which are defined using the @function at-rule.

The <dashed-function> CSS data type represents the syntax used to call CSS custom functions, which are defined using the @function at-rule.

Syntax

A <dashed-function> value consists of the --function-name, followed by parentheses containing the function's arguments (for example, --my-function(30px, 3)).

You can include <dashed-function> values in place of regular CSS property values or property value components, in cases where you want to dynamically calculate the values based on function logic rather than providing static values.

In cases where you want to pass comma-containing values as arguments, you can do so by wrapping them in curly braces ({ }).

Examples

For more examples, see our Using CSS custom functions guide.

Basic <dashed-function> usage

This example shows a basic function that returns a semi-transparent version of the color passed to it.

HTML

The markup features a p containing some text content:

<p>Some content</p>

CSS

In our styles, we first define the CSS custom function. The function is called --transparent and accepts two parameters: a color and a numeric alpha channel value. Inside the function body, we use relative color syntax to transform the passed color into an oklch() color with an alpha channel equal to the passed alpha value; this becomes the function's result:

@function --transparent(--color <color>, --alpha <number>) {
  result: oklch(from var(--color) l c h / var(--alpha));
}

Next, we define a --base-color custom property with a value of #faa6ff on the :root element. We assign that property to be the value of the <p> element's border color, and then set its background-color value to equal a transparent version of the same color. This is done by setting the value to equal the <dashed-function> syntax, specifying the --transparent() function and passing it arguments of var(--base-color) and 0.8.

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  place-items: center;
  font-family: system-ui;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 20px,
    lightgrey 20px 40px
  );
}
:root {
  --base-color: #faa6ff;
}

p {
  width: 50%;
  padding: 30px;
  border-radius: 20px;
  border: 3px solid var(--base-color);
  background-color: --transparent(var(--base-color), 0.8);
}

Result

basic-example

Specifications

Browser compatibility

See also

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

资料来源与适用范围

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

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

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