Same height of elements in different lists in 2 column CSS(2列css中不同列表中元素的高度相同)
本文介绍了2列css中不同列表中元素的高度相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我。我在这里和其他地方搜索与我的案例相同的例子,但没有找到我需要的东西。 我有2列不同的动态列表。 在一栏中,5列列出了元素(标题),5列出了其他元素(每个元素的描述)。它们可能或多或少是5件以上的物品。但列中的数量列表项总是相同的。 我需要一列中每个元素的高度与另一列中的高度相对应。 你能告诉我怎么做吗,或者显示手册的链接来解决我的问题? 感谢您的帮助! 数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
.columnlist {
display: grid;
grid-template-columns: 0.5fr 1.5fr;
grid-template-areas: "sortable1 sortable2";
padding: 20px;
}
.columnlist ul {}
#sortable1 {
grid-area: sortable1;
}
#sortable1 li {
padding: 10px;
margin: 5px 0;
border: solid 1px black;
}
#sortable2 {
grid-area: sortable2;
}
#sortable2 li {
background: rgb(255, 250, 205);
padding: 10px;
margin: 5px 0;
border: solid 1px black;
}
ul {
list-style: none;
}
ol,
ul {
margin: 0;
}
<div class="columnlist">
<ul id="sortable1">
<li>title 1</li>
<li>title 2</li>
<li>title 3</li>
<li>title 4</li>
<li>title 5</li>
</ul>
<ul id="sortable2">
<li>1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. </li>
<li>4 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>5 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum.</li>
</ul>
</div>
Code on codepen
推荐答案
.columnlist {
display: grid;
grid-template-columns: 0.5fr 1.5fr;
grid-template-areas: "sortable1 sortable2";
padding: 20px;
}
.columnlist ul {}
#sortable1 {
grid-area: sortable1;
display: grid;
}
#sortable1 li {
padding: 10px;
margin: 5px 0;
border: solid 1px black;
}
#sortable2 {
grid-area: sortable2;
display: grid;
grid-auto-rows: 1fr;
}
#sortable2 li {
background: rgb(255, 250, 205);
padding: 10px;
margin: 5px 0;
border: solid 1px black;
}
ul {
list-style: none;
}
ol,
ul {
margin: 0;
}
<div class="columnlist">
<ul id="sortable1">
<li>title 1</li>
<li>title 2</li>
<li>title 3</li>
<li>title 4</li>
<li>title 5</li>
</ul>
<ul id="sortable2">
<li>1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. </li>
<li>4 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus. </li>
<li>5 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sit amet vestibulum risus, vitae condimentum mi. Vivamus eu finibus dui. Fusce mollis lorem vel dui imperdiet, nec viverra lectus tempus. Morbi laoreet urna non urna sodales, non
feugiat diam rutrum.</li>
</ul>
</div>
这篇关于2列css中不同列表中元素的高度相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:2列css中不同列表中元素的高度相同
基础教程推荐
猜你喜欢
- 在for循环中使用setTimeout 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 响应更改 div 大小保持纵横比 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 动态更新多个选择框 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01