グローバルスタイル
:global(...)
スタイルをグローバルに適用するには、セレクターに :global(...)
修飾子を使用します
<style>
:global(body) {
/* applies to <body> */
margin: 0;
}
div :global(strong) {
/* applies to all <strong> elements, in any component,
that are inside <div> elements belonging
to this component */
color: goldenrod;
}
p:global(.big.red) {
/* applies to all <p> elements belonging to this component
with `class="big red"`, even if it is applied
programmatically (for example by a library) */
}
</style>
グローバルにアクセス可能な @keyframes を作成する場合は、キーフレームの名前に -global-
を挿入する必要があります。
コンパイルすると -global-
部分は削除され、キーフレームはコードの他の場所で my-animation-name
として参照されるようになります。
<style>
@keyframes -global-my-animation-name {
/* code goes here */
}
</style>
:global
グループのセレクターにスタイルをグローバルに適用するには、:global {...}
ブロックを作成します
<style>
:global {
/* applies to every <div> in your application */
div { ... }
/* applies to every <p> in your application */
p { ... }
}
.a :global {
/* applies to every `.b .c .d` element, in any component,
that is inside an `.a` element in this component */
.b .c .d {...}
}
</style>
上記の 2 番目の例は、
.a :global .b .c .d
という同等のセレクターとして記述することもできます。ここでも:global
の後にあるすべてはスコープ外ですが、ネストされた形式の方が推奨されます。
前へ 次へ