zl程序教程

您现在的位置是:首页 >  前端

当前栏目

HTML常用布局方式

HTML 方式 常用 布局
2023-09-14 09:14:25 时间

前言:对HTML的学习,在了解了基础的语法之后,需要学习与掌握的是,HTML的基础布局方式,这个是网页布局的基础,本文讲解是当前常用布局。

布局一

示例图

在这里插入图片描述

代码部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .header{
            border-style: solid;  /*设置边框样式*/
            text-align: center; /*让文字居中*/
            height: 100px;
            width: 100%; /*设置宽度为浏览器100%*/
        }
        .left{
            height: 500px;
            width: 20%;
            margin-top: 10px;
            display: inline-block; /*设置块类元素为行内块*/
            border-style: solid;
            text-align: center;
        }
        .center{
            height: 500px;
            width: 79%;
            margin-top: 10px;
            display: inline-block;
            border-style: solid;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">header</div>
    <div class="left">left</div>
    <div class="center">center</div>
</body>
</html>

布局二

在这里插入图片描述
代码部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .header{
            border-style: solid;  /*设置边框样式*/
            text-align: center; /*让文字居中*/
            height: 100px;
            width: 100%;
        }   
    
        .center{
            height: 500px;
            width: 100%;
            margin-top: 10px;
            display: inline-block;
            border-style: solid;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">header</div>
    <div class="center">center</div>
</body>
</html>

布局三

在这里插入图片描述
代码部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .center{
            height: 500px;
            width: 100%;
            border-style: solid;
            text-align: center;
            margin-bottom: 10px;
        }
        .buttom{
            height: 200px;
            width: 100%;
            border-style: solid;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="center">center</div>
    <div class="buttom">buttom</div>
</body>
</html>

布局四

在这里插入图片描述
代码部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .border1{
            border-style: solid;
            text-align: center;
        }
        .header{
            height: 200px;
            width: 100%;
        }
        .left{
            width: 23.5%;
            display: inline-block;
        }
        .center{
            width: 50%;
            display: inline-block;
        }
        .right{
            width: 23.5%;
            display: inline-block;
        }
        .buttom1{
            margin-top: 10px;
            margin-bottom: 10px;
            height: 200px;
        }
        .buttom{
            height: 200px;
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="header border1" >header</div>
    <div class="left border1 buttom1">left</div>
    <div class="center border1 buttom1">center</div>
    <div class="right border1 buttom1">right</div>
    <div class="buttom border1">buttom</div>
</body>
</html>