我正在学习CSS Grid并且非常着迷它。特别是,我使用template-areas
方法来定义结构。这是我编写的代码示例,用于定义具有两个侧边栏,主要内容区域和文章页脚的基本文章布局:
HTML:
<div class="article-wrapper">
<div class="sidebar-left">
Left Sidebar Content
</div>
<div class="article-content">
Main Article Content
<div class="article-overflow">
Overflow Content
</div>
</div>
<div class="sidebar-right">
Right Sidebar Content
</div>
<div class="article-footer">
Article Footer Content
</div>
</div>
CSS:
.article-wrapper{
display:grid;
grid-template-areas:
"h h h h h h h h h h h h"
"l l c c c c c c c c r r"
"l l f f f f f f f f r r";
}
.article-wrapper > .article-sidebar-left{
grid-area: l;
}
.article-wrapper > .article-sidebar-right{
grid-area: r;
}
.article-wrapper > .article-content{
grid-area: c;
}
.article-wrapper > .article-footer{
grid-area: f;
}
我的问题;有没有办法,使用网格区域的这种方法,我可以制作article-overflow
元素,它完全在c
grid-template-area
范围内,以扩展到l
和{ {1}}区域?
基本上,我希望r
元素的宽度是这样的:
article-overflow
而现在是l x x x x x x x x x x x r
换句话说,我试图将其一个网格单元扩展到当前侧边栏使用的每个区域。
答案 0 :(得分:0)
...有没有办法,使用网格区域的这种方法,我可以创建
.article-overflow
元素,它完全在c
网格模板区域内扩展到{ {1}}和l
区域?
没有
r
元素甚至不是网格项,因此它不识别网格属性 1 。
在未来版本的Grid Layout中,.article-overflow
功能 2 可能允许网格项的子项尊重主容器的行,实施。但那是猜测。即便如此,也不能保证您想要的网格区域可用subgrid
。它可能仅适用于基于行的放置 3 。
注意:
1 Grid properties not working on elements inside grid container
2 Positioning content of grid items in primary container (subgrid feature)