最新のブラウザーを使用している場合は、フレックスボックス レイアウト モジュールを使用できます: http://caniuse.com/#feat=flexbox。
フレックスボックスのドキュメント: developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
注: 私の担当者のため、2 つ以上のリンクを投稿することはできません。
JSFiddle。
(簡単なので、footer
タグの代わりにタグを使用します。)div#footer
<div id="footer-container">
<footer>hello world</footer>
<div>
#footer-container {
bottom: 20px;
position: fixed;
display: flex;
justify-content: center;
width: 100%;
}
footer {
width: 500px;
background-color: red;
}
justify-content: center;
'centers'#footer-container
の子であり、この場合は単なるfooter
要素です。
text-align
これは、フッターのプロパティをリセットする必要がないことを除いて、Nick N. のソリューションと非常によく似ています。
その場合のフッターの幅は 500px ではなく可変 (80%) であるため、受け入れられた解決策はわずかにずれています。
親がform
要素で、子がinput
要素である場合flex: 1;
、input
(子) 要素で使用し、max-width: 500px;
代わりにを使用してwidth: 500px;
ください。を使用flex: 1;
するinput
と、要素の幅を埋めるために要素が拡張されform
ますが、それ以外の場合はそうではありません。