如何在不同的表单元素中提供css属性?

时间:2017-03-23 16:13:48

标签: css

我的html页面中有两个表单。这两个表单都包含input type="text"属性。

如何为输入类型文本提供不同的CSS?

如果我申请:

input[type=text] {
   //style
}

它将改变表格元素的风格。

2 个答案:

答案 0 :(得分:0)

你可以给每个输入它自己的Id或类选择器并分别设置Ids样式。

<input id='input1'> </input>
<input id='input2'> </input>

<style> 
#input1 {
-- insert styles here for input 1
}

#input2 {
-- insert styles here for input 2
}
</style>

您还可以通过创建内联样式(快速和脏)来实现所需的结果。

<input style="style1:theStyle;"> </input>
<input style="style2:theStyle;"> </input>

将来请分享一个代码段并更具描述性。

答案 1 :(得分:0)

为此我认为你有这个输入[type = text]标签的任何容器。所以你可以使用这个容器作为参考,并指向两个输入标签。

&#13;
&#13;
.form-container input[type=text]:nth-child(1){
border:2px dashed #000;
}
.form-container input[type=text]:nth-child(2){
border:2px dotted #000;
}
&#13;
<div class="form-container">
  <input type="text" >
  <input type="text">
</div>
&#13;
&#13;
&#13;

或者你可以提出一个&#39; id&#39;输入标签。

&#13;
&#13;
#form-one{border:1px dashed #000;}
#form-two{border:1px dotted #000;}
&#13;
<div class="form-container">
<input type="text" id="form-one" >
<input type="text" id="form-two">
</div>
&#13;
&#13;
&#13;