用css进行网页布局

 第一部分

<style type="text/css">
      body{margin:0;padding:0}
      .top{height:100px;background:blue}
      .main{width:800px;height:300px;background:black;margin:0 auto}
      .foot{width:800px;height:100px;background:red;margin:0 auto}
</style>
<body>
     <div class="top"></div>
     <div class="main"></div>
     <div class="foot"></div>
</body>
    上面代码是网页的一列布局,其中有几个点和大家分享一下。

         

<div class="top"></div>
<div class="main"></div>
<div class="foot"></div>
   一般网页都是分上中下三部分,即代码中的“top”,“main”,“foot”

 

 

body{margin:0;padding:0}
   这句话是为了让布局和html页面没有边距。
margin:0 auto

   是为了让“main”,"foot"居中,0 是指上下的距离,auto指左右自适应

 

 第二部分  

<style type="text/css">
      body{margin:0;padding:0}
      .main{width:800px;margin:0 auto}
      .left{width:30%;height:500px;float:left;background:red}
      .right{width:70%;height:500px;float:right;background:blue}
</style>
<body>
     <div class="main">
     <div class="left"></div>
     <div class="right"></div>
     </div>
</body>
   这第二部分是网页的二列布局。

 

   与第一部分大体相同但主要是中间部分“main”,分成了两部分“left”,“right”。
   二列布局最重要的是控制其宽度,即
.left{width:30%;}
    设置可以是百分比,也可以是具体的数据如 300px,但左右总值是800px。
    为了实现能分成两列,咱们需要用到float属性,即
float:left   right
   用于控制元素的位置(位于左,还是右)。
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值