DIV内的内容更改
我正在研究根据特定按钮更改DIV中内容的方法。
基本上我有一个:
默认情况下,“国家联赛”的内容,“国家联赛”的内容出现,因此,当我单击“ MHA Cup”时,内容将变成与“ MHA Cup”相关的游戏和“友谊”。
如何做这样的事情?
@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Raleway", sans-serif;
}
body {
background: #e5e5e5;
width: 100vw;
}
ul,
li {
list-style: none;
}
.parent {
display: flex;
flex-direction: column;
width: 60%;
margin: 75px auto;
}
.parent h1 {
font-weight: 900;
font-size: 16px;
text-transform: uppercase;
margin-bottom: 20px;
}
.parent ul {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.category {
display: flex;
flex-direction: row;
}
.category li {
margin-right: 30px;
padding-bottom: 5px;
margin-bottom: 50px;
border-bottom: 2.5px solid #01296f;
}
.category li,
.show-all li {
font-size: 12px;
text-transform: uppercase;
font-weight: 600;
}
.match {
display: flex;
justify-content: space-between;
background: white;
align-items: center;
height: 120px;
border-bottom: 1px solid #F0F0F0;
}
.match-details {
text-align: center;
}
#friendlies {
border: 2px solid red;
}
#mha-cup {
border: 2px solid purple;
}
.home-team,
.away-team {
display: flex;
align-items: center;
}
.team-badge {
background: grey;
height: 42px;
width: 42px;
border-radius: 50%;
margin: 30px;
}
.team-name {
font-weight: 700;
padding: -10px;
text-transform: uppercase;
font-size: 12px;
}
.match-type{
margin: 20px;
font-size: 12px;
font-weight: 600;
color: #999999;
letter-spacing: 1px;
}
.match-score span{
background: #01296f;
color: white;
border-radius: 5px;
padding: 7.5px 10px;
}
.match-status{
margin: 20px;
font-size: 10px;
letter-spacing: 1px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="styles.css" />
<title>Static Template</title>
</head>
<body>
<div class="parent">
<h1>Latest Matches</h1>
<ul>
<div class="category">
<li>National League</li>
<li>MHA Cup</li>
<li>Friendlies</li>
</div>
<div class="show-all">
<li>Show All</li>
</div>
</ul>
<div class="tables" id="national-league">
<div class="match">
<div class="home-team">
<div class="team-badge"></div>
<span class="team-name">La Salle</span>
</div>
<div class="match-details">
<div class="match-type">
<h4>MHA CUP - SEMIFINALS</h4>
</div>
<div class="match-score">
<span>25 - 24</span>
</div>
<div class="match-status">
FULL TIME
</div>
</div>
<div class="away-team">
<span class="team-name">HMS</span>
<div class="team-badge"></div>
</div>
</div>
<div class="match">
<div class="home-team">
<div class="team-badge"></div>
<span class="team-name">La Salle</span>
</div>
<div class="match-details">
<div class="match-type">
<h4>MHA CUP - SEMIFINALS</h4>
</div>
<div class="match-score">
<span>25 - 24</span>
</div>
<div class="match-status">
FULL TIME
</div>
</div>
<div class="away-team">
<span class="team-name">HMS</span>
<div class="team-badge"></div>
</div>
</div>
</div>
</div>
</body>
</html>
I am looking into ways of changing the content within a div based on a specific button.
Basically I have this:
By default, the contents of the "National League" will show up, so when I click on "MHA Cup", the content will change to games that are "MHA CUP" related and as well as "Friendlies".
How can something like this be done?
@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@100;200;300;400;500;600;700;800;900&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Raleway", sans-serif;
}
body {
background: #e5e5e5;
width: 100vw;
}
ul,
li {
list-style: none;
}
.parent {
display: flex;
flex-direction: column;
width: 60%;
margin: 75px auto;
}
.parent h1 {
font-weight: 900;
font-size: 16px;
text-transform: uppercase;
margin-bottom: 20px;
}
.parent ul {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.category {
display: flex;
flex-direction: row;
}
.category li {
margin-right: 30px;
padding-bottom: 5px;
margin-bottom: 50px;
border-bottom: 2.5px solid #01296f;
}
.category li,
.show-all li {
font-size: 12px;
text-transform: uppercase;
font-weight: 600;
}
.match {
display: flex;
justify-content: space-between;
background: white;
align-items: center;
height: 120px;
border-bottom: 1px solid #F0F0F0;
}
.match-details {
text-align: center;
}
#friendlies {
border: 2px solid red;
}
#mha-cup {
border: 2px solid purple;
}
.home-team,
.away-team {
display: flex;
align-items: center;
}
.team-badge {
background: grey;
height: 42px;
width: 42px;
border-radius: 50%;
margin: 30px;
}
.team-name {
font-weight: 700;
padding: -10px;
text-transform: uppercase;
font-size: 12px;
}
.match-type{
margin: 20px;
font-size: 12px;
font-weight: 600;
color: #999999;
letter-spacing: 1px;
}
.match-score span{
background: #01296f;
color: white;
border-radius: 5px;
padding: 7.5px 10px;
}
.match-status{
margin: 20px;
font-size: 10px;
letter-spacing: 1px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="styles.css" />
<title>Static Template</title>
</head>
<body>
<div class="parent">
<h1>Latest Matches</h1>
<ul>
<div class="category">
<li>National League</li>
<li>MHA Cup</li>
<li>Friendlies</li>
</div>
<div class="show-all">
<li>Show All</li>
</div>
</ul>
<div class="tables" id="national-league">
<div class="match">
<div class="home-team">
<div class="team-badge"></div>
<span class="team-name">La Salle</span>
</div>
<div class="match-details">
<div class="match-type">
<h4>MHA CUP - SEMIFINALS</h4>
</div>
<div class="match-score">
<span>25 - 24</span>
</div>
<div class="match-status">
FULL TIME
</div>
</div>
<div class="away-team">
<span class="team-name">HMS</span>
<div class="team-badge"></div>
</div>
</div>
<div class="match">
<div class="home-team">
<div class="team-badge"></div>
<span class="team-name">La Salle</span>
</div>
<div class="match-details">
<div class="match-type">
<h4>MHA CUP - SEMIFINALS</h4>
</div>
<div class="match-score">
<span>25 - 24</span>
</div>
<div class="match-status">
FULL TIME
</div>
</div>
<div class="away-team">
<span class="team-name">HMS</span>
<div class="team-badge"></div>
</div>
</div>
</div>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是最有效的,而是一种简单的方法,而无需添加引导程序/jQuery是使用JavaScript添加/删除“ Display:none;”;您要显示和隐藏并设置按钮作为触发器在两者之间交替的触发器的样式。
Not the most efficient but an easy way to do this without having to add Bootstrap/JQuery is to use JavaScript to add/remove "display: none;" style to the content you want to show and hide and set the button as the trigger to alternate between the two.
实际上,您只需将您想用JavaScript隐藏的每个Div提供一个but显示实际上很容易。
这是你的方式
you can just give put display none to each div you want to hide with javascript is quite easy actually.
here is how you do it