修改:
所以我看到了指向的重复链接,在我看来,这个问题是为了解决你给出固定大小(固定宽度或固定高度)的问题。
原始问题的解决方案更多的是使用hacky方法修复容器。我决定采用不同的方法来修复它,同时修复我在这个问题中提出的问题。
在CSS中,当使用display: grid
和fixed height
并启用overflow: auto
时,您可能会获得此类布局,如下所示:
.scroll {
overflow: auto;
background-color: #bbddee;
}
.container {
padding: 10px;
display: grid;
grid-template-columns: 1fr;
grid-row-gap: 10px;
height: 420px;
}
.itemContainer {
border: 1px solid #efefef;
padding: 10px 20px;
background-color: #fff;
}
.itemTitle {
text-align:center;
margin: 0 auto;
}
.itemLink {
text-align: center;
margin: 0 auto;
}

<div id="retailerContent" class="tab-pane fade in active show">
<div class="scroll">
<div id="retailerOffersContainer" class="container">
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
</div>
</div>
</div>
&#13;
当发生这种情况时,存在滚动列表最底部没有填充/边距的问题。如何修改HTML和CSS,因此底部填充/边距将显示在可滚动的CSS网格布局中?
答案 0 :(得分:0)
这是我使用CSS网格时的解决方案:
/* Fix scrollbar removing padding-bottom */
@supports (-moz-appearance:none) {
.container::after {
content: "";
height: 1px;
margin: calc(var(--padding) - var(--gap));
}
}
答案 1 :(得分:-1)
这是一个解决方案(可能是其中之一),展示了如何使用div
解决固定高度display: grid
中缺少底部填充/边距的问题:
.container {
padding: 10px;
display: grid;
grid-row-gap: 10px;
grid-template-columns: 1fr;
width: 100%;
}
.itemContainer {
border: 1px solid #efefef;
background-color: #fff;
max-height: 100%;
padding: 10px 20px;
height: 100%;
}
.itemTitle {
text-align: center;
margin: 0 auto;
line-height: 20px;
}
.itemLink {
text-align: center;
margin: 0 auto;
line-height: 20px;
}
&#13;
<div id="retailerContent" class="tab-pane fade in active show">
<div style="height: 420px;background-color: #bbddee;">
<div id="retailerOffersContainer" class="container">
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
<div class="itemContainer">
<div class="itemTitle">15% Off Room Essentials Cubes & Bins</div>
<div class="itemLink"><a>Get Offer ></a></div>
</div>
</div>
</div>
</div>
&#13;
这里的主要区别是:
这将拉伸网格容器,而网格元素内容不会溢出网格容器。