【发布时间】:2017-08-14 11:04:19
【问题描述】:
我用 HTML 和 CSS 编写了一些代码。输出显示在屏幕截图中。在“TABS”中有一个大小限制,而每个选项卡中的部分的大小可以变化。 (以下代码中TABS的高度为200像素)
如何解决这个问题? (请不要建议任何 Java Script 代码。)
正确的形式:
如果我将其设置为自动,它将显示在图 2 中。 enter image description here
.items {
width: 100%;
height: auto;
float: right;
}
.tab-frame input {
display: none;
width: 100%;
height: auto;
float: right;
}
.tab-frame label {
display: block;
float: right;
cursor: pointer;
text-align: center;
width: 110px;
height: 80px;
margin: 0 5px;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
.tab-frame label img {
display: block;
margin: 20px auto 10px auto;
}
.tab-frame label span:nth-child(2) {
opacity: 0;
color: white;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
.tab-frame label:hover span:nth-child(2) {
opacity: 1;
display: block;
}
.tab-frame label:hover {
height: 100px;
}
#tab1 + label {
margin-right: 35px;
}
.tab-frame input:checked + label {
color: white;
cursor: default;
height: 110px;
}
.tab-frame input:checked + label span:nth-child(2) {
opacity: 1;
}
.tabs {
width: 100%;
height: 200px;
float: right;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow: hidden;
position: relative;
}
.tab {
/*display: none;*/
clear: left;
overflow: hidden;
float: right;
width: 100%;
height: auto;
position: relative;
}
.tab-frame input:nth-of-type(1) ~ .tabs .tab:nth-child(1),
.tab-frame input:nth-of-type(2) ~ .tabs .tab:nth-child(2) {
position: absolute;
top: -100%;
transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
-webkit-transition: all 1s ease;
}
.tab-frame input:nth-of-type(1):checked ~ .tabs .tab:nth-child(1),
.tab-frame input:nth-of-type(2):checked ~ .tabs .tab:nth-child(2) {
top: 0%;
}
#tab1 + label {
background: #479cd7;
background: -moz-linear-gradient(top, #479cd7 0%, #2c7eb8 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#479cd7), color-stop(100%,#2c7eb8));
background: -webkit-linear-gradient(top, #479cd7 0%,#2c7eb8 100%);
background: -o-linear-gradient(top, #479cd7 0%,#2c7eb8 100%);
background: -ms-linear-gradient(top, #479cd7 0%,#2c7eb8 100%);
background: linear-gradient(to bottom, #479cd7 0%,#2c7eb8 100%);
}
#tab2 + label {
background: #a9d747;
background: -moz-linear-gradient(top, #a9d747 0%, #88b82c 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a9d747), color-stop(100%,#88b82c));
background: -webkit-linear-gradient(top, #a9d747 0%,#88b82c 100%);
background: -o-linear-gradient(top, #a9d747 0%,#88b82c 100%);
background: -ms-linear-gradient(top, #a9d747 0%,#88b82c 100%);
background: linear-gradient(to bottom, #a9d747 0%,#88b82c 100%);
}
.header {
width: 100%;
height: 45px;
float: right;
margin-bottom: 40px;
}
.header1 {
background-color: #2c7eb8;
}
.header2 {
background-color: #88b82c;
}
.header h2 {
float: left;
margin: 0;
line-height: 45px;
padding: 0 35px 0 35px;
color: white;
font-weight: bold;
font-size: 18px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="items">
<div class="tab-frame">
<input type="radio" name="tab" id="tab1" checked>
<label for="tab1">
<span>
<img src="../images/home.png" />
</span>
<span>صفحه اصلی</span>
</label>
<input type="radio" name="tab" id="tab2">
<label for="tab2">
<span>
<img src="../images/download.png" />
</span>
<span>دانلود رایگان</span>
</label>
<div class="tabs">
<div class="tab">
<div class="header header1">
<h2>
Home
</h2>
</div>
<div>
text1 text1 text1 text1 text1 text1 text1 text1 text1 text1
</div>
</div>
<div class="tab">
<div class="header header2">
<h2>
Free Download
</h2>
</div>
<div>
text2 text2 text2 text2 text2 text2 text2 text2 text2 text2
</div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
وضّح شنو سؤالك بالضبط وماهو الناتج الذي تتوقعه؟
-
对不起,我不清楚你有什么问题?你想让 div 灵活地处理你的内容,或者你想固定你的 div 高度???
-
@AbdullahAlemadi 每个选项卡都有内容。此内容的高度也各不相同。 (例如,第一个选项卡内容为 200 x 500 像素,第二个选项卡内容。它们的确切数量不清楚,取决于其中的文本)。在编写的代码中,选项卡的高度为 200 像素,出现了我们正在寻找的最终正确形状(图 1),但问题是它的高度是恒定的。虽然我们需要一些不确定性
-
@Anami 灵活