怎么用div布局加css样式做网页

html-css017

怎么用div布局加css样式做网页,第1张

在div里设置id或者class

<div id="aaa"></div>

<div class="bbb"></div>

然后在css样式表里定义样式

#aaa{

}

.bbb{

}

---------------

DIV+CSS通用样式布局实例代码

对于刚开始接触DIV+CSS的同学来说,记住那些对象属性以及对应的值就很困难了,更何况来完成页面的布局了

一下是一个非常简单易懂的通用样式布局,希望对于刚开始接触DIV+CSS的同学有帮助。先看效果图:

我们可以看出通常的页面布局有以下几个部分:头部、内容、底部,其中内容有左侧主显区和右侧边栏。下面贴出代码:

代码如下:

<!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/htmlcharset=gbk" />

<title>DIV+CSS practice</title>

<link

href="css/common.css" rel="stylesheet" type="text/css" media="all" />

</head>

<body>

<!-- 头部 -->

<div

id="head">

</div>

<!--END 头部 -->

<!-- 主容器 -->

<div id="container">

<!-- 左侧主显区 -->

<div

id="content">

</div>

<!-- END 左侧主显区 -->

<!-- 右侧边栏

-->

<div id="side">

</div>

<!-- END 右侧边栏 -->

</div>

<!-- END 主容器 -->

<div

class="clear"></div>

<!-- 底部 -->

<div id="foot">

</div>

<!-- END 底部 -->

</body>

</html>

common.css样式文件:

*{

margin:0

padding:0

}

body{

background-color:gray

}

.clear{

clear:both

}

/*head*/

#head{

background-color:blue

height:150px

}

/*container*/

#container{

background-color:red

width:960px

height:800px

margin:20px auto

}

/*content*/

#content{

background-color:yellow

float:left

width:685px

height:100%

}

/*side*/

#side{

background-color:green

float:right

width:255px

height:100%

}

/*foot*/

#foot{

background-color:white

height:150px

width:960px

margin:20px

auto

}

大致布局很简单了,首先要有这个大局观,然后再完善其中的细节,学习PHP或者其他语言同样如此,首先要有一个思想,知道每一步做什么,怎么做,这样才能把知识灵活运用。

我看到你的要求后,第一反应就是用position

将head定位在顶端,content的高度设为100%

在content中嵌套一层,并指定padding-top的值为head的高度

是否OK?

.panel{

border: solid RGB(153,187,232) 1px

width: 300px

height: 200px

top:0px

left:0px

position:relative

}

.head{

width: 100%

height: 20px

border-bottom: solid RGB(153,187,232) 1px

background-color: RGB(217,231,248)

position:absolute

top:0left:0

}

.content{

background-color:gray

width:100%

height:100%

}

.content .area {

padding-top:21px

background-color:red

}

<div id="contentDiv" class="content">

<div class="area">adfadfadf</div>

</div>