PHP & JavaScript Room :: 設置サンプル

実行結果

NetscapeやFirefoxでは、センタリングしたい要素にmargin-left:auto;margin-right:auto;を指定すればセンタリングされますが、 IEでは更にbody要素などセンタリングしたい要素の親要素にtext-align:center;を指定する必要があります。

ソース

<style type="text/css">
    div.centering {
        width:100%;
        background-color:orange;
        margin:0 auto;  /* Netscape, Firefox用 */
        padding:20px 0;
        text-align:center; /* IE用 */
    }
    div.centering p {
        width:80%;
        text-align:left;
        margin:0 auto;  /* Netscape,Firefox用 */
        background-color:#ffffcc;
    }
</style>

<div class="centering">
    <p>NetscapeやFirefoxでは、センタリングしたい要素に<code>margin-left:auto;</code>と<code>margin-right:auto;</code>を指定すればセンタリングされますが、 IEでは更にbody要素などセンタリングしたい要素の親要素に<code>text-align:center;</code>を指定する必要があります。</p>
</div>


polarized women