【问题标题】:rows overlapping in CSS Grid LayoutCSS 网格布局中重叠的行
【发布时间】:2017-04-19 11:50:36
【问题描述】:

如何防止页脚行与内容行重叠?

这就是我得到的:

body {
	display: grid;
	grid-template-rows: 3.7rem auto auto;
	grid-template-columns: 3rem 3fr 2fr;
}
*[role="banner"] {
	grid-row: 1;
	grid-column: 2/4;
	
	background-color: green;
	height: 3rem;
}
*[role="main"] {
	grid-row: 2;
	grid-column: 2;
	background-color: yellow;
	height: 100px;
}
*[role="contentinfo"] {
	grid-row: 3;
	grid-column: 2/3;
	border-top: 1px solid black;
}
*[role="contentinfo"] img {
	height: 100px;
}
<div role="banner"></div>
<article role="main"><p>Some Text.</p><p>Some more text</p><p>the last text</p></article>
<footer role="contentinfo"><img src="https://s14-eu5.ixquick.com/cgi-bin/serveimage?url=https%3A%2F%2Fdata.motor-talk.de%2Fdata%2Fgalleries%2F0%2F147%2F9424%2F43109894%2Fbild--7008737403287221413.jpg&sp=6a4eaf3bd8ff58ca9d9bba2e3519888e"></footer>

【问题讨论】:

    标签: html css grid-layout css-grid


    【解决方案1】:

    页脚(第 3 行)与文章(第 2 行)重叠,因为文章的高度是固定的:

    [role="main"] { height: 100px; }
    

    覆盖您在网格容器上指定的auto 高度:

    grid-template-rows: 3.7rem auto auto
    

    删除height 规则后,重叠就消失了。

    body {
    	display: grid;
    	grid-template-rows: 3.7rem auto auto;
    	grid-template-columns: 3rem 3fr 2fr;
    }
    *[role="banner"] {
    	grid-row: 1;
    	grid-column: 2/4;
    	
    	background-color: green;
    	height: 3rem;
    }
    *[role="main"] {
    	grid-row: 2;
    	grid-column: 2;
    	background-color: yellow;
    	/* height: 100px; <-------- REMOVE */
    }
    *[role="contentinfo"] {
    	grid-row: 3;
    	grid-column: 2/3;
    	border-top: 1px solid black;
    }
    *[role="contentinfo"] img {
    	height: 100px;
    }
    <div role="banner"></div>
    <article role="main"><p>Some Text.</p><p>Some more text</p><p>the last text</p></article>
    <footer role="contentinfo"><img src="https://s14-eu5.ixquick.com/cgi-bin/serveimage?url=https%3A%2F%2Fdata.motor-talk.de%2Fdata%2Fgalleries%2F0%2F147%2F9424%2F43109894%2Fbild--7008737403287221413.jpg&sp=6a4eaf3bd8ff58ca9d9bba2e3519888e"></footer>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      相关资源
      最近更新 更多