2016-04-14 36 views
2

フレックスボックスで垂直方向に整列した列の内容を管理しました。 しかし、私は列のヘッダーも持つ必要があります。見出しの付いた垂直方向の中央揃えのフレックスflexbox

私はテキストが列の幅を中心とし

は私codepen試して見列(コンテンツが垂直方向に中央揃えたままにしなければならない)の上部にあるされているヘッダを持つことができます方法: http://codepen.io/anon/pen/QNmrNx私が正しくあなたを理解していれば

+0

、あなたは '.wpをしたい:最初-child'トップ整列するには? – Paul

+0

@Paulのいずれか、または見出しに余分の行があります。列の幅はコンテンツ行の幅と同じです – ManuKaracho

+2

これは何か? http://codepen.io/anon/pen/ONvoGw – Paul

答えて

0

.tothetop{ 
     position: absolute; 
     top:0; 
     text-align:center; 
     background: yellow; 
    } 

が上にヘッダを置くが、私は、テキストをセンタリングすることはできませんので、幅が列幅と一致していない、あなたは、ヘッダーテキストが中央になりたい水平I列に対するn。これはあなたを助けるかもしれない - そう

header { 
 
    display: flex; 
 
    justify-content: center; 
 
    width: 500px; 
 
    margin: auto; 
 
}  
 
.myView { 
 
      margin: auto; 
 
      display: flex; 
 
      flex-direction: row; 
 
      justify-content: space-around; 
 

 
      height: 500px; 
 
      width: 500px; 
 
     } 
 

 
     .wpType { 
 
      display: -webkit-flex; 
 
      display: flex; 
 
      -webkit-flex-direction: column; 
 
      flex-direction: column; 
 
      -webkit-align-items: center; 
 
      align-items: center; 
 
      -webkit-justify-content: center; 
 
      justify-content: center; 
 
      padding: 0; 
 
      margin: 0; 
 
      list-style: none; 
 
      border: 1px solid silver; 
 
     } 
 

 
     .wpType:nth-child(even){ 
 
      background: blue; 
 
     } 
 
     .wpType:nth-child(odd){ 
 
      background: red; 
 
     } 
 

 
     .wp{ 
 
      flex: 0 1 auto; 
 
      padding: 5px; 
 
      width: 100px; 
 
      height: 100px; 
 
      margin: 10px; 
 
      background: white; 
 
      line-height: 100px; 
 
      color: white; 
 
      font-weight: bold; 
 
      font-size: 2em; 
 
      text-align: center; 
 
     }
<header>header</header> 
 
<div class="myView"> 
 
    <div class="wpType"> 
 
     <div class="wp"></div> 
 

 
    </div> 
 
    <div class="wpType"> 
 
     <div class="wp"></div> 
 
     <div class="wp"></div> 
 
     <div class="wp"></div> 
 
    </div> 
 
    <div class="wpType"> 
 
     <div class="wp"></div> 
 
     <div class="wp"></div> 
 
     <div class="wp"></div> 
 
    </div> 
 
    <div class="wpType"><div class="wp"></div> 
 
     <div class="wp"></div></div> 
 
    <div class="wpType"><div class="wp"></div></div> 
 

 
</div>

関連する問題