2014-01-19 213 views
2

如何让绿色/黄色框显示在边栏旁边而不是下面? 绿色/黄色部分应该是100%的宽度。CSS:两个div并排

Screensho

这里是我的源代码: HTML

<div id="sidebar"> 

    </div> 

    <div class="header"> 

    </div> 

CSS

#sidebar{ 
    background-color: #404040; 
    height: 100%; 
    width: 50px; 
} 

.header{ 
    margin-left: 50px; 
    width: 100%; 
    height: 200px; 
    background-color: #808000; 
} 

回答

4

给这个CSS代码一试,我加了float财产。你也可以在这里使用这个jsfiddle,看看我改变了什么。
你也想看看的链接和尖端(约结算),其@Ian克拉克在给予:micro clearfix hack

#sidebar{ 
    background-color: #404040; 
    height: 100%; 
    width: 50px; 
    float: left; 
} 

.header{ 
    margin-left: 50px; 
    height: 200px; 
    background-color: #808000; 
} 

更多有关float检查:

+0

http://www.w3fools.com/ :) –

+0

任何其他谷歌搜索也会做到这一点,是的。 ;) – ztirom

+0

顺便说一句我只是看着你的代码。你不需要'float'头部有一个'position'或者'width' [(见JSFiddle)](http://jsfiddle.net/AVY7T/7/) –

6

添加display:inline-block#sidebar.header

+0

this ^^^^^^^^^^^ – thatOneGuy