我正在处理一个新的 web 组件,但标签的定义方式让我卡住了。
HTML 看起来是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Chessboard Element Demo</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.11.0/chess.min.js"></script>
<script type="module" src="https://unpkg.com/chessboard-element?module"></script>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<script type="module">
const board = document.querySelector('chess-board');
const game = new Chess();
</script>
<style>
chess-board::part(white) { background-color: white; }
chess-board::part(black) { background-color: orange; }
/* does not work */
chess-board [part*="black"] { color: blue }
chess-board > [part="board"] > [part*="black"] > [part*="notation"] { color: blue }
</style>
</head>
<body>
<div class="flex items-center justify-center w-screen">
<chess-board position="start" draggable-pieces class="w-1/2" />
</div>
</body>
</html>
这可用于为所有符号设置样式。
chess-board::part(notation) { background-color: #829982; }
这适用于对白色区域内的所有内容进行样式设置。
chess-board::part(white) { background-color: #829982; }
但是这些都不起作用:
chess-board::part(white notation) { background-color: #829982; }
chess-board::part(white)::part(notation) { background-color: #829982; }
有人知道是否有一种语法可以针对父元素进行定位吗?
[part="notation"] { background-color: #829982; }
、web-component [part="notation"] { background-color: #829982; }
和*[part="notation"] { background-color: #829982; }
。 - vesperknight