gpt4 book ai didi

html - CSS 为什么悬停只改变背景颜色而不改变文本颜色?

转载 作者:太空宇宙 更新时间:2023-11-03 22:32:46 25 4
gpt4 key购买 nike

我正在创建一个计算器程序,我正在努力做到当用户将鼠标悬停在每个按钮上时,背景颜色和文本颜色将会改变。但是,只有背景颜色在变化,而文本颜色没有变化。我的代码做错了什么?

HTML代码

  <html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<link rel="stylesheet" type="text/css" href="calculator.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<div class="container">
<div id="calc" class="row">
<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

</div>
</div>


<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

CSS代码

#calc{
text-align: center;
border: 2px solid #909080;
background: #c7c7c7;
}

.b1{
text-align: center;
width: 60px;
height: 60px;
color: #370000;
}
.b1:hover{
color: red;
background: #7a7a7a;

}
#buttons{
margin-left: 35%;
}

最佳答案

你的风格必须与 bootstrap 风格重叠,所以:

变化:

.b1:hover {

收件人:

.btn.b1:hover {

 #calc {
text-align: center;
border: 2px solid #909080;
background: #c7c7c7;
}

.b1 {
text-align: center;
width: 60px;
height: 60px;
color: #370000;
}

.btn.b1:hover{
color: red;
background: #7a7a7a;
}

#buttons{
margin-left: 35%;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container">
<div id="calc" class="row">
<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

<div>
<button class="btn b1">7</button>
<button class="btn b1">8</button>
<button class="btn b1">9</button>
</div>

</div>
</div>

关于html - CSS 为什么悬停只改变背景颜色而不改变文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47852664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com