[英]Make <ul> list items fill div completely
I have a unordered list, which is inside a div
element. 我有一个无序列表,它在
div
元素内。 The goal is to make list elements fill the <div>
from one side to the other perfectly. 目的是使列表元素从一侧到另一侧完全填充
<div>
。
Right now the left side is positioned just as I need, but I need the right side to look the same way. 现在,左侧的位置正好与我所需的位置相同,但我需要右侧的外观相同。 Hopefully you get the idea of what I mean.
希望你明白我的意思。
HTML code: HTML代码:
<div id="currency">
<ul>
<li>Currency £</li>
<li>Sign in</li>
<li>My Account</li>
<li>My Gifts</li>
<li>My Basket</li>
</ul>
</div>
CSS code CSS代码
#currency{
height: 11px;
width: 360px;
background-color: green;
float: right;
margin-top: 11px;
margin-right: 11px;
line-height: 11px;
font-size: 11px;
text-align: justify;
}
#currency ul{
list-style-type: none;
margin: 0;
padding: 0;
display: table;
table-layout: fixed;
width: 100%;
}
#currency ul li{
display: table-cell;
}
Try the flexbox model since it's meant for situations like this: 尝试使用flexbox模型,因为它适用于以下情况:
The flex CSS property is a shorthand property specifying the ability of a flex item to alter its dimensions to fill available space.
flex CSS属性是一种简写属性,用于指定flex项目更改其尺寸以填充可用空间的能力。 Flex items can be stretched to use available space proportional to their flex grow factor or their flex shrink factor to prevent overflow.
可以拉伸弹性项目以使用与其弹性增长因子或弹性收缩因子成比例的可用空间,以防止溢出。
#currency {
width: 500px;
background-color: green;
float: right;
margin-top: 11px;
margin-right: 11px;
line-height: 11px;
font-size: 14px;
text-align: justify;
padding:10px;
vertical-align:middle;
}
#currency ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
justify-content:center;
width: 100%;
}
#currency ul li {
flex-grow:2;
text-align:center;
margin:3px;
background:#fc0;
height:20px;
padding:5px;
}
All colors, paddings and margins were added in order to show how it works since your tiny example is very difficult to see 添加了所有颜色,内边距和边距以显示其工作原理,因为您的小示例很难看清
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.