Cakers
Cakers

Reputation: 655

Row-wrap center align in flexbox

Currently I am trying to get my columns to center using flexbox but it is sticking to the left when I resize the browser. I have tried justify content center and align-items center but I may not be putting them in the right places. If anyone knows how to fix this that would be much appreciated! Thank you!

.wrap{
	display:flex;
}

main{
	flex:1;
	display:flex;
}

aside, article{
    padding:2em;	
}

aside{
	flex:1;
}

article{
	flex:1;
}

@media (max-width: 800px) {
  main {
    flex-direction: column;
  }
}
<div class="wrap">
    <main>
        <aside>
            <h1>Do You Want to...</h1>
            <ul>
                <li>Rebrand myself online</li>
                <li>Take my current website and make it modern</li>
                <li>Find a way to make information more accessible for customers</li>
                <li> Improve customer service</li>
                <li> Reach a wider range of people</li>
            </ul>
        </aside>
        <article>
            <h1>Do You Want to...</h1>
            <ul>
                <li>Create forms and documents that customers can fill out online</li>
                <li>Start an email list for recurring customers</li>
                <li>Show relatability with my audience</li>
                <li> Have 24/7 online exposure</li>
                <li>Create a map or a way for customers to find my location</li>
            </ul>
        </article>
    </main>
</div>

Upvotes: 8

Views: 22726

Answers (1)

Joseph Marikle
Joseph Marikle

Reputation: 78520

For centering the stacked columns on the mobile view use align-items: center on main. For the desktop view, you can collapse the columns by specifying flex: 0 auto. This indicates that the item should not be allowed to grow and should use an automatic width. Then you add justify-content: center to main to center the collapsed columns.

.wrap{
	display:flex;
	
}

main{
	flex:1;
	display:flex;
	justify-content: center;
}

aside, article{

padding:2em;	
}

aside{
	flex:0 auto;
}

article{
	flex:0 auto;
}

@media (max-width: 800px) {
  main {
    flex-direction: column;
    align-items: center;
  }
}
<div class="wrap">
<main>
<aside>
	<h1>Do You Want to...</h1>
    <ul>
  <li>Rebrand myself online</li>
  <li>Take my current website and make it modern</li>
  <li>Find a way to make information more accessible for customers</li>
  <li> Improve customer service</li>
  <li> Reach a wider range of people</li>
</ul>
</aside>
<article>
<h1>Do You Want to...</h1>

<ul>
  <li>Create forms and documents that customers can fill out online</li>
  <li>Start an email list for recurring customers</li>
  <li>Show relatability with my audience</li>
  <li> Have 24/7 online exposure</li>
  <li>Create a map or a way for customers to find my location</li>
</ul>
</article>

</main>
</div>

Upvotes: 11

Related Questions