CSS网格布局中的每一列之间的边界
我正在尝试在CSS中的网格布局中添加每个列之间的边界。但是,在我的包装师内部,我没有包含相同内容的div,因此当我试图设置边框并留在包装纸上,然后在我的内部divs上放置边框权利和底部,边界的高度不是相同的。我只想知道,当我做网格 - 板柱时:1fr 1fr 1fr;我如何为每个分数设置边界右翼。
这是我的代码:
<div class="sort-count-filter">
<div class="product-count">
<p>{{ collection.products_count }} products</p>
</div>
<!-- collections filter by tag -->
<div class="filter-by">
{% if collection.all_tags.size > 0 %}
<p>Filter by</p>
<ul class="tag-filters">
{% for tag in collection.all_tags %}
{% unless tag contains "_"%}
{% if current_tags contains tag %}
<li class="tag-filters__item"><p class="filters">{{ tag | link_to_remove_tag: tag }}</p></li>
{% else %}
<li class="tag-filters__item"><p class="filters">{{ tag | link_to_add_tag: tag }}</p></li>
{% endif %}
{% endunless %}
{% endfor %}
</ul>
{% endif %}
</div>
<!-- collection sort -->
<div class="sort-by">
<span>Sort by</span>
<span>
<select id="sort-by">
{% assign sort_by = collection.sort_by | default: collection.default_sort_by %}
{% for option in collection.sort_options %}
<option value="{{ option.value }}" {% if option.value == sort_by %}selected="selected"{% endif %}>
{{ option.name }}
</option>
{% endfor %}
</select>
</span>
</div>
</div>
这是CSS:
.sort-count-filter {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
margin-top: 3%;
font-family: "Open Sans";
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-left: 1px solid black;
}
.sort-count-filter > div {
border-bottom: 1px solid black;
border-right: 1px solid black;
}
I am trying to add borders between each columns in a grid layout in CSS. However, inside my wrapper div, the divs that I have don't contain the same content, so when I'm trying to set a border-top and left on my wrapper div and then a border-right and bottom on my inside divs, the borders aren't of the same height. I just want to know that when I'm doing grid-template-columns: 1fr 1fr 1fr; how can I set a border-right for each fraction.
Here's my code:
<div class="sort-count-filter">
<div class="product-count">
<p>{{ collection.products_count }} products</p>
</div>
<!-- collections filter by tag -->
<div class="filter-by">
{% if collection.all_tags.size > 0 %}
<p>Filter by</p>
<ul class="tag-filters">
{% for tag in collection.all_tags %}
{% unless tag contains "_"%}
{% if current_tags contains tag %}
<li class="tag-filters__item"><p class="filters">{{ tag | link_to_remove_tag: tag }}</p></li>
{% else %}
<li class="tag-filters__item"><p class="filters">{{ tag | link_to_add_tag: tag }}</p></li>
{% endif %}
{% endunless %}
{% endfor %}
</ul>
{% endif %}
</div>
<!-- collection sort -->
<div class="sort-by">
<span>Sort by</span>
<span>
<select id="sort-by">
{% assign sort_by = collection.sort_by | default: collection.default_sort_by %}
{% for option in collection.sort_options %}
<option value="{{ option.value }}" {% if option.value == sort_by %}selected="selected"{% endif %}>
{{ option.name }}
</option>
{% endfor %}
</select>
</span>
</div>
</div>
Here's the CSS:
.sort-count-filter {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
margin-top: 3%;
font-family: "Open Sans";
justify-content: center;
align-items: center;
border-top: 1px solid black;
border-left: 1px solid black;
}
.sort-count-filter > div {
border-bottom: 1px solid black;
border-right: 1px solid black;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您想要
Align-Items:Stretch
?此页面是格式化网格的很好参考。
Perhaps you want
align-items: stretch
?This page is a great reference for formatting grids.
我有一个类似的问题,使我进入了这篇文章。但是,我直接使用网格。这是我所做的,这可能会帮助您或访问此帖子的人有类似的问题:
我正在使用以下代码创建四个网格,但它一直在每列之间创建空间:
我只是使用以下属性来使列无用额外的空间:
希望此属性有助于解决问题。
I had a similar issue that led me into this post. However, I was using grids directly. Here's what I did that may help you or the person visiting this post with similar issue:
I was using the below code to create four grids but it kept creating space between each column:
I just used the below property to make the columns be free of extra space:
Hope this property helps with the issue.