English 中文(简体)
HTML/CSS文本框文本颜色
原标题:HTML/CSS textbox text color

使用VS Code Live Server扩展和Chrome。出于某种原因,我可以更改文本框的所有其他属性,但不能更改文本颜色——为什么?

文本框.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Search Google</title>
        <link rel="stylesheet" href="textbox.css">
    </head>
    <body>
        <input id="search-box" type="text" placeholder="Search Google or type a URL">
    </body>
</html>

文本框.css:

#search-box {
    font-family: Arial;
    font-size: 16px;
    background-color: red;
    color: blue;
}
问题回答

color属性仅为用户在表单字段中键入的文本设置样式。要为占位符文本上色,需要使用:占位符伪元素:

#search-box {
  font-family: Arial;
  font-size: 16px;
  background-color: red;
  color: blue;
}

::placeholder {
  color: blue;
}
<input id="search-box" type="text" placeholder="Search Google or type a URL">

您只能更改输入文本的颜色,但不能更改占位符文本的颜色。如果要设置占位符文本的颜色,可以执行以下操作:

#search-box::placeholder {
     color: blue;
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签