::grammar-error

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

::grammar-error CSS 偽元素表示使用者代理標記為語法不正確的文字片段。

::grammar-error 偽元素遵循所有高亮偽元素共有的特殊繼承模型。有關此繼承如何工作的更多詳細資訊,請參閱高亮偽元素繼承部分。

允許的屬性

在選擇器中使用 ::grammar-error 的規則中,只能使用 CSS 屬性的一小部分

語法

css
::grammar-error {
  /* ... */
}

示例

基本文件語法檢查

在此示例中,最終支援的瀏覽器應使用所示樣式突出顯示任何標記的語法錯誤。

HTML

html
<p contenteditable spellcheck="true">
  My friends is coming to the party tonight.
</p>

CSS

css
::grammar-error {
  text-decoration: underline red;
  color: red;
}

結果

規範

規範
CSS 偽元素模組 Level 4
# selectordef-grammar-error

瀏覽器相容性

另見