【问题标题】:Why doesn't background-color change when I use button:hover?为什么当我使用按钮时背景颜色没有改变:悬停?
【发布时间】:2010-12-26 01:37:02
【问题描述】:
    body{
font-family:"Arial","Lucida Grande", "Lucida Sans Unicode", Verdana, Helvetica, sans-serif;
font-size:12px;
}
p, h1, form, button{border:0; margin:0; padding:0;}
.spacer{clear:both; height:1px;}
/* ----------- My Form ----------- */
.myform{
margin:0 auto;
width:450px;
padding:14px;
}

/* ----------- regForm ----------- */
#regForm{
border:solid 2px #b7ddf2;
background:#A9D0F5;
}
#regForm h1 {
font-size:18px;
font-weight:bold;
margin-bottom:8px;
}
#regForm p{
font-size:11px;
color:#666666;
margin-bottom:20px;
border-bottom:solid 1px #b7ddf2;
padding-bottom:10px;
}
#regForm label{
display:block;
font-weight:bold;
text-align:right;
width:140px;
float:left;
}

#regForm .small{
color:#666666;
display:block;
font-size:11px;
font-weight:normal;
text-align:right;
width:140px;
}
#regForm input{
float:left;
font-size:100%;
padding:4px 2px;
border:solid 1px #2E9AFE;
width:200px;
margin:2px 0 20px 10px;

}
input:focus{
color:#848484;
font-weight:bold;
background-color:#FFC;
}
#regForm select{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #2E9AFE;
width:200px;
margin:2px 0 20px 10px;
}

#regForm button{
clear:both;
margin-left:150px;
width:150px;
height:50px;
background:#2E9AFE no-repeat;
text-align:center;
line-height:32px;
color:#FFFFFF;
font-size:20px;
font-weight:bold;
}
button:hover{
background-color:#FFC;

}

我的问题是为什么按钮的背景颜色没有改变?谢谢。

fyi 我的 .html 中有这一行:

<button type="submit">Sign-up</button>

【问题讨论】:

标签: html css hover


【解决方案1】:

这是因为选择器 #regForm buttonbutton:hover具体 - 请参阅:http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html 以了解有关该主题的简化概述。

使用:hover 选择器和id 选择器可以解决这个问题:

#regForm button:hover{
    background-color:#FFC;
}

见:http://jsfiddle.net/32MvE/

【讨论】:

    【解决方案2】:

    您必须使用建议的 Scartag 类或使用属性选择器:

    input[type="button"]:hover {background-color:#FFC;}
    

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 2018-05-15
      • 1970-01-01
      • 2013-06-26
      • 2019-12-06
      • 2018-05-30
      • 2017-04-12
      • 2014-09-09
      • 2015-10-29
      相关资源
      最近更新 更多