gpt4 book ai didi

HTML/CSS 标签显示独特的内容

转载 作者:太空宇宙 更新时间:2023-11-04 13:45:28 25 4
gpt4 key购买 nike

对于用户点击的每个选项卡,我需要显示不同的内容。我必须坚持布局保持不变。我的 CSS 如下:

#header ul {
list-style: none;
padding:0;
margin:0;
}


#header li {
float: left;
border: 1px solid;
border-bottom-width: 0;
margin: 0 0.5em 0 0;
}

#header li a {
padding: 0 1em;
}

#content {
border: 1px solid;
clear: both;
}

h1 {
margin: 0;
padding: 0 0 1em 0;
}



#header #selected {
position: relative;
top: 1px;
background: white;
}

我的 HTML 文件如下:

<head>
<link rel="stylesheet" href="style/style-style.css">
</head>


<div id="header">

<h1><center>Tabs</center></h1>
<ul>
<li><a href="#">This</a></li>
<li id="selected"><a href="#">That</a></li>
<li><a href="#">The Other</a></li>
<li><a href="#">Banana</a></li>
</ul>

</div>

<div id="content">
<p>Ispum schmipsum.</p>
</div>

同样,我的问题是如何根据用户可能点击的选项卡(这个、那个、另一个、香蕉)显示独特的内容。

最佳答案

做这样的事情

您的 html 代码

<ul class="tabs">
<li>
<input type="radio" checked name="tabs" id="tab1">
<label for="tab1">tab 1</label>
<div id="tab-content1" class="tab-content animated fadeIn">
...
</div>
</li>
<li>
<input type="radio" name="tabs" id="tab2">
<label for="tab2">tab 2</label>
<div id="tab-content2" class="tab-content animated fadeIn">
...
</div>
</li>
<li>
<input type="radio" name="tabs" id="tab3">
<label for="tab3">tab 3</label>
<div id="tab-content3" class="tab-content animated fadeIn">
...
</div>
</li>
</ul>

你的CSS

body, html {
height: 100%;
margin: 0;
-webkit-font-smoothing: antialiased;
font-weight: 100;
background: #aadfeb;
text-align: center;
font-family: helvetica;
}

.tabs input[type=radio] {
position: absolute;
top: -9999px;
left: -9999px;
}
.tabs {
width: 650px;
float: none;
list-style: none;
position: relative;
padding: 0;
margin: 75px auto;
}
.tabs li{
float: left;
}
.tabs label {
display: block;
padding: 10px 20px;
border-radius: 2px 2px 0 0;
color: #08C;
font-size: 24px;
font-weight: normal;
font-family: 'Lily Script One', helveti;
background: rgba(255,255,255,0.2);
cursor: pointer;
position: relative;
top: 3px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.tabs label:hover {
background: rgba(255,255,255,0.5);
top: 0;
}

[id^=tab]:checked + label {
background: #08C;
color: white;
top: 0;
}

[id^=tab]:checked ~ [id^=tab-content] {
display: block;
}
.tab-content{
z-index: 2;
display: none;
text-align: left;
width: 100%;
font-size: 20px;
line-height: 140%;
padding-top: 10px;
background: #08C;
padding: 15px;
color: white;
position: absolute;
top: 53px;
left: 0;
box-sizing: border-box;
-webkit-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
animation-duration: 0.5s;
}

关于HTML/CSS 标签显示独特的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551564/

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