I'm trying to do a responsive layout with css grid by getting two elements to overlap each other halfway. On wide screens they are in one row and overlapping horizontally, but on narrow screens they should be in one column and overlap vertically.
Here is an illustration of what I'm trying to achieve:
Is this behavior possible with css grid? Here is how far I got but now I'm stuck trying to get the vertical overlap.
CSS
.wrapper {
background: white;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(444px, 1fr));
}
.wrapper__red, .wrapper__green {
align-self: center;
}
.wrapper__red {
z-index: 1;
background: red;
}
.wrapper__green {
justify-self: end;
height: 100%;
background: green;
}
HTML
<div class="wrapper">
<h1 class="wrapper__red">Title text goes here</h1>
<img class="wrapper__green" src="/a.jpg" />
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…