0

我正在尝试制作一个类似于 twitter 的内容 div,它旁边有一个似乎被覆盖的侧边栏。如何使用 css 实现这一点?

4

3 回答 3

0

将其存档的一种技术称为仿列。看看... http://www.alistapart.com/articles/fauxcolumns/

也许否则你可以使用 min-height/max-height

于 2011-02-01T19:18:52.943 回答
0

创建始终与内容区域高度相同的侧边栏的最常用方法本质上是创建“假”或人造侧边栏。这是一个例子:

<div id="wrapper">

     <div id="content">
          <p>My Content</p>
     </div>

     <div id="sidebar">
          <p>Sidebar</p>
     </div>

</div>

您的样式表看起来像这样:

#wrapper {
     background: url(faux_sidebar.jpg) top right repeat-y;
}

#sidebar {
     float:right;
     width:200px;
}

图像 faux_sidebar.jpg 将与侧边栏具有相同的宽度(对于某些填充可能会更宽一些)。这个想法是#wrapper 的背景是一个图像,它是侧边栏的背景。然后侧边栏像往常一样漂浮在内容旁边,并且因为#wrapper 将扩展以容纳其两个子项中较高的一个,所以侧边栏将始终与内容的高度相同。

于 2011-02-01T19:23:17.513 回答
0

我更喜欢这个:

HTML:

<div class="surround">
    <div class="main">
        <br /><br />
        <br /><br />
        <br /><br />
        <br /><br />
        <br /><br />
        <br /><br />
    </div>
    <div class="side">
        /* allways the same height like main */
    </div>
</div>

CSS:

.surround
{
    display: table;
    width:900px;
    min-height:200px;
}

.main{
    display:table-cell;
    width:600px;
    min-height:200px;
    background-color:blue;
}
.side{
    display:table-cell;
    width:300px;
    min-height:200px;
    background-color:red;
}
于 2011-02-01T20:13:54.327 回答