2016-08-03 15 views
-3

このHTMLはdisplay:table-cellを使ってグリッドの一部です。 divの幅が内容よりも広い:divの内側にボタンやテキストを水平に配置するにはどうすればよいですか?

<div>123</div> 
<div><button>1</button></div> 

大きなdivの中にテキストとボタンを入力するにはどうすればよいですか?

+0

あなたが既に試したことを私たちに教えてください。私たちはあなたのブラウニーではありません – DestinatioN

+1

https://css-tricks.com/centering-css-complete-guide/ –

答えて

0

.centeredFlex { 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    height: 600px; /* whatever you want... */ 
 
    width: 100%; /* whatever you want... */ 
 
}
<div class="centeredFlex"> 
 
    <button>1</button> 
 
</div>

フレックスボックスをご覧ください:http://www.w3schools.com/css/css3_flexbox.asp

+1

Syam Pillaiはより速く、彼の解決策は正しいです。私のほうがちょっときれいです。 – sandrooco

2

flex-boxはあなたが水平方向の中心をしたくない場合はalign-items: centerを削除することができますし、垂直方向の中心を望んでいないjustify-content: centerを削除することができ

.container{ 
 
\t display: flex; 
 
\t align-items: center; 
 
\t justify-content: center; 
 
\t flex-direction: column; 
 
\t height: 100vh; 
 
\t background: brown; 
 
}
<div class="container"> 
 
\t <p>Text at center</p> 
 
\t <button>button</button> 
 
</div>

最善の解決策にある

関連する問題