css - 为内容创建动态增长的宽度

标签 css html

您好,我知道有很多关于内容的动态宽度的问题。但是这个具体问题我找不到好的答案。

我的网站(一些页面)有以下设置

         +--------------+---------------------------------+
     |              |                                 |
     |  Sidebar     |       Content                   |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     |              |                                 |
     +--------------+---------------------------------+

总宽度为980px

但是在其中一些页面上我没有使用侧边栏,所以左侧有空白区域..当没有侧边栏时,如何让内容页面向左流动来解决这个问题?

     +--------------+---------------------------------+
     |                                                |
     |                      Content                   |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     |                                                |
     +--------------+---------------------------------+

我有如下的html结构

我给 aside 和 content div 都设置了固定宽度,aside 左边有一个 float ,内容右边有一个 float 。

有什么简单的方法可以做到这一点吗?

最佳答案

HTML

<div id="main">
    <div id="sidebar"></div>
    <div id="content"></div>
</div>

CSS

#main{
    width: 980px;
    margin: 0 auto;
}
#main:after{
    content: '';
    display: block;
    clear: both;
}
#sidebar{
    float: left;
    width: 200px;
}
#content{overflow: hidden;}

关于css - 为内容创建动态增长的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18956464/

相关文章:

javascript - 检测图像输入加载

javascript - 直接从 AngularJS 中的嵌套数组获取数据

html - 如何使用 CSS 隐藏 UL 的前 3 个 child

jquery - 无论表中的 TH 是什么,都扩展 TR

html - 不能在列中居中内容

DIV 元素中的 HTML 表格随着浏览器调整大小而不断移动

javascript - 如何将 "push notifications"发送到特定用户网页?

javascript - 在页面(哈希)链接中,获取第一个可见元素

html - css overflow auto 中的相同页面 anchor

jquery - 我正在努力让 .children() 工作