使用div与CSS实现网页布局

文章展示了如何使用VSCode创建HTML和CSS文件,并编写代码实现页面布局。HTML部分包含多个div元素,CSS部分定义了不同ID的样式,用于画图布局,创建了一个1000px*500px的结构,包括不同颜色和尺寸的块状元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用vscode创建文件夹

在文件夹里面创建text.html和text.css文件

在text文件输入如下代码:

<!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>tt1</title>
    <link rel="stylesheet" type="text/css" href="text.css">
</head>
<body>
    <div id="z">
        <div id="a"></div>
            <div id="d">
               <div id="e"></div>
               <div id="f">
                   <div id="g"></div>
                   <div id="h"></div>
               </div>
               <div id="c">
                   <div id="l"></div>
                   <div id="j"></div>
                   <div id="k"></div>
               </div>
            </div>
        <div id="b"></div>    
    </div>
</body>
</html>

用css画图布局输入如下代码:

#z{width:1000px;height:500px;margin: 0 auto;}
#a{background-color:
 red;width: 1000px;height: 90px;margin-bottom: 10px;}
#d{width:1000px;height:300px;background-color: brown;}
#e{width:240px;height:300px;float: left;background-color:gray;margin-right:10px;}
#c{width:500px;height:300px;background-color:salmon;float:right;}
#f{width:240px;height:300px;float:right;margin-left: 10px;}
#b{background-color:gold;width: 1000px;height: 90px;margin-top: 10px;}
#g{width:115px;height:300px;margin-right: 5px;background-color: pink;float: left;}
#h{width:115px;height:300px;margin-left:5px;background-color:yellow;float: right;}
#l{width:500px;height:100px;background-color:hotpink;margin-bottom: 50px;}
#j{width:220px;height:150px;background-color:black;margin-left: 15px;float: left;}
#k{width:220px;height:150px;background-color:blue;margin-left: 15px;margin-right: 30px;float: right;}

 点击Ctrl+s保存,然后运行,得到如图所示:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

失之一灵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值