Home  >  Article  >  Web Front-end  >  Briefly introduce the method of implementing single-column layout and horizontal center layout using HTML+CSS

Briefly introduce the method of implementing single-column layout and horizontal center layout using HTML+CSS

巴扎黑
巴扎黑Original
2017-09-07 09:32:421765browse

This article mainly introduces the relevant information about HTML+CSS to implement single-column layout and horizontal center layout. Friends in need can refer to the following

Horizontal center layout

  1. Parent element text-align:center; child element: inline-block;

  2. Advantages: good compatibility;

  3. Disadvantage: You need to set both the child element and the parent element


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>水平居中布局</title>
<style>
    *{
      margin: 0;
      padding: 0;
    }
    .parent {
        width: 100%;
        background: green;
        text-align: center;
    }
    .child {
        display: inline-block;
        width: 800px;
        height: 100px;
        background: blue;
    }
</style>
</head>
<body>
<p class="parent">
    <p class="child">1</p>
    <p class="child">2</p>
    <p class="child">3</p>
    <p class="child">4</p>
    <p class="child">5</p>
    <p class="child">6</p>
</p>
</body>
</html>

The above is the detailed content of Briefly introduce the method of implementing single-column layout and horizontal center layout using HTML+CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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