2016-06-28 55 views
0

我有一个孩子的div居中垂直和水平在其父母的内部中心以及使用柔性。但是,内容和h2并排居中,我希望它们堆叠。需要物品堆叠,同时使用柔性

.jumbotron { 
 
    position: relative; 
 
    min-height: 600px; 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
#s-text { 
 
    text-align: center; 
 
    height: 100px; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
    width: 70%; 
 
    margin: 0 auto; 
 
} 
 
#s-text h2 { 
 
    color: #fff; 
 
    margin-bottom: 20px; 
 
    padding: 0; 
 
}
<div class="jumbotron" style="..."> 
 
    <div id="s-text"> 
 
    <h2> the_secondary_title </h2> \t 
 
    <p>multiple lines of content ...</p> 
 
    </div> 
 
</div>

回答

3

使用flex-direction: column;

.jumbotron { 
 
    position: relative; 
 
    min-height: 400px; 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    margin: 0; padding: 0; 
 
} 
 

 
#s-text { 
 
    text-align: center; 
 
    height: 100px; 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: center; 
 
    justify-content: center; 
 
    width: 70%; 
 
    margin: 0 auto; 
 
} 
 

 
#s-text h2 { 
 
    color: #000; 
 
    margin-bottom: 20px; padding: 0; 
 
}
<div class="jumbotron" style="..."> 
 
    <div id="s-text"> 
 
     <h2> Heading </h2>    
 
     <p>multiple lines of content ...</p>  
 
    </div> 
 
</div>

+0

完善,该属性具有相同的跨浏览器支持的那些弯曲的休息吗? – user3550879

+0

@ user3550879是的,它有很好的浏览器支持。如果浏览器支持'flex',它也会支持'flex-direction'。 –

相关问题