Roych Posted March 12, 2020 Share Posted March 12, 2020 Hello I need some help with aligning every second post different than the first. First post with image on the left and text on the right and every second with text on the left and image on the right. I have a repeater field with title, image and text. I would like to stick with repeater if possible. I tried to look on the forum and google but no luck as I'm not even sure how this function is called. It would be great if someone already did something similar. Thank you very much R Link to comment Share on other sites More sharing options...
elabx Posted March 12, 2020 Share Posted March 12, 2020 If using flexbox you could use the order property to change the order of the columns, I normally add a class to a parent div that wraps both columns. foreach($page->repeater as $i => $item){ //Going to offset the count starting from 1 instead of 0 so I can use modulo operator $i = $i + 1; $class = ""; // If the count is even, such as 2,4,6, etc. if($i%2 == 0){ $class = "invert-order"; } echo "<div class='row {$class}'>"; //output the columns here echo "..."; echo "</div>"; } You should end up with something like this: https://codepen.io/elabx/pen/RwPMaym 3 Link to comment Share on other sites More sharing options...
MoritzLost Posted March 13, 2020 Share Posted March 13, 2020 You don't even need to adjust your template, as long as the rows have one common parent you can use the CSS nth-selector: .row { display: flex; flex-flow: row nowrap; justify-content: space-between; align-items: center; } .row:nth-child(2n) { flex-direction: row-reverse; } 5 Link to comment Share on other sites More sharing options...
Roych Posted March 13, 2020 Author Share Posted March 13, 2020 Hello, elabx I tried your code and it works perfect. I was looking for this so long. You are the best ? Thank you very much R 1 Link to comment Share on other sites More sharing options...
elabx Posted March 13, 2020 Share Posted March 13, 2020 5 hours ago, MoritzLost said: .row:nth-child(2n) { flex-direction: row-reverse; } Smarter solution! 3 Link to comment Share on other sites More sharing options...
Roych Posted March 13, 2020 Author Share Posted March 13, 2020 Thank you all, got it up and running perfectly. ? R Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now