Skip to content

Commit

Permalink
CSS页面布局与定位
Browse files Browse the repository at this point in the history
  • Loading branch information
shuailong committed Aug 22, 2016
1 parent 9aecf23 commit 92d92d3
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
72 changes: 72 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@charset "utf-8";
/* CSS Document */

#layout{
background-color:#cccccc;
border:2px solid #333333;
/* width:80%; /* 一列宽度自适应 */
/* 一列宽度固定 */
width:300px;
height:30px;
/* 当margin使用两个参数,第一个上下边距,第二个左右边距,此处设计呈现出居中状态 */
margin:0px auto;
}

/*
两列 左列固定 右列宽度自适应
若使二列固定宽度居中可在外层套一个div
*/
#left_2{
background-color:#cccccc;
border:2px solid #333333;
/* width:20%; */
width:100px;
height:30px;
float:left;
}
#right_2{
background-color:#cccccc;
border:2px solid #333333;
height:30px;
/* width:70%;
float:left; */
}

/*
三列浮动 中间列自适应
absolute通过z-index属性设置其重叠的顺序 大值对象层级位于小值对象之上
*/
#left_3{
background-color:#cccccc;
border:2px solid #333333;
width:100px;
height:100%; /* 高度自适应 */
position:absolute;
top:68px;
left:0px;
z-index:1;
}
#right_3{
background-color:#cccccc;
border:2px solid #333333;
width:100px;
height:300px;
position:absolute;
top:68px;
right:0px;
}
#center_3{
background-color:#cccccc;
border:2px solid #333333;
height:300px;
margin-left:104px;
margin-right:104px;
}
body{
margin:0px;
padding:0px;
}
/* 用于高度自适应 */
html,body{
height:100%;
}
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" rev="stylesheet" href="css/index.css" type="text/css" />
<title>CSS页面布局与定位</title>
</head>
<body>
<div id="layout">一列固定宽度</div>
<div id="left_2">左列</div>
<div id="right_2">右列</div>
<div id="left_3">左列</div>
<div id="center_3">中列</div>
<div id="right_3">右列</div>
</body>
</html>

0 comments on commit 92d92d3

Please sign in to comment.