【发布时间】:2017-06-13 03:48:29
【问题描述】:
我正在制作一个交互式列表。我遇到的问题是,当项目数超过窗口高度时,列表应该可以向上/向下滚动以查看内容。
对于我的列表,我使用了一个弹性框,以便我可以根据需要拥有多列项目。此外,窗口的高度和宽度被缩放以填充屏幕。 (不过,我在此测试代码中设置了固定尺寸。)
HTML
<div class="container">
<div class="list">
<div class="input">
<input type="text" placeholder="Add new item..."></input>
</div>
<div class="list-container">
<ul>
<li>Entry 1</li>
<li>Entry 2</li>
<li>Entry 3</li>
<li>Entry 4</li>
<li>Entry 5</li>
<li>Entry 6</li>
</ul>
</div>
</div>
</div>
CSS (.scss)
.container {
margin: auto;
height: 300px; //**NOTE: This is an arbitrary value for showcase. It really would just scale to the screen size.
width: 780px;
background-color: #2c3e50;
border-radius: 10px;
padding: 15px;
font-family: sans-serif;
}
.list {
.input {
border-bottom: 1px solid white;
input {
color: white;
background: transparent;
border: none;
width: 100%;
font-size: 28px;
padding-bottom: 10px;
&:focus {
outline: 0;
}
}
input::-webkit-input-placeholder {
color: white;
opacity: 0.6;
font-style: italic;
}
}
.list-container {
overflow-y: scroll; //**Doesn't work
ul {
margin: 0;
margin-top: 10px;
padding: 0;
display: flex;
flex-direction: column;
flex-wrap: wrap;
li {
flex: 1 0 100%;
background: #34495e;
border-radius: 5px;
box-shadow: 0px 2px 4px black;
color: white;
list-style: none;
padding: 10px;
margin: 10px 0px;
white-space: nowrap;
font-size: 22px;
}
}
}
}
【问题讨论】: