**CSS 文件内部:**
input[type="text"]{
border: 2px solid red;
}
input::placeholder{
color:green;
}
input[title="google"]{
background-color:black;
color:white;
}
为什么类型、占位符和标题的写入过程不同?尽管 标签内的文字看起来相同。如何理解哪些是属性,哪些是元素?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
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; }注意:此答案是从评论转换而来的,因为我找不到任何重复的目标。