我有一个可以添加项目的列表。但是,在列表达到一定大小(在我的情况下为5)之后,列表中的项目会向上爬行,而不是向下延伸页面并允许滚动的所需(和正常)行为。我觉得这与使用CSS网格模板有关,因为我是一个完整的新手......我已经搜索过高低,但却找不到任何提示!
我的代码如下:
为什么一旦达到一定数量的项目,此列表中的项目会爬上我的页面?
body {
margin: 0;
padding: 0;
background: #2e112d;
}
.container {
display: grid;
grid-template-columns: 20% 20% 20% 20% 20%;
grid-template-rows: 60px repeat(10, 10%);
height: 100vh;
}
.nav-bar {
grid-column: 1 / 6;
grid-row: 1 / 2;
background: #ffdbc5;
text-align: center;
}
.brand {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
display: inline-block;
padding: 1.5%;
}
.background-image {
grid-row: 2 / 9;
grid-column: 1 / -1;
overflow: hidden;
position: relative;
}
img {
position: absolute;
display: block;
height: 100%;
width: auto;
margin: 0 auto;
left: 50%;
top: 50%;
-webkit-transform: translateY(-50%) translateX(-50%);
}
.workouts {
grid-column: 2 / 5;
grid-row: 2 / -1;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: repeat(3, 1fr);
}
.new-workout {
font-size: 200%;
color: white;
background: none;
border: white 10px;
display: inline-block;
height: 30%;
width: 30%;
grid-row: 1;
margin: auto;
z-index: 1;
}
.workout-list {
display: block;
position: relative;
align-self: start;
grid-column: 1 / 2;
grid-row: 3;
z-index:1;
}
button.btn {
color: #5a5a5a;
background-color: #e8e8e8;
margin: 10px 0 10px 0;
width: 100%
}
span.delete {
display: inline-block;
float: right;
color: red;
}

<div id="app">
<div data-reactroot="" class="container">
<div class="nav-bar"></div>
<div class="brand">Fiery Leaf</div>
<div class="background-image">
<img src="/static/media/landscape-banner.67e9e794.jpg">
</div>
<div class="workouts">
<button class="new-workout">New Workout</button>
<div class="workout-list">
<div class="workout">
<button type="button" class="btn btn-default" />
</div>
<div class="workout">
<button type="button" class="btn btn-default" />
</div>
</div>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
看起来您的HTML代码已损坏:
一个button
(第二个)未关闭,另外一个div
结尾,弄乱了页面流的布局。
以下是selenium-standalone,代码正确。
我的建议:始终jsbin您的代码。
答案 1 :(得分:0)
尝试添加vertical-align:top;到你正在扩展的div。
这是一个小例子 - 如果你将vertical-align更改为bottom,它将像你在案例中描述的那样工作,我希望有所帮助:
.container {
width: 100px;
background-color: red;
display: inline-block;
margin: 0;
vertical-align: top;
}
p {
width: 90px;
display: block;
margin: 5px 0;
}
.other {
margin: 0;
background-color: blue;
width: 40px;
height: 50px;
display: inline-block;
}
&#13;
<div class="container">
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
<p>Test</p>
</div><div class="other"></div>
&#13;