2014-10-18 114 views
1

我的侧边栏没有按“当我添加的内容牛逼垂直拉伸 我怎样才能使HTML和CSS只使用侧边栏不垂直拉伸

enter image description here

HTML代码成长:?

<div id="main"> 
    <section> 
    a lot of text here... 
    </section> 
    <div id="sidebar"> 
    a lot of text here... 
    </div> 
</div> 
<footer> 
Copyright © domain.com 2014 
</footer> 

CSS代码:

#main{ 
    background: #ffffff; 
    width: 60%; 
    margin: auto; 
    padding: 20px; 
    position:relative; 
} 

section{ 
    width: 75%; 
    margin: 40px 0; 
    padding: 0; 
    line-height: 1.5em; 
    min-height: 100px; 
} 

#sidebar{ 
    width:150px; 
    position: absolute; 
    margin: 60px 0 0 10px; 
    padding: 0 20px 0 20px; 
    right:0; 
    bottom:0; 
    top:0; 
    line-height: 1.5em; 
} 

footer{ 
    width: 60%; 
    background-color: #700505; 
    text-align: center; 
    padding: 20px; 
    padding-top: 10px; 
    padding-bottom: 10px; 
    margin: auto; 
    margin-bottom: 20px; 
    color: #ffffff; 
} 

我知道有可能是在那里有很多不需要的属性...

编辑:现在增加了页脚,我希望这就够了。复制时必须添加很多行以使其与页脚重叠。

+0

你能上传更多的源代码吗? – 2014-10-18 18:16:54

+0

请提供所有必要的代码来重现问题。 – George 2014-10-18 18:17:20

+0

@IPADDRESS添加了更多源代码。 – user3002135 2014-10-18 18:32:15

回答

1

试试这个...

CSS:

#main{ 
background: #ffffff; 
width: 60%; 
margin: auto; 
padding: 20px; 
position:relative; 
} 

section{ 
width: 55%; 
display:inline-block; 
vertical-align:top; 
margin: 40px 0; 
padding: 0; 
line-height: 1.5em; 
min-height: 100px; 
} 

#sidebar{ 
width:150px; 
display:inline-block; 
margin: 60px 0 0 10px; 
padding: 0 20px 0 20px; 
vertical-align:top; 
right:0; 
bottom:0; 
top:0; 
line-height: 1.5em; 
} 

footer{ 
width: 60%; 
background-color: #700505; 
text-align: center; 
padding: 20px; 
padding-top: 10px; 
padding-bottom: 10px; 
margin: auto; 
margin-bottom: 20px; 
color: #ffffff; 
} 

http://jsfiddle.net/zsdutj9p/

,如果这是不是你想要的,或者你需要更多的帮助,请评论回来 - 我很乐意提供帮助。

1

这是你的问题:

postition: absolute; 

这将删除正常流动的侧边栏,从而使其无法影响其他元素。尝试更换与:

float: right; 
+0

侧边栏现在在页脚下方。 – user3002135 2014-10-18 18:27:03

+0

Alrighty,我正在研究它:) – kiaaanabal 2014-10-18 18:33:20

+0

您需要从您的部分类中删除宽度,然后添加float:left。然后添加清楚:两个到你的页脚。 – kiaaanabal 2014-10-18 18:37:03