zoukankan      html  css  js  c++  java
  • 如何使用CSS进行网页布局(HTML/CSS)

    什么叫做布局?

    又称为版式布局,是网页UI设计师将有限的视觉元素进行有机的排列组合。

    题目:假设高度已知,请写出三栏布局,其中左栏和右栏宽度各为300px,中间自适应

    1、浮动布局

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Layout</title>
        <style>
          html * {
            margin: 0;
            padding: 0;
          }
          .layout article div {
            min-height: 100px;
          }
          .layout.float .left {
            float: left;
            width: 300px;
            background: red;
          }
          .layout.float .right {
            float: right;
            width: 300px;
            background: blue;
          }
          .layout.float .center {
            background: yellow;
          }
        </style>
      </head>
      <body>
        <section class="layout float">
          <article class="left-right-center">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">
              <h1>浮动解决方案</h1>
              <p>
                这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分
              </p>
            </div>
          </article>
        </section>
      </body>
    </html>
    View Code

    2、绝对定位布局

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Layout</title>
        <style>
          html * {
            margin: 0;
            padding: 0;
          }
          .layout article div {
            min-height: 100px;
          }
          .layout.absolute .left-center-right>div {
            position: absolute;
          }
          .layout.absolute .left {
            left: 0;
            width: 300px;
            background: red;
          }
          .layout.absolute .center {
            left: 310px;
            right: 310px;
            background: yellow;
          }
          .layout.absolute .right {
            right: 0;
            width: 300px;
            background: blue;
          }
        </style>
      </head>
      <body>
        <section class="layout absolute">
          <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
              <h1>绝对定位解决方案</h1>
              <p>
                这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分
              </p>
            </div>
            <div class="right"></div>
          </article>
        </section>
      </body>
    </html>
    View Code

    3、flexbox布局

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Layout</title>
        <style>
          html * {
            margin: 0;
            padding: 0;
          }
          .layout article div {
            min-height: 100px;
          }
          .layout.flexbox .left-center-right {
            display: flex;
          }
          .layout.flexbox .left {
            width: 300px;
            background: red;
          }
          .layout.flexbox .center {
            flex: 1;
            background: green;
          }
          .layout.flexbox .right {
            width: 300px;
            background: yellow;
          }
        </style>
      </head>
      <body>
        <section class="layout flexbox">
          <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
              <h1>flexbox解决方案</h1>
              <p>
                这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分
              </p>
            </div>
            <div class="right"></div>
          </article>
        </section>
      </body>
    </html>
    View Code

    4、表格布局

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Layout</title>
        <style>
          html * {
            margin: 0;
            padding: 0;
          }
          .layout article div {
            min-height: 100px;
          }
          .layout.table .left-center-right {
            width: 100%;
            display: table;
            height: 100px;
          }
          .layout.table .left-center-right>div {
            display: table-cell;
          }
          .layout.table .left {
            width: 300px;
            background: black;
          }
          .layout.table .center {
            background: green;
          }
          .layout.table .right {
            width: 300px;
            background: burlywood;
          }
        </style>
      </head>
      <body>
        <section class="layout table">
          <article class="left-center-right">
            <div class="left"></div>
            <div class="center">
              <h1>表格布局解决方案</h1>
              <p>
                这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分 这是三栏布局中间部分
              </p>
            </div>
            <div class="right"></div>
          </article>
        </section>
      </body>
    </html>
    View Code

    5、网格布局

  • 相关阅读:
    C++ VC实现对话框窗口任意分割
    C++ 关于滚动条的滚动问题
    C++ 自定义控件的移植(将在其它程序中设计的自定义控件,移植到现在的系统中)
    C++ 动态创建按钮及 按钮的消息响应
    C++ Custom Control控件 向父窗体发送对应的消息
    C++ MFC 改变控件大小和位置
    C++ 使用VS2010创建MFC ActiveX工程项目
    VC++ 自定义控件的建立及使用方法
    C++ CTreeview的checkbox使用方法
    C++ vc中怎么使用SendMessage自定义消息函数
  • 原文地址:https://www.cnblogs.com/fengxiongZz/p/8146641.html
Copyright © 2011-2022 走看看