简体   繁体   English

项目之间的空白

[英]Gap whitespace between items

I have setup a grid system and they are almost behaving as expected. 我已经设置了网格系统,并且它们的行为几乎与预期的一样。

The problem is there is a big gab between the columns 问题是列之间有很大的缺口

在此处输入图片说明

I tried setting the grid-column-gap but it seems unresponsive. 我尝试设置网格-列间隙,但似乎无响应。 Note that im using scss, though i tried changing it back to css but that gave the same result. 请注意,即时通讯使用的是scss,尽管我尝试将其更改回css,但结果却相同。

 .container { display: grid; grid-template-columns: repeat(3, 1fr); grid-column-gap: 1rem; grid-gap: 1rem; justify-items: center; .language { width: 360px; height: 150px; border: 1px solid rgb(214, 214, 214); background: white; padding: 1rem; text-align: left; border-radius: 10px; cursor: pointer; color: black; box-shadow: 2px 1px 1px 1px rgb(228, 228, 228); } p { color: red; } } 
 <template> <div class="container"> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> <div class="language"> <h3>LanguageContainer</h3> <p>Description</p> </div> </div> </template> 

As commented by Niet the dark Absol. 正如尼特所说,黑暗的Absol。

The whole container is 100% width by default, and so the columns each take a third of the full width available. 默认情况下,整个容器的宽度为100%,因此每个列占用可用总宽度的三分之一。 However, the items within have a fixed width, so you have a large gap. 但是,其中的项目具有固定的宽度,因此间隙很大。 – Niet the Dark Absol 54 mins ago – 54分钟前

Simply by putting a width to my container fixed it. 只需在我的容器中放一个宽度即可将其固定。

.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-column-gap: 1rem;
grid-gap: 1rem;
width: 70%;
justify-items: center;

.language {
    width: 360px;
    height: 150px;
    border: 1px solid rgb(214, 214, 214);
    background: white;
    padding: 1rem;
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
    color: black;
    box-shadow: 2px 1px 1px 1px rgb(228, 228, 228);
}

p {
    color: red;

}

Try this: 尝试这个:

grid-template-columns: repeat(3, 0fr);

Now you can adjust the gap with this: 现在您可以使用以下方法调整差距:

grid-gap: 10px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM