html - 如何使用双侧边栏设置 html 布局的样式

标签 html css

我正在尝试使用双侧栏设计布局样式。左栏和右栏。我试过用下面的 html/css 解决它。下面是有人可以帮助我的代码。 example of the layout

下面的 CSS 代码

    #wrap {
      margin: auto;
      position: relative;
      width: 700px;
      border: 3px solid black;
      background-color: grey;
      height: 700px;
      padding: 10px
    }

    #header {
      margin: auto;
      background-color: white;
      height: 70px;
      padding: 10px;
    }

    #left {
      margin: auto;
      width: 150px;
      height: 70%;
      background-color: white;
      float: left;
      padding: 10px;
    }

    #content{
      background-color: red;
    }

    #right {
      margin: auto;
      width: 150px;
      height: 70%;
      background-color: white;
      float: right;
      padding: 10px;
    }

    #footer {
      margin: auto;
      height: 10%;
      background-color: blue;
      padding: 10px;
    }

这是 HTML

    <div id="wrap">
        <div id="header">
        <p>header will be here</p>
        </div>
        <div id="left">
            <ul>
              <li><a href="#">Link 1</a></li>
              <li><a href="#">Link 2</a></li>
              <li><a href="#">Link 3</a></li>
            </ul>
        </div>
        <div id="content">
            content here
        </div>
        <div id="right">
            <p> name and address here</p>
        </div>
        <div id="footer">
            <p> copyright </p>
        </div>

    </div>

最佳答案

这就是所谓的 chalice 布局,它很容易用 Flexbox 解决

#wrap {
  margin: auto;
  position: relative;
  width: 90%;
  border: 3px solid black;
  background-color: grey;
  height: 700px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}
#header {
  background-color: pink;
  height: 70px;
  padding: 10px;
}
.center {
  flex: 1;
  display: flex;
}
#left {
  width: 150px;
  background-color: goldenrod;
  padding: 10px;
}
#content {
  background-color: red;
  flex: 1
}
#right {
  width: 150px;
  background-color: #c0ffee;
  padding: 10px;
}
#footer {
  height: 10%;
  background-color: blue;
  padding: 10px;
}
<div id="wrap">
  <div id="header">
    <p>header will be here</p>
  </div>
  <div class="center">
    <div id="left">
      <ul>
        <li><a href="#">Link 1</a>
        </li>
        <li><a href="#">Link 2</a>
        </li>
        <li><a href="#">Link 3</a>
        </li>
      </ul>
    </div>
    <div id="content">
      content here
    </div>
    <div id="right">
      <p>name and address here</p>
    </div>
  </div>
  <div id="footer">
    <p>copyright</p>
  </div>

</div>

关于html - 如何使用双侧边栏设置 html 布局的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38746004/

相关文章:

php - 在自定义 PHP CMS 中呈现头部元标记

HTML 将 css 背景图像替换为视频

javascript - Bootstrap - 输入不考虑网格大小/约束

javascript - 有没有办法在 Django 中显示登录错误?

javascript - 如何排除所选 parent 的 child

javascript - HTML 5 模板标签(页面刷新)

html - div 中图像下的额外填充?

html - 最小高度 :100% on html `div` messes up footer

html - CSS 网格 - 基于行的放置

jquery - 将焦点切换到另一个元素的焦点显示的字段