CSS控制DIV宽度代码:

html-css013

CSS控制DIV宽度代码:,第1张

<div

class="main"><div

class="left"></div><div

class="center"></div><div

class="right"></div><div

class="cle"></div></div><style

type="text/css">.main

{width:1000pxmargin:0

auto}.left

{width:245pxfloat:left}.center

{width:435pxfloat:leftmargin-left:10px}.right

{width:300pxfloat:right}.cle

{height:0clear:both}</style>

正常情况中间是要定宽度的,特殊手段还是做到不定宽度的,注意:center、left和right的总宽度+他们的margin不能大于main的宽度。

给所有的DIV设定宽度和高度不是必须的。

DIV是块级元素,默认的宽为100%,也就是你DIV外面的元素有多宽,DIV就是多宽。

DIV的高默认为内部元素的高,也就是DIV里面的元素有多高,DIV就是多高。当DIV里面的元素为浮动元素时候就会出现DIV高为0,所以这时候就得清除浮动。

<div class="main"><div class="left"></div><div class="center"></div><div class="right"></div><div class="cle"></div></div><style type="text/css">.main {width:1000pxmargin:0 auto}.left {width:245pxfloat:left}.center {width:435pxfloat:leftmargin-left:10px}.right {width:300pxfloat:right}.cle {height:0clear:both}</style>正常情况中间是要定宽度的,特殊手段还是做到不定宽度的,注意:center、left和right的总宽度+他们的margin不能大于main的宽度。