gpt4 book ai didi

javascript - 单击时如何使按钮改变颜色(html、CSS、JavaScript)

转载 作者:行者123 更新时间:2023-12-05 09:06:35 26 4
gpt4 key购买 nike

我设置了 3 个按钮,想知道如何让它们在单击时改变颜色。"is"应该是绿色的“否”应该是红色的'也许'也应该是红色的。

<!DOCTYPE html>

<html lang="en">
<head>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap"
rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<title>Trivia!</title>

<script></script>

</head>
<body>

<div class="jumbotron">
<h1>Trivia!</h1>
</div>

<div class="container">

<div class="section">
<h2>Part 1: Multiple Choice</h2>
<hr>

<h3>Do you love me?
<h3>

<button id="q1button">Yes</button>
<button id="q2button">No</button>
<button id="q3button">Maybe</button>

</div>

</div>
</body>
</html>

最佳答案

你是这个意思吗?

button:focus {
outline: none;
border: 1px solid black;
}
#q1button:focus {
background-color: green;
color: pink;
}
#q2button:focus {
background-color: red;
color: white;
}
#q3button:focus {
background-color: yellow;
color: black;
}
    <body>

<div class="jumbotron">
<h1>Trivia!</h1>
</div>

<div class="container">

<div class="section">
<h2>Part 1: Multiple Choice</h2>
<hr>

<h3>Do you love me?<h3>

<button id="q1button">Yes</button>
<button id="q2button">No</button>
<button id="q3button">Maybe</button>

</div>

</div>
</body>

关于javascript - 单击时如何使按钮改变颜色(html、CSS、JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65794930/

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