gpt4 book ai didi

html - CSS:如何获得高度统一的可滚动标签列表

转载 作者:行者123 更新时间:2023-11-28 04:19:54 25 4
gpt4 key购买 nike

我正在尝试获取显示在两列中的可滚动标签列表。

  1. 列的大小需要根据包含的 div 进行调整。
  2. 列表应从左到右,然后从上到下排列。根据其他 SO 帖子,使其 display: inline 应该可以工作,但似乎并非如此。
  3. 单词也需要换行,出于某种原因,在我下面的尝试中,这不起作用。在破折号之后,它将标签的其余部分推到下一行,而不是继续然后换行。
  4. 棘手的部分是,每个标签的高度需要统一,并且它们应该等于最高标签的高度。正如您在演示中所见,一个标签标题可能很长,因此该标签的高度应决定所有其他标签的高度。我什至不知道如何开始在 CSS 中执行此操作。

我对此进行了适度的尝试:http://jsfiddle.net/pdExf/860/ ,但它缺少我上面需要的要求。

HTML:

<div>
<ul>
<li>
<label>
<input type="checkbox"/>
<span> 1-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 2-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 3-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 4-very_short_word </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 5-medium_length_word </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 6-still_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 7-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
</ul>
</div>

CSS:

span {
margin-left: 14px;
flex: 1 1 auto;
overflow: 'hidden',
word-wrap: break-word;
}

label {
box-sizing: border-box;
background: white;
color: black;
padding: 10px;
margin: 10px 10px 20px 10px;
display: flex;
border: 1px solid black;
}

ul {
display: flex,
flex: 1 1 auto;
flex-wrap: wrap;
margin: 10px 0px 0px 10px;
column-count: 2;
column-gap: 20px;
}

div {
height: 130px;
background-color: lightblue;
overflow: scroll;
}

li {
display: inline; // want labels to display left-to-right
}

还应该添加什么才能使这项工作正常进行?

最佳答案

再添加一个类使用word-wrap: break-word; & word-break: break-all; & 空白:正常;

Revised Fiddle

label span { 
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -webkit-pre-wrap; /*Chrome & Safari */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: pre-wrap; /* css-3 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
word-break: break-all;
white-space: normal;
}

span {
margin-left: 14px;
flex: 1 1 auto;
overflow: 'hidden', word-wrap: break-word;
}

label span {
white-space: -moz-pre-wrap !important;
/* Mozilla, since 1999 */
white-space: -webkit-pre-wrap;
/*Chrome & Safari */
white-space: -pre-wrap;
/* Opera 4-6 */
white-space: -o-pre-wrap;
/* Opera 7 */
white-space: pre-wrap;
/* css-3 */
word-wrap: break-word;
/* Internet Explorer 5.5+ */
word-break: break-all;
white-space: normal;
}

label {
box-sizing: border-box;
background: white;
color: black;
padding: 10px;
margin: 10px 10px 20px 10px;
display: flex;
border: 1px solid black;
}

ul {
display: flex, flex: 1 1 auto;
flex-wrap: wrap;
margin: 10px 0px 0px 10px;
column-count: 2;
column-gap: 20px;
}

div {
height: 130px;
background-color: lightblue;
overflow: scroll;
}

li {
display: inline; // want labels to display left-to-right
}
<div>
<ul>
<li>
<label>
<input type="checkbox"/>
<span> 1-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 2-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 3-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 4-very_short_word </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 5-medium_length_word </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 6-still_no_spaces </span>
</label>
</li>
<li>
<label>
<input type="checkbox"/>
<span> 7-thisisaverrrrrrrrrrrrryyyyyy_long_word_with_no_spaces </span>
</label>
</li>
</ul>
</div>

关于html - CSS:如何获得高度统一的可滚动标签列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42264856/

25 4 0