使用类将样式应用于div中的元素

时间:2013-07-26 15:14:56

标签: html css styles

我能做什么:

HTML:

<div id="test">
    HELLO! 
    <input type="text">
</div>

CSS:

#test {
   color:#F00;
}

#test input[type=text] {
   background-color:#000;
}

如果#test没有ID而是一个班级,我想做的是同样的事情:

<div class="test">
   ...

在这种情况下我该如何编写CSS?

2 个答案:

答案 0 :(得分:3)

使用.表示课程。

.test {
    color: red;
}

答案 1 :(得分:2)

只需将#替换为.(句号):

.test {
   color:#F00;
}

.test input[type=text] {
   background-color:#000;
}