3 回答

TA贡献2019条经验 获得超9个赞
你的问题不在于保证金本身。这是滚动条,只标注元素的可见内容。
要解决这个问题,一种方法是创建一个占用边距的可见元素。
此解决方案在最后一个子节点上使用伪处理。
ul {
list-style-type: none;
padding: 0;
margin: 0;
display: flex;
height: 300px;
overflow: auto;
width: 600px;
background: orange;
}
ul li {
background: blue;
color: #fff;
padding: 90px;
margin: 0 30px;
white-space: nowrap;
flex-basis: auto;
position: relative;
}
li:last-child:after {
content: "";
width: 30px;
height: 1px;
position: absolute;
left: 100%;
top: 0px;
}
<div class"container">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>

TA贡献1858条经验 获得超8个赞
你可以width和overflow在div容器,并设置display: inline-flex而不是flex在ul,这样就可以根据内部的项目来计算FLEX框的大小,并且所有填充和页边距都将适用,不会出现任何问题。
.container {
width: 600px;
overflow: auto;
}
.container ul {
list-style: none;
padding: 0;
margin: 0;
display: inline-flex;
background: orange;
}
.container li {
padding: 60px;
margin: 0 30px;
white-space: nowrap;
background: blue;
color: #fff;
}
<div class="container">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
- 3 回答
- 0 关注
- 515 浏览
相关问题推荐
添加回答
举报