2013-09-05 95 views
1

我知道这里有些问题涉及我的问题的部分内容,但我不能将它们放在一起以使我的布局工作。Html,Body 100%内容的高度和动态宽度

所以基本上我想要一个固定的边栏和动态内容填充剩余空间的两个列布局。

HTML:

<body> 
    <div id="navbar"> 
     <ul> 
      <li>Nav 1</li> 
      <li>Nav 2</li> 
      <li>Nav 3</li> 
     </ul> 
    </div> 

    <div id="content"> 
    </div> 
</body> 

CSS:

html, body { 
    height:100%; 
    margin: 0; 
    padding: 0; 
    border: 0; 
} 

#content { 
    height:100%; 
    float:left; 
    /*margin: 0 0 0 200px;*/ 
} 

#navbar{ 
    height:100%; 
    width:200px; 
    float:left; 
} 

有了这个CSS我有我的内容isn't占用的剩余空间的问题,如果我删除浮动,我收到了垂直滚动条,因为在顶部有一个边缘!

任何建议如何我可以实现100%的高度没有滚动条(没有溢出隐藏,因为它不会删除顶部边距)和动态内容宽度?

在此先感谢

编辑:

具有讽刺意味的与jsfiddle

+1

什么小提琴 – Itay

+0

@Itay呃,小提琴?怎么样一个URL? –

+0

你想要你的div#内容有动态宽度吗? – Syd

回答

2

这里是一个解决方案,让您100%的高度,无论在内容和导航栏:

小提琴:http://jsfiddle.net/92c6M/

HTML

<div id="navbar"> 
    <ul> 
     <li>Nav 1</li> 
     <li>Nav 2</li> 
     <li>Nav 3</li> 
    </ul> 
</div> 

<div id="content"> 
</div> 

CSS

html, body { 
    height:100%; 
    margin: 0; 
    padding: 0; 
    border: 0; 
} 

#content { 
    height:100%; 
    width: calc(100% - 200px); 
    display: inline-block; 
    background-color: #DDF; 
} 

#navbar{ 
    height:100%; 
    width:200px; 
    float: left; 
    background-color: #CEC; 
} 
+0

哇这是一个非常好的解决方案,不知道钙!这是否适用于所有浏览器,例如IE7甚至6? – makim

+0

兼容性是ie9 +(http://caniuse.com/#feat=calc) –

+0

IE6?认真。它在IE9 +中工作。 – fred02138

4

http://jsfiddle.net/gXubX/2/

.container { 
    width: 100%; 
    background: fuchsia; 
} 

.left { 
    width: 200px; 
    float: left; 
    background: purple; 
    min-height: 300px; 
} 

并应用于容器clearfix工作。

+0

嘿,你能解释我一点,什么是clearfix? –

+0

[清除](http://www.webtoolkit.info/css-clearfix.html) –

+0

我已经尝试了您的建议,但我仍然有一个边缘,现在也在底部http://jsfiddle.net/ tqEfS/1/ – makim

1

CSS:

#wrapper { 
width: 100%; 
float: left; 
positon: relative; 
} 

#navbar { 
width: 200px; 
float: left; 
top: 0px; 
left: 0px; 
position: absolute; 
    height: 300px; 
background-color: red; 
z-index: 2; 
} 

    #content-wrapper { 
position: absolute; 
top: 0px; 
left: 0px; 
width: 100%; 
height: 300px; 
float: left; 
background-color: blue; 
z-index: 1; 
} 

    #content { 
left: 200px; 
margin-left: 200px; 
background-color: green; 
z-index: 3; 
color: white; 
} 

HTML

<div id="wrapper"> 
<div id="navbar"></div> 
<div id="content-wrapper"> 
    <div id="content"> 
     asdfasfdasdfasdg asdga sdgasdg asdgasdgasdgasdg 
    </div> 
</div> 
</div> 
+0

我不希望导航栏是动态的,它应该有一个固定的宽度 – makim

+0

固定它上面;) – q0re

+0

关闭,但导致水平滚动条: -/ – makim

相关问题