我有一个要迭代的对象数组。每个对象都显示在其自己的div中。在这个特定的列表中,只有三个对象,因此我可以将它们与grid-row一起手动放置在css-grid中,但是对于另一个页面,我可能需要数百个对象。
当前,这三个类在彼此之上而不是在彼此之下呈现。
<div class="sidebar-last-three" v-for="patient in this.lastThree">
<div class="patient-entry">
<span class="patient-name">{{patient.value}}</span>
<span class="patient-date">{{patient.key}}</span>
<span class="dots">...</span>
<span class="line"></span>
</div>
</div>
这是我使用的CSS。
.sidebar-last-three{
display: grid;
grid-row: 7/30;
grid-column: 1/11;
grid-template-rows: repeat(30, 1fr);
grid-template-columns: repeat(5, 1fr);
}
.patient-entry{
display: grid;
grid-column: 1/6;
grid-row: auto;
grid-template-columns: repeat(15, 1fr);
grid-template-rows: repeat(15, 1fr);
}
我想这与使用v-for创建类有关,因为通常使用css-grid,子div会自动进入行和列。预先感谢!
答案 0 :(得分:0)
希望这对您有所帮助。
<style>
.sidebar-last-three{
display: grid;
}
.patient-entry{
display: grid;
grid-column: auto;
grid-row: auto;
}
</style>
<div class="sidebar-last-three" v-for="patient in this.lastThree">
<div class="patient-entry">
<span class="patient-name">one on top of the one</span>
<span class="patient-date">MM/DD/YY</span>
<span class="dots">...</span>
<span class="line"></span>
</div>
<div class="patient-entry">
<span class="patient-name">one on top of the two</span>
<span class="patient-date">MM/DD/YY</span>
<span class="dots">...</span>
<span class="line"></span>
</div>
<div class="patient-entry">
<span class="patient-name">one on top of the three</span>
<span class="patient-date">MM/DD/YY</span>
<span class="dots">...</span>
<span class="line"></span>
</div>
</div>
答案 1 :(得分:0)
您需要的样式:
.sidebar {
display: grid;
position: fixed;
grid-template-columns: repeat(10, 1 fr);
grid-template-rows: repeat(10, 1 fr);
grid-column: 1;
width: 16.8vw;
height: 100%;
box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.3);
background: #26292c;
z-index: 1; /* Stay on top */
top: 0; /* Stay at the top */
left: 0;
}
.patient-name{
font-size: 16px;
color: #ffffff;
grid-column: 3/15;
grid-row: 1/2;
}
.patient-date{
font-size: 14px;
color: #98acc1;
grid-column: 3/15;
grid-row: 2/3;
}
.line{
background-color: #424a51;
width: 100%;
height: 1px;
grid-column: 1/16;
grid-row: 5;
}
.dots{
justify-self: center;
font-size: 16px;
align-self: center;
grid-column: 14/15;
grid-row: 1/2;
color: #ffffff;
}
.sidebar-last-three{
display: grid;
}
.patient-entry{
display: grid;
grid-column: auto;
grid-row: auto;
}
我已将您的示例移至Codepen。
尝试一下是否适合您。 Here is working example: