How to center text and labels in html

王林
Release: 2020-08-29 16:30:17
forward
5615 people have browsed it

How to center text and labels in html

Implementation method:

(Recommended tutorial: html tutorial)

1. Text centering:

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

2. Center the label

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

Specific code:

<!DOCTYPE html>
<html>
<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>
         <div>1111</div>
         <div>2222</div>
    </div>
</body>

</html>
Copy after login

The above is the detailed content of How to center text and labels in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!