4

这是网站的简化布局:

#left_column {
  width: 200px;
  height: 100%;
}

<div id="left_column">
</div>

<div id="right_column">
  /* A bunch of 100px width photos that are being floated */
</div>

所以正如代码所暗示的,我有一个左列和一个右列。左列应为 200 像素宽并位于屏幕底部。右列应该占据其余的宽度,并将包含一堆浮动图像(有点像谷歌图像搜索的样子)。如何使用 CSS 和 HTML 做到这一点?我宁愿不使用 JavaScript。

4

5 回答 5

6

只需在右列的左边缘添加 200px 的边距,然后浮动左列。

#left_column {
  width: 200px;
  float: left;
}

#right_column {
  margin-left: 200px;
}

100% 的高度不会像你认为的那样起作用。

于 2012-09-05T03:49:37.563 回答
1

HTML:

<div id="leftcol">Demo text</div>
<div id="rightcol">More demo text</div>

​CSS:

#leftcol{
    position:fixed;
    left:0;
    top:0;
    height:100%;
    width:200px;
    background-color:yellow;
}

#rightcol{
    width:100%;
    -moz-box-sizing: border-box; /*The rest of the browsers support this now*/
    box-sizing: border-box;
    margin:0;
    padding:0;
    padding-left:200px;
    min-height:2000px;
    background-color:blue;
}
​

演示

于 2012-09-05T03:57:32.290 回答
0

试试这个小提琴 -

http://jsfiddle.net/hKyzT/

HTML

<div id="left_column">
    /* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated */
</div>

<div id="right_column">
/* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated *//* A bunch of 100px width photos that are being floated */
</div>

CSS

html, body, #wrapper, #left_column, #right_column { height: 100%; min-height: 100%; }


#left_column {
  width: 200px;
  float: left;
    border:1px solid green;
    height: 100%;
    min-height: 100%;
}

#right_column {
  margin-left: 200px; border:1px solid red;
}
于 2012-09-05T04:00:25.803 回答
0

我认为高度需要有一个像素值 - 百分比值似乎不会增加高度。

<style type="text/css">
#left_column {
    width: 20%;
    float:left;
    background-color:blue;
}
#right_column {
    width:80%;
    float:right;
    background-color:green;
}
div {
    height:1000px;
}
</style>

<div id="left_column">&nbsp;</div>
<div id="right_column">&nbsp;</div>
于 2012-09-05T04:14:56.340 回答
0

这些解决方案并不适合我。根据我在http://derpturkey.com/two-columns-with-one-fixed-width-and-one-variable-width/上读到的内容,我最终得到了以下内容:

#right_column {
    margin-left: 200px;
    float: left;
}

#left_column {
    float: left; 
    width: 200px;
    margin-left: -100%;
}
于 2014-06-27T00:08:54.923 回答