html网页制作篮球比赛记分器
时间: 2023-12-09 12:35:14 浏览: 40
以下是一个简单的HTML篮球比赛计分器的示例代码,其中使用了CSS样式来设置布局和样式:
```html
<!DOCTYPE html>
<html>
<head>
<title>Basketball Scoreboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
height: 100vh;
}
.team {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 20px;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.team h2 {
margin: 0;
font-size: 36px;
color: #333;
}
.team p {
margin: 0;
font-size: 24px;
color: #666;
}
.score {
display: flex;
flex-direction: row;
align-items: center;
margin-top: 20px;
}
.score button {
background-color: #333;
color: #fff;
border: none;
font-size: 36px;
padding: 10px 20px;
border-radius: 5px;
margin: 0 10px;
cursor: pointer;
}
.score button:hover {
background-color: #666;
}
.score button:active {
transform: translateY(2px);
}
.score span {
font-size: 48px;
font-weight: bold;
color: #333;
margin: 0 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="team">
<h2>Team A</h2>
<p>Player 1, Player 2, Player 3</p>
<div class="score">
<button onclick="incrementScore('teamA', 1)">+1</button>
<button onclick="incrementScore('teamA', 2)">+2</button>
<button onclick="incrementScore('teamA', 3)">+3</button>
<span id="teamAScore">0</span>
</div>
</div>
<div class="team">
<h2>Team B</h2>
<p>Player 4, Player 5, Player 6</p>
<div class="score">
<button onclick="incrementScore('teamB', 1)">+1</button>
<button onclick="incrementScore('teamB', 2)">+2</button>
<button onclick="incrementScore('teamB', 3)">+3</button>
<span id="teamBScore">0</span>
</div>
</div>
</div>
<script>
var teamAScore = 0;
var teamBScore = 0;
function incrementScore(team, points) {
if (team === 'teamA') {
teamAScore += points;
document.getElementById('teamAScore').innerHTML = teamAScore;
} else if (team === 'teamB') {
teamBScore += points;
document.getElementById('teamBScore').innerHTML = teamBScore;
}
}
</script>
</body>
</html>
```
该示例代码使用了flex布局来实现两个球队的布局,并使用CSS样式来设置球队名称、得分和按钮的样式。JavaScript代码用于处理得分逻辑,并将得分更新到HTML页面上。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)