我有1300px宽的标签的内容。我不能理解如何调整上面的标签块,使它们在一行中(彼此之间有轻微的缩进,1px),100%宽,1300px以内。我提供了我的标签代码,以及图片,如果有必要的话。非常感谢你的帮助!
.rate_selector {
display: flex;
justify-content: center;
width: 100%;
max-width: 100%;
}
.rate_selector_content {
display: flex;
justify-content: space-between;
width: 1300px;
max-width: calc(100% - 100px);
margin: 50px 0 50px 0;
}
.tabs {
font-size: 0;
width: 100%;
}
.tabs>input[type="radio"] {
display: none;
}
.tabs>div {
display: none;
border: 1px solid #e0e0e0;
background-color: #FAFAFA;
font-size: 16px;
}
#tab-btn-1:checked~#content-1,
#tab-btn-2:checked~#content-2,
#tab-btn-3:checked~#content-3,
#tab-btn-4:checked~#content-4 {
display: flex;
}
.tabs>label {
display: inline-block;
user-select: none;
background-color: #FFFFFF;
border: 1px solid #e0e0e0;
font-size: 16px;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out;
cursor: pointer;
position: relative;
height: 70px;
top: 1px;
}
.tabs>label:not(:first-of-type) {
border-left: none;
}
.tabs>input[type="radio"]:checked+label {
background-color: #FAFAFA;
border-bottom: 1px solid #FAFAFA;
}<div class="rate_selector">
<div class="rate_selector_content">
<div class="tabs">
<input type="radio" name="tab-btn" id="tab-btn-1" value="" checked>
<label for="tab-btn-1">Text1</label>
<input type="radio" name="tab-btn" id="tab-btn-2" value="">
<label for="tab-btn-2">Text2</label>
<input type="radio" name="tab-btn" id="tab-btn-3" value="">
<label for="tab-btn-3">Text3</label>
<input type="radio" name="tab-btn" id="tab-btn-4" value="">
<label for="tab-btn-4">Text4</label>
<div id="content-1">
Text content 1
</div>
<div id="content-2">
Text content 2
</div>
<div id="content-3">
Text content 3
</div>
<div id="content-4">
Text content 4
</div>
</div>
</div>
</div>
]1
发布于 2020-05-28 17:36:14
您可以通过使用flexbox并对其进行包装来实现。
.tabs {
display: flex;
flex-wrap: wrap;
}现在,所有内容都在一行中(标签和内容)。因此,您需要通过将宽度设置为100%来扩展内容区域。
#tab-btn-1:checked~#content-1,
#tab-btn-2:checked~#content-2,
#tab-btn-3:checked~#content-3,
#tab-btn-4:checked~#content-4 {
width: 100%;
}因此,我们在一开始就实现了我们的目标。最后要做的就是将flex-grow添加到标签中,以填充所有内容。
.tabs>label {
flex-grow: 1;
}工作codepen
https://stackoverflow.com/questions/62061111
复制相似问题