2016-06-28 56 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'。 –

相關問題