如何拼接css变量

如--co1为 #ff3366, 这个值是后台设置的, 有且仅有一个全局颜色
这样使用没问题: background: var(--co1)

现在有一个块要设置半透明: #ff336655 怎么设置呢(不能用js)

background: var(--co1)"55" //无效
background: calc(var(--co1)"55") //无效

阅读 5.1k
1 个回答
<html>

<head>

<title>option chain</title>

<meta charset="utf-8" />

<style>

body {

--x: 255, 0 ,0;

}

div {

height: 100px;

}

div:nth-of-type(1) {

background-color: rgb(var(--x));

}

div:nth-of-type(2) {

background-color: rgba(var(--x), .5);

}

</style>

</head>

<body>

<div></div>

<div></div>

</body>

</html>

ff336655 是有效的颜色值?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题