开发者

CSS -- Creating sub classes

I have a default style for my input boxes. I would like to add an additional style to the box when I specify a class of "req". It's not working. Here's my code.

CSS:

开发者_运维百科
input{background-color: #000; color: #FFF; border: 1px solid #515151; width: 230px;}
input req {background-color: Purple;}

HTML:

<input id="FirstName" type="text" class="req" />

The textbox reflects the input class, but not the sub class. Any ideas?


In your CSS stylesheet, change:

input req { ... }

to:

input.req { ... }

(input.req denotes all input elements that belong to class req, while input req denotes all req elements that are inside an input element. The dot prefixed class name is merely shorthand for the [class~=req] attribute selector.)


Turns out I need a dot between my base input class and my sub class.

input.req {background-color: Purple;} 


You are missing a dot from class name, try this:

input.req {background-color: Purple;}

Or simply add this style because you are already using this for your textbox:

.req {background-color: Purple;}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜