如何在选择字段和选项字段中给出颜色?

时间:2018-06-02 15:58:47

标签: html css forms css3

我在我的网站上建立了联系表格,我想在我的选择字段中添加颜色,就像其他字段一样。现在,当我在“选择”字段中选择任一选项之一时,该字段中不会显示任何选项。我在这做什么错?请通过以下链接查看问题。

http://shahfahad.com/demo/contact.html

2 个答案:

答案 0 :(得分:2)

您可以尝试通过CSS更改option标记内每个select标记的颜色。

例如:

select option {
    background-color: green;  
}
<select>
    <option>Please choose</option>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
    <option>Option 4</option>
</select>

请注意,您不必定位CSS中的所有select标记,也可以使用其ID

如果我理解正确,这应该回答你的问题。

答案 1 :(得分:0)

我能够使用Mozilla的检查器查看代码并成功测试问题。 问题是您已将color属性设置为inherit,因此它与您的背景颜色相同。这只是让它看不见。而是将属性设置为除可见颜色之外的可见颜色。试试这个片段。

&#13;
&#13;
.form-control {
    background: none;
    border-radius: 0;
    border: 1px solid #fff;
    font-size: 18px;
    text-transform: uppercase;
    font-family: 'PT Sans Narrow', sans-serif;
    height: 44px;
    letter-spacing: 1px;
    padding: 26px 10px 26px 15px;
    color: black !important; /* Set the text color to be black, not inherited to the background */
}
.form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: black;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}
button, select {
    text-transform: none;
}
option {
    margin: 0;
    font: inherit;
        font-size: inherit;
        line-height: inherit;
        font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    font-family: inherit;
    font-color: black; /* Set the text color to be black, not inherited to the background */
	}
* {
    -webkit-box-sizing: border-box;
        box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
body {
    font-size: 16px;
    font-family: 'PT Sans', sans-serif;
    color: #414141;
}
html {
    font-size: 10px;
}
html {
    font-family: sans-serif;
    -webkit-text-size-adjust: 100%
	;
}
/* Change the background of all choices */
option {
background-color: blue;
color: gray; /* This is the color of text */
}
#Responsive {
background-color: lightblue;
}
&#13;
 <h2> You could change the background/color of all options. </h2>
<select id="form_service" name="service" class="form-control" title="Please Select Your Service" required="" data-error="Select Your Service.">
 <option disabled="">Choose Your Require Service</option>
  <option value="Responsive Website Desin">Responsive Website Design</option>                                        
 <option value="Wordpress Website Design">Wordpress Website Design</option>
  <option value="Only Template/PSD Design">Only Template/PSD Design</option>
 <option value="PSD to HTML">PSD to HTML</option>
  <option value="PSD to Wordpress">PSD to Wordpress</option>
 <option>Banner Design</option>                                        
</select>
 <h2> You could change the background/color of a specific option. </h2>
<select id="form_service" name="service" class="form-control" title="Please Select Your Service" required="" data-error="Select Your Service.">
 <option disabled="">Choose Your Require Service</option>
  <option id="Responsive">Responsive Website Design</option>                                        
 <option>Wordpress Website Design</option>
  <option>Only Template/PSD Design</option>
 <option>PSD to HTML</option>
  <option>PSD to Wordpress</option>
 <option>Banner Design</option>                                        
</select>
&#13;
&#13;
&#13;