目前我正在尝试使用flexbox将我的列设置为中心,但是当我调整浏览器大小时它会粘在左侧。我已经尝试过对齐内容中心和对齐项目中心,但我可能不会将它们放在正确的位置。如果有人知道如何解决这个问题将非常感激!谢谢!
.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>
&#13;
答案 0 :(得分:6)
要使移动视图上的堆积列居中,请使用align-items: center
上的main
。对于桌面视图,您可以通过指定flex: 0 auto
来折叠列。这表示不应允许该项目增长,并应使用自动宽度。然后,您将justify-content: center
添加到main
以使折叠列居中。
.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>