css - 为标题和图像使用网格,但现在一个图像位于/隐藏另一个图像之上

标签 css image css-grid

第二个 img 现在不是并排出现,而是将另一个隐藏在它后面,不确定是什么原因造成的。有一段时间没有使用网格区域,但使用了一些我用于其他东西的相同结构,已经成功了,所以不明白为什么这不起作用。感谢您的帮助。

#intro article{
	background: #FFE121;
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-areas: 
		"a a"
		"b c";
	grid-column-gap: 50px;
	
}

#intro article h2{
	grid-area: a;
}

#intro article:first-of-type img{
	grid-area: b;
}

#intro article:last-of-type img{
	grid-area: c;
}

#intro h2{
	text-align: center;
	color:#037272;
}


#intro p{
	flex:100%;
	font-size: 25px;
	padding:20px 40px;
}
	<section id="intro">
		<article>
		
			<img src="images/c1.JPG" alt="c 1">

			<h2>This year we welcome ...</h2>

			<img src="images/c2.JPG" alt="c 2">
			
		</article>
			
		
		<p>By popular demand...</p>
		
	</section>

最佳答案

您的 CSS 选择器 #intro article:first-of-type img 不正确,应该是 #intro article img:first-of-type

#intro article:last-of-type img 也是如此。

#intro article{
	background: #FFE121;
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-areas: 
		"a a"
		"b c";
	grid-column-gap: 50px;
	
}

#intro article h2{
	grid-area: a;
}

#intro article img:first-of-type{
	grid-area: b;
}

#intro article img:last-of-type{
	grid-area: c;
}

#intro h2{
	text-align: center;
	color:#037272;
}


#intro p{
	flex:100%;
	font-size: 25px;
	padding:20px 40px;
}
<section id="intro">
		<article>
		
			<img src="" alt="c 1">

			<h2>This year we welcome ...</h2>

			<img src="" alt="c 2">
			
		</article>
			
		
		<p>By popular demand...</p>
		
	</section>

关于css - 为标题和图像使用网格,但现在一个图像位于/隐藏另一个图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59389856/

相关文章:

javascript - 停止多个动画直到另一个动画完成

html - 悬停文本时更改父 div 背景颜色

html - CSS 能处理这种类似沙漏的情况吗?

html - 如何使用文本字体百分比而不是文本图像进行响应式设计?附上我的代码

html - 多个图像下方的文本对齐

html - CSS 网格。隐藏未使用区域

c# - 登录页面不能在未登录的情况下引用其他文件

java - OpenCV4Android 默认的 Mat 图像类型是什么?

html - 使 CSS Grid 适合最小空间

html - 如何定位 CSS 网格布局中的特定列或行?