开发者

CSS Comma Usage

Below is some CSS code.

.form-field {min-height: 20px; margin-bottom: 开发者_JS百科10px; padding-top: 4px; width: 80px;}
.form-field TEXTAREA, INPUT[type='text'] {position: absolute; left: 100px; top: 0px; height: 15px;}
.form-field TEXTAREA {height: 80px;}

So every time there is a input or textarea in the div.form-field that css should be applied.

Although anywhere just a INPUT[type='text'] (even outside the .form-field) the css gets applied. How do I stop it from doing that?


.form-field TEXTAREA, .form-field INPUT[type='text']{


The comma separates the entire selector. So .form-field TEXTAREA, INPUT[type='text'] selects .form-field TEXTAREA and INPUT[type='text'].

What you might be interested in is the :matches() selector. At present, this is only available in FireFox as the :-moz-any() selector. That allows you to write:

.form-field:-moz-any(TEXTAREA, INPUT[type='text'])

However, it's safer just to go with

.form-field TEXTAREA, .form-field INPUT[type='text']

As a side note, HTML tag names should be lowercase. So you should really be using

.form-field textarea, .form-field input[type='text']


Whoops you wanted OR, ignore this.

The + "Matches any F element immediately preceded by a sibling element E." Source: W3

.form-field TEXTAREA + INPUT[type='text'] {position: absolute; left: 100px; top: 0px; height: 15px;}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜