<div class="outer">
<div class="inner">
<div class="inner-position">
<p>I should be centered</p>
</div>
</div>
</div>
<div class="outer">
<div class="inner">
<div class="inner-position">
<p>I should be centered</p>
</div>
</div>
</div>
Solution 3 :
Using the example from the first snippet and wrapping that twice I’ve managed to get the desired effect, there’s still the issue with having to use text-align to align horizontally but this is the closest I can get without using flex or box-sizing: border-box;. If there’s a more appropriate way to do this an example would be appreciated.
I’ve used text-align: center; but there should be a better way to center the contents vertically too. My issue arises trying to do the same where two of these are next to each other with centered content, like this;
<div class="outer">
<div class="inner">
<div class="inner-position">
<p>I should be centered</p>
</div>
</div>
</div>
<div class="outer">
<div class="inner">
<div class="inner-position">
<p>I should be centered</p>
</div>
</div>
</div>
It’s looking even worse in a snippet for some reason but something like this would be desired;
I can get the column layout or I can center content. I need to be able to do both.
Close but the background needs to be on the main wrapper as it won’t be a solid colour in the end. I’ve found an approach with more wrappers
Comment posted by Itay Gal
OK, you can use the background where you want, but this is the core idea of the layout and it matches your image
Comment posted by learningtoanimate
I’m going to test a few variants now
Comment posted by learningtoanimate
That’s close (and fine for stacking them), there’s no support for keeping it working horizontally
Comment posted by yinsweet
@learningtoanimate what do you mean no support for keeping it working horizontally? Sorry, I don’t understand.
Comment posted by learningtoanimate
If you see my answer and then resize the viewport you’ll notice it adapts to the screen
Comment posted by yinsweet
@learningtoanimate that’s because I’m using % for the height. Once I changed the height to fix value such as 100px, I think I get the same results as yours. Please check the code snippets again. Thx.