将段落标题放在flexbox内的段落上方



我目前有一个节,其中包含一个图像,一个h2和一个段落。对于768px+的媒体查询,它使用display: flex;左右对齐。然而,这当然使得h2位于图像和段落之间,但我希望h2位于段落上方并左对齐。我觉得我已经尝试了很多不同的东西,所以在这一点上有点不知所措。

没有看到你的代码,我在这里有点猜测。但我认为你需要image>h2祝辞P在彼此下面,然后image>媒体查询中H2/P相邻

如果是这种情况,只需将h2和p包装在自己的div中,以控制特定宽度的伸缩方向。

.wrapper {
display: flex;
flex-direction: column;
}
.text-wrapper {
display: flex;
flex-direction: column;
}
// Not sure what you want here, but changing the direction property should solve it
@media only screen and (min-width: 768px) {
.wrapper {
flex-direction: row;
}
}
<div class="wrapper">
<div> Image </div>
<div class="text-wrapper">
<h2> Header </h2>
<p> Paragraph </p>
</div>
</div>

最新更新