2011-12-07 22 views
0

divタグとそのタグのテキストを含むhtmlファイルがあります。私はdivの真ん中にそのテキストを調整したいし、またどんな解決のためにもページの真ん中を分割したい。私はmargin:0 autoでそれを試しました、そして、それは上の中央に現れますが、垂直には中に現れません。CSSを中心に整列する

答えて

4

divがあなたのHTMLの残りの部分に応じて、次のようにCSSを必要とします。そのコンテナの中央にdiv要素を整列させ、また、センターに内のテキストを揃えます

margin-left: auto; 
margin-right: auto; 
text-align: center; 

編集 - 私はちょうどdivを縦方向に集中したいと思っています。など、この方法として迅速なGoogleが現れるだろうと、これを行う方法、のがたくさんあります:http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

0

これを試すことができます。

margin-left: auto; 
margin-right: auto; 

そして、このコードのdiv使用の途中でテキストを作る:

text-align: center; 
+0

違法CSSは、送信する前に、コードを確認してください。 –

+1

はい私は間違いを更新しました。 –

2

margin auto 0あなたはヨーヨーにwidthを与えるだけでのみ動作しますur divtext-align:centerはテキストを中央に揃えます。

0

div{ 
    margin: 0 auto; /*= the 0 sets the top and bottom margin to zero and the auto centers the div =*/ 
    width: 940px; /*= the width is a must have but can be set to the size you need =*/ 
    text-align: center; /*= use this if you want to center the text inside the div =*/ 
} 
関連する問題