• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
青春你好
博客园    首页    新随笔    联系   管理    订阅  订阅
十天学会DIV+CSS(DIV布局)

一列布局:

一列固定宽度、一列固定宽度居中、一列自适应宽度、一列自适应宽度居中

一列固定宽度

<head>

<style type="text/css">

#layout { height: 300px; width: 400px; background: #99FFcc; }
</style>

</head>

一列固定宽度居中

<head>

<style type="text/css">

#layout { height: 300px; width: 400px; background: #99FFcc; margin: auto; }

</style>

</head>

一列自适应宽度

 <head>

<style type="text/css">

#layout { height: 300px; background: #99FFcc;}

</style>

</head>

一列自适应宽度居中

 <head>

<style type="text/css">

body { margin: 0px; }
#layout { margin:auto; height: 300px; background: #99FFcc; width: 80%; }

</style>

</head>

两列布局

二列自适应宽度、两列固定宽度、两列固定宽度居中、float属性。

二列自适应宽度

<head>
<style type="text/css">
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#main { background: #99FFFF; height: 300px; width: 70%; margin-left: 120px; }
</style>
</head>

 两列固定宽度

<head>
<style type="text/css">
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#main { background: #99FFFF; height: 300px; width: 350px; margin-left: 120px; }
</style>
</head>

两列固定宽度居中

<head>
<style type="text/css">
#content { width:470px; margin:0 auto;}
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#main { background: #99FFFF; height: 300px; width: 350px; margin-left: 120px; }
</style>
</head>

float属性

<head>

<style type="text/css">

body { font-size:18px; line-height:200%; }
#side { float:left;width:202px;}

#main { margin-left:202px;}

</style>

</head>

三列布局

三列自适应宽度、三列固定宽度、三列固定宽度居中、

IE6的3像素bug

三列自适应宽度

<head>

<style type="text/css">
body { margin:0;}
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#side1 { background: #99FF99; height: 300px; width: 120px; float: right; }
#main { background: #99FFFF; height: 300px; margin:0 120px; }
</style>
</head>
三列固定宽度

<head>

<style>
body { margin:0;}
#content { width:470px; margin:0 auto;}
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#side1 { background: #99FF99; height: 300px; width: 120px; float: right; }
#main { background: #99FFFF; height: 300px; margin:0 120px; }
</style>
</head>

三列固定宽度居中

<head>
<style>
body { margin:0;}
#content { width:470px; margin:0 auto;}
#side { background: #99FF99; height: 300px; width: 120px; float: left; }
#side1 { background: #99FF99; height: 300px; width: 120px; float: right; }
#main { background: #99FFFF; height: 300px; margin:0 120px; }
</style>
</head>

 

 

posted on 2015-09-14 11:30  青春你好  阅读(754)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3