Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row-wrap center align in flexbox

Tags:

html

css

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>
like image 513
Cakers Avatar asked Feb 03 '17 15:02

Cakers


People also ask

How do you center with flex-wrap?

You need to use the justify-content property to center flex items along the main axis. Its default value is flex-start which aligns all the items inside the flex container to the beginning of the main axis. If you want to center the items you need to use it with the center value.

How do I align items horizontally in Flexbox?

To center our box we use the align-items property to align our item on the cross axis, which in this case is the block axis running vertically. We use justify-content to align the item on the main axis, which in this case is the inline axis running horizontally.

What does the flex-wrap wrap rule do?

The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.


1 Answers

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>
like image 182
Joseph Marikle Avatar answered Oct 14 '22 00:10

Joseph Marikle