Html当中文本与标签如何居中

来源:互联网 发布:淘宝商城开店条件 编辑:程序博客网 时间:2024/06/06 02:27

1、文本居中:

text-align: center;line-height: 100px; (=height)

2、标签居中

margin: 0 auto;   其中0指的是margin-top:0

代码片:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>搜索论坛</title>    <link rel="stylesheet" href="https://www.baidu.com/img/baidu_jgylogo3.gif">    <style>        .item1{            height: 100px;            width: 100px;            background-color: red;            text-align: center;            line-height: 100px;            margin: 0 auto;        }        .item2{            height: 100px;            width: 100px;            background-color: wheat;            text-align: center;            line-height: 100px;            margin: 100px auto;        }    </style></head><body>    <div class="outer">         <div class="item1">1111</div>         <div class="item2">2222</div>    </div></body></html>

这里写图片描述