Hiding an element with CSS Grid [closed]

我与影子孤独终老i 提交于 2019-12-11 15:07:22

问题


Using CSS Grid layout how can I safely hide a row without grid-template-rows layout properties getting passed over to the next row? I tried display: none; but the layout of the hidden element is passed over to the next element.

Here's a code example: http://plnkr.co/edit/E3kuJcDxKnrjjbdVHQbO?p=preview. What I'm trying to do is toggle the visibility of the .item2 element without effecting any other elements on the page. Thanks!


回答1:


Since you're not using grid-gap in your example, you can achieve this like so:

.grid {
    grid-template-rows: 55px 0px;
}
.item2 {
    visibility: hidden;
}

To achieve the same results but with a gap, however, you'd need to avoid using the very handy grid-gap declaration, as it will cause .item2 to leave an extra gap space when collapsed. Some margin manipulation should give you the same results though.

  • Example - no gap
  • Example - with gap



回答2:


Set the row height for each individual item instead grid-template-rows. Then 'display: none' will work.



来源:https://stackoverflow.com/questions/47067227/hiding-an-element-with-css-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!