CSS - How to Align Children in Different Parents Vertically
To align children in different parents vertically without using JavaScript, make them siblings and use flexbox to control their order and flex basis. Here's how to achieve this:
Updated Code:
<code class="css">@media (min-width: 768px) { .content { display: flex; flex-wrap: wrap; justify-content: space-around; } .content > * { flex-basis: calc(50% - 30px); } .content h2 { order: 0; } .content p { order: 1; } .content p + p { order: 2; flex-basis: calc(100% - 30px); } .content ul { order: 3; } }</code>
HTML Code:
<code class="html"><div class="content"> <h2>Lorem ipsum Lorem ipsum</h2> <p>...</p> <p>...</p> <ul class="check">...</ul> <h2>Lorem ipsum</h2> <p>...</p> <ul class="check">...</ul> </div></code>
Explanation:
The above is the detailed content of How to Vertically Align Elements from Different Parents in CSS without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!