DIV+CSS一行三列代码如何写?

html-css010

DIV+CSS一行三列代码如何写?,第1张

此处的注释为去掉换行符的影响

.wrapper

{

width:

100%

/*

也可以固定宽度

*/

height:

200px

}

.wrapper

>

div

{

display:

inline-block

/*

如需支持ie8以下版本,用浮动来做

*/

width:

calc(100%

/

3)

/*

此处运用了一个css3的表达式,将div三等分,ie8及以上可以支持,当然也可以根据需要设置固定值

*/

width:

-webkit-calc(100%

/3)

width:

-moz-calc(100%

/

3)

height:

100%

}

以上经亲自测过,ie8+、chrome、firefox表现良好。

1、首选看一下html代码:

html代码:

<div id="left">

<div class="inner">this is left sidebar content</div>

</div>

<div id="main">

<div class="inner">this is main content</div>

</div>

<div id="right">

<div class="inner">this is right siderbar content</div>

</div>

这种方法是借助于负的margin来实现的,首先在中间列定好固定值,因为此值是不会在改变的,接着对其进行左浮动;那么关键地主是在左右边栏设置地方,这种方法是将其都进行50%的宽度设置,并加上中负的左边距,此负的左边距最理想的值是中间栏宽度的一半加上1px,这样一来,左右边栏内容无法正常显示,那是因为对他们进行了负的左边距操作,现在只需要在左右边栏的内层div.inner将其拉回来。

2、css样式写法如下:

#left,

#right {

float: left

margin: 0 0 0 -271px

width: 50%

}

#main {

width: 540px

float: left

background: green

}

.inner {

padding: 20px

}

#left .inner,

#right .inner {

margin: 0 0 0 271px

background: orange

}

3、具体效果如下: