简体   繁体   English

使用CSS更改输入字段的文本颜色

[英]Change color of text for input field using css

I have created an input field for a log-in feature on the page however I have been trying to change the color of the text in the field using css. 我已经在页面上为登录功能创建了输入字段,但是我一直在尝试使用CSS更改字段中文本的颜色。 Is this possible. 这可能吗。 I have tried many routes however none seem to work so far. 我尝试了很多路线,但到目前为止似乎都没有。 Below is the code for the email portion of the sign in. 以下是登录电子邮件部分的代码。

 <input class="form-control ng-class:{'error':dashboard.showFormErrors && !dashboard.signinForm.email.$valid}"
               data-ng-model="signinController.signin.email"
               type="email"
               name="email"
               id="email"
               placeholder="Email"
               ng-minlength="2"
               ng-maxlength="3"
               required>

Yes, it is possible. 对的,这是可能的。

The CSS can target the input of type "email" or just this unique input. CSS可以定位“电子邮件”类型的输入或仅此唯一输入。

Email input element: 电子邮件输入元素:

input[type=email]{
    color: red;
}

Or specific id="email": 或特定的id =“ email”:

#email {
    color: red;
}

Here's a snippet: 这是一个片段:

 input[type=email] { color: red; } #email2 { color: green; } 
 <input class="form-control ng-class:{'error':dashboard.showFormErrors && !dashboard.signinForm.email.$valid}" data-ng-model="signinController.signin.email" type="email" name="email" id="email" placeholder="Email" ng-minlength="2" ng-maxlength="3" required> <input class="form-control ng-class:{'error':dashboard.showFormErrors && !dashboard.signinForm.email.$valid}" data-ng-model="signinController.signin.email" type="email" name="email" id="email2" placeholder="Email" ng-minlength="2" ng-maxlength="3" required> 

If this still isn't working, you may have to use the "!important" attribute to override other CSS setters. 如果仍然无法使用,则可能必须使用“!important”属性来覆盖其他CSS设置器。

color: red !important;

I think you can do this in your css file : 我认为您可以在css文件中执行此操作:

#email{
  color:red;
}

You can give color of your choice. 您可以选择颜色。

Create a css class that holds the changes you want to do to the fields , and then affect the class to the input tags via ng-class directive. 创建一个css类,其中包含要对字段进行的更改,然后通过ng-class指令影响该类对输入标签的影响。 In your code the syntax is wrong I think.. but that's the idea. 我认为在您的代码中语法是错误的..但这就是想法。

You can apply the following code input { color: red; 您可以应用以下代码输入{ } }

It is definitely possible that you can change your input's text color with CSS and there are quite some ways to that depending upon the result you want to achieve. 绝对有可能您可以使用CSS更改输入的文本颜色,并且有很多种方法可以实现,具体取决于要实现的结果。

For example, if you want to set your colour to blue and have it always stay blue, you can use the following code: 例如,如果要将颜色设置为blue并始终保持蓝色,则可以使用以下代码:

#email {
    color: blue; /* Or color: #0000ff */
}

Alternatively, if you want to change your text's colour when your selected input has focus, you can use this instead: 另外,如果要在选定的输入具有焦点时更改文本的颜色,则可以使用以下方法:

#email:focus {
    color: blue; /* Or color: #0000ff */
}

You can also change your colour on hover, but this is not something that is used very often: 您还可以在悬停时更改颜色,但这不是经常使用的方法:

#email:hover {
    color: blue; /* Or color: #0000ff */
}

To change input color for different types of input use respective tag (with/without its pseudo state) 要为不同类型的输入更改输入颜色,请使用相应的标签(带有/不带有伪状态)

input, select, textarea {
    color: #000;
}
input:focus, input:active

/* etc... */

input[type=text] - will only select text fields
input[type=password] - will only select password fields
input[type=number] - will only select number fields
/* etc.. */

input[type=text]:focus
/* etc */

For placeholder styling 用于占位符样式

::-webkit-input-placeholder {
   color: red;
}

:-moz-placeholder { /* Firefox 18- */
   color: red;  
}

::-moz-placeholder {  /* Firefox 19+ */
   color: red;  
}

:-ms-input-placeholder {  
   color: red;  
}

Many of your suggestions work great. 您的许多建议效果很好。 This is the route I used with css 这是我与CSS一起使用的路线

input, select, textarea{
    color: #076000;
}

textarea:focus, input:focus {
    color: #076000;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM