2014-09-24 93 views
-1

我有这些div。如何让左边的div对齐顶部?

enter image description here

的HTML如下。

<div id="full-size"> 
    <div id="left-content"> 

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

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

    </div> 
</div> 

那四个的div的CSS:

#full-size{ 
    height:100%; 
    width:100%; 
    overflow:auto; 
    top:5px; 
    position:relative; 
    padding: 1px 220px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    box-sizing: border-box; 
    display:table; 
    table-layout:fixed; 

    background-color:#F00; 
} 
#left-content { 
    width:190px; 
    border:1px solid #000; 
    overflow:auto; 
    padding: 5px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box;   
    background-color:#222; 
    margin-left: -200px; 
    float:left; 
    border:1px solid #000; 
    display:table-cell; 
} 
#center-content { 
    height:100%; 
    width: 100%; 
    border:1px solid #000; 
    overflow:auto; 
    display:inline-block; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box;  
    background-color:#222; 
    padding:5px; 
    display:table-cell;  
} 
#right-content { 
    width:190px; 
    border:1px solid #000; 
    overflow:auto; 
    float:right; 
    padding: 5px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box; 
    background-color:#222; 
    margin-right: -200px; 
    display:table-cell; 
    background-color:#222; 
    position: absolute; /*newly added*/ 
    right: 220px; /*newly added*/ 
    top: 5px;/*newly added*/ 
} 

每一件事响应完全像我想要的。左右分区的大小和位置都是固定的,中心分区必须始终适应边界分区之间的宽度。

我无法弄清楚,为什么左边的div总是停留在底部,我需要它始终位于正确的顶部。

这是我的问题,让左边的div留在上面。我不太了解css,但是这些都是我在Firefox,Chrome和IE中完成的工作。在他们所有的布局是一样的。

正如我所说我不明白那么多关于CSS,唯一我想要的是这种布局在大多数浏览器中工作。如果我需要,我不介意把它全部扔掉。我只需要一些工作。

UPDATE:

貌似这些工作就好了,如果孤立的,所以这里所有的东西和错误发生。

http://jsfiddle.net/wr0r8msu/1/

这只是发生在Firefox,IE和Chrome正在努力!

感谢您的任何帮助提前。

+0

从图像看,左边的div看起来像是对齐到底部。这里是提供的代码小提琴http://jsfiddle.net/wr0r8msu/ – Huangism 2014-09-24 19:53:26

+0

是的,这是左边,我的坏:P,小提琴的例子在那里工作,但不在这里:X – JaimeASV 2014-09-24 20:00:30

+0

好吧,所以问题不能在这里,必须是CSS的其余部分,我会把所有的代码放在小提琴中,并显示发生了什么 - http://jsfiddle.net/wr0r8msu/1/ – JaimeASV 2014-09-24 20:08:14

回答

0

使用位置:相对;而不是位置:绝对;当使用浮动,也许这将解决您的问题;-)

+0

我从右内容div中删除了绝对位置,它工作正常。 – 2014-09-24 20:27:23

+0

我犯了一个错误,它不是正确的,它是我想要忍受的左边那个。如果我放弃de的位置,他们都去底部 – JaimeASV 2014-09-24 20:34:53

0

我修改了你的CSS了一下。

#full-size{ 
    height:100%; 
    width:100%; 
    overflow:auto; 
    top:5px; 

    padding: 1px 220px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    box-sizing: border-box; 
    display:table; 
    table-layout:fixed; 

    background-color:#F00; 
} 
#left-content { 
    width:190px; 
    border:1px solid #000; 
    overflow:auto; 
    padding: 5px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box;   
    background-color:#222; 
    margin-left: -200px; 
    float:left; 
    border:1px solid #000; 
    display:table-cell; 
} 
#center-content { 
    height:100%; 
    width: 100%; 
    border:1px solid #000; 

    display:inline-block; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box;  
    background-color:#222; 
    padding:5px; 
    display:table-cell;  
} 
#right-content { 
    width:190px; 
    border:1px solid #000; 

    float:right; 
    padding: 5px; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;  
    box-sizing: border-box; 
    background-color:#222; 
    margin-right: -200px; 
    display:table-cell; 
    background-color:#222; 


} 

它没有固定或相对定位的div工作。

+0

你是否试图使这是一个响应式设计? – 2014-09-24 20:25:06

+0

刚刚阅读的问题

每件事情都是响应完全像我想要的。左右分区的大小和位置都是固定的,中心分区必须始终适应边界分区之间的宽度。

CodeFanatic 2014-09-24 20:27:20

+0

是的,这是桌面版本。你的CSS把它们都放在底部:( – JaimeASV 2014-09-24 20:28:29