**In der CSS-Datei:**
input[type="text"]{ border: 2px solid red; } input::placeholder{ color:green; } input[title="google"]{ background-color:black; color:white; }
Warum sind die Schreibverfahren für Typen, Platzhalter und Titel unterschiedlich? Auch wenn der Text im -Tag gleich aussieht. Wie kann man verstehen, welche Attribute und welche Elemente sind?
input::placeholder
選擇 的占位符,而
input[attribute="value"]
選擇 >
其屬性值為 value。它們做不同的事情。
可視化示例:
/* Selects an <input> with a 'placeholder' attribute */ input[placeholder] { color: #2ab7ca; } /* Selects the placeholder itself */ input::placeholder { color: #ff6b6b; } /* Ignore these */ body { margin: 0; padding: 2em; } input { display: block; margin: 1em 0; height: 2em; width: 100%; padding: 0.5em; }
<input type="text" placeholder="This placeholder is red and not editable." > <input type="text" placeholder="" value="...whereas the input content itself is blue and editable." >
注意:此答案是從評論轉(zhuǎn)換而來的,因為我找不到任何重復(fù)的目標(biāo)。