html - 侧边栏下方的主要内容。 float 不起作用?

标签 html css styles frontend

我的布局如下 -

.page-wrapper {
  height: 100%;
  min-height: 970px;
  position: relative;
}

.pageheader {
  min-height: 50px;
  position: fixed;
  min-width: 100%;
}

.navbar-fixed-top {
  top: 0;
}

.page-sidebar {
  float: left;
  width: 180px;
  top: 0;
  overflow: auto;
}

.page-content {
  min-height: 970px;
  float: left;
}

footer {
  width: 100%;
  text-align: center;
  position: relative;
}
<div class="page-wrapper">
  <div>
    <div id="header" class="pageheader navbar navbar-fixed-top">
      Navbar Top
    </div>
    <div class="clearfix"></div>
  </div>
  <div class="content-wrapper">
    <div>
      <div class="clearfix"></div>
      <div id=".navbar-collapse" class="page-sidebar">
        Navbar Side
      </div>
      <div class="clearfix"></div>
    </div>
    <div>
      <div id="content" class="page-content">
        Content
      </div>
    </div>
    <div>
      <footer id="footer">
        Foter
      </footer>
    </div>
  </div>

我的主要内容包装器位于边栏下方,页脚位于中间某处。我试过使用

display:inline-flex

content-wrapper 上,它将 page-content 放在 sidebar 旁边,但页脚仍保留在页面中间。请帮我解决这个问题。

最佳答案

您可以使用 calc 设置 page-content 宽度。检查下面更新的代码段

body {
    margin: 0px;
}
.page-wrapper {
    height: 100%;
    min-height: 970px;
    position: relative;
    width: 100%;
    padding-top: 50px;
    display: block;
}    
.pageheader {
    min-height: 50px;
    position: fixed;
    min-width: 100%;
    background: red;
}
.navbar-fixed-top {
    top: 0;
}
.content-wrapper {
    background: grey;
    float: left;
    width: 100%;
}
.page-sidebar {
    float: left;
    width: 180px;
    overflow: auto;
}
.page-content {
    min-height: 970px;
    float:left;
    background: green;
    width: calc(100% - 180px);
}
footer {
    width: 100%;
    text-align: center;
    position:relative;
    background: black;
    clear: both;
}
<div class="page-wrapper">
    <div>
        <div id="header" class="pageheader navbar navbar-fixed-top">    header<br/>
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="content-wrapper">
        <div>   
            <div class="clearfix"></div>
            <div id=".navbar-collapse" class="page-sidebar">sidebar</div>
            <div class="clearfix"></div>
        </div>
        <div>
            <div id="content" class="page-content">    content 
        </div>
    </div> 
            <div class="clearfix"></div> 
    <div>
        <footer id="footer">footer
        </footer> 
    </div>
</div>

关于html - 侧边栏下方的主要内容。 float 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46215270/

相关文章:

HTML slider 颜色和标记

javascript - 只要它们具有相同的类,如何组合标签

html - 不同操作系统/屏幕的不同代码

javascript - 无法使字体大小响应

html - 多个 CSS 样式相互干扰

javascript - 同时有两个事件选项卡!我该怎么做?

html - float 元素有上边距

CSS更改 child 名字的高度

html - IE窗口缩小时DIV溢出外层DIV(Restore-Down)

html - 在本地主机上没有填充但在网络服务器上没有填充?