html + css 容器居中一例

来源:互联网 发布:c语言选择结构编程题 编辑:程序博客网 时间:2024/06/05 11:08

指定了 width 属性的容器,当 left-margin 和 right-margin 设置为 auto 的时候,容器会居中显示。

<body>    <p>Analog synthsizers are often said to have a "warmer" sound than their digital counterparts.</p>    <p class="example">        p.example {        margin: 10px auto 10px auto;        text-align: left;        }    </p></body><style type="text/css">    body {        text-align: center; // 兼容 IE6    }    p {        width: 300px;        height: 50px;        border: 20px solid #0088dd;    }    p.example {        margin: 10px auto 10px auto;         text-align: left; // 继承来的 text-align:center 会让文字内容居中,这里设置回 left 默认值.    }</style>
0 0
原创粉丝点击