Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a CSS classes named
CSS
class1
{
color:red;
}
class2
{
color:blue;
}
class3
{
color:yellow;
}

and I have a text box
HTML
<input type="text" id="txtname" class="class1 class2 class3" >

The text box includes 3 classes. So on running the text box which will be the color of the text and how can I predict the color.
Posted
Updated 9-Apr-14 1:39am
v4
Comments
Thomas Daniels 9-Apr-14 7:42am    
I rolled back your edit and formatted the code. The reason for the rollback was that you added dots before the class names, as said in Solution 1. But adding them invalidated a part of that answer, because the answer says that there are some mistakes, but that statement was incorrect after you edited your question. So, I rolled back your edit to make the answer again fully correct.
My Doubt 9-Apr-14 7:43am    
ok I appreciate your roll back.

1 solution

Yes, you can use multiple class in same field as you did. But there are some mistake in your class file.
it should have '.' prefix in style tag class name like
XML
<style>

.class1
{
color:red;
}
.class2
{
color:blue;
}
.class3
{
color:yellow;
}
</style>


Now, in such case, last class will be effective (mainly the last overlapping property)
 
Share this answer
 
Comments
My Doubt 9-Apr-14 7:38am    
So the color will be yellow? So what is the need of using more than one class
Er. Puneet Goel 9-Apr-14 7:42am    
yes the color will be yellow, use of more than one class depends on your requirement like
You have three text box, In one you need Border:red, in second you need Color:red
Now in third you need both border and color red than instead of creating three class, just create two class and in third text box use both class.So two properties will be merged.

please mask solution accepted in case you get the solution.
Thomas Daniels 9-Apr-14 7:47am    
I don't see why someone downvoted this. It's a correct answer, so +5!
My Doubt 9-Apr-14 7:58am    
Mr. Er.Puneet,
So I have a doubt that if I use classes
.class1
{
font-weight:bold;
}
.class2
{
color:red;
}
.class3
{
height:20px;
}
So my text box takes all the properties said in the class?
Er. Puneet Goel 12-Apr-14 7:42am    
yea off course

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900