div悬停背景颜色变化?

时间:2012-02-13 19:27:44

标签: css html hover

我如何让它像一行div一样锚定,所以当我将鼠标悬停在它上面时它会返回红色

CSS

.e
{
    width:90px;
    border-right:1px solid #222;
    text-align:center;
    float:left;
    padding-left:2px;
    cursor:pointer;


}
.f .e
{
    background-color:#F9EDBE;

}

HTML

<div>
    <div class="e" >Company</div>
    <div class="e">Target</div>
    <div class="e" style="border-right:0px;">Person</div>
</div>         
<div class="f">
    <div class="e">Company</div>
    <div class="e">Target</div>
    <div class="e" style="border-right:0px;">Person</div>
</div>   
<div>
    <div class="e">Company</div>
    <div class="e">Targetaaa</div>
    <div class="e" style="border-right:0px;">Person</div>
</div>            
<div class="f"> 
    <div class="e">Company</div>
    <div class="e">Target</div>
    <div class="e" style="border-right:0px;">Person</div>
</div>  

4 个答案:

答案 0 :(得分:118)

.e:hover{
   background-color:#FF0000;
}

答案 1 :(得分:32)

如果您希望在只添加:hover

时更改颜色
div.e:hover {
    background-color:red;
}

答案 2 :(得分:0)

div悬停背景颜色更改

尝试这样:

.class_name:hover{
    background-color:#FF0000;
}

答案 3 :(得分:0)

<html>
<head>
<style>

.e {
    width:90px;
    border-right:1px solid #222;
    text-align:center;
    float:left;
    padding-left:2px;
    cursor:pointer;
}

e2:hover {
    background-color:red;
}

</style>
</head>
<body>

<div>
    <div class="e e2" >Company</div>
    <div class="e e2">Target</div>
    <div class="e e2" style="border-right:0px;">Person</div>
</div>

</body>
</html>