gpt4 book ai didi

html - 多行内联列表取决于屏幕大小

转载 作者:太空宇宙 更新时间:2023-11-03 22:59:20 25 4
gpt4 key购买 nike

我有一个内联列表,当屏幕变得太小无法容纳文本时,我希望它被分成两行(我可以定义媒体查询来这样做,因为内容总是相同的大小)。知道如何让这样的事情发生吗?

这是我目前拥有的,但在调整大小时它会自行缩小:

.tabs {
margin: 0;
padding: 0;
list-style: none;
display: table;
table-layout: fixed;
width: 100%;
text-align: center;
}
.tabs__item {
display: table-cell;
border: 1px solid red;
border-left-width: 0;
}
.tabs__item:first-child {
border-left: 1px solid red;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.tabs__item:last-child {
border-right: 1px solid red;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
<ul class="tabs">
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
</ul>

提前致谢。

最佳答案

希望我有所帮助。这段代码应该可以解决问题。

.tabs, .tabs2 {
float: left;
margin: 0;
padding: 0;
list-style: none;
display: table;
table-layout: fixed;
width: 50%;
text-align: center;
}

.tabs__item, .tabs__item2 {
display: table-cell;
border: 1px solid red;
border-left-width: 0;
}
.tabs__item:first-child {
border-left: 1px solid red;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.tabs__item2:last-child {
border-right: 1px solid red;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}

@media (max-width:768px) {
.tabs, .tabs2 {
float: left;
margin: 0;
padding: 0;
list-style: none;
display: table;
table-layout: fixed;
width: 100%;
text-align: center;
clear:both;
}
.tabs__item:first-child, .tabs__item2:first-child {
border-left: 1px solid red;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.tabs__item:last-child, .tabs__item2:last-child {
border-right: 1px solid red;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
}
<ul class="tabs">
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
<li class="tabs__item">Hello</li>
</ul>
<ul class="tabs2">
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
<li class="tabs__item2">Hello</li>
</ul>

关于html - 多行内联列表取决于屏幕大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37122504/

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