zoukankan      html  css  js  c++  java
  • CSS多列布局(实例)

    前言

    1. 一列布局
    2. 二列布局
    3. 三列布局

    1 一列布局

    • 一列布局:
      HTML部分
      <!DOCTYPE html>
      <html>
      <head>
      <meta charset="utf-8" />
      <title>一列布局</title>
      </head>
      <body>
      <div class="head">head</div>
      <div class="main">main</div>
      <div class="foot">foot</div>
      </body>
      </html>
      
      
      CSS部分
      div{text-align: center;}
      .head{height: 60px;background-color:#fae1e1;}
      .main{margin: 0 auto;height:300px;background-color:#e6686a;}
      .foot{margin: 0 auto;background-color:red;}
    • 效果图如下:

    2 二列布局

    • 二列布局代码如下(即左右布局),二列布局有多种方法,float+margin(一侧定宽,一侧自动)、position+margin(一侧定宽,一侧自动)、float+负margin(一侧定宽,一侧自动)等,本篇用的是设定两栏的宽度的百分比,随宽度自适应变化代码如下:
      HTML部分
      <!DOCTYPE html>
      <html>
      <head>
      <title>二列布局</title>
      </head>
      <body>
      <div class="main">
      <div class="left">left</div>
      <div class="right">right</div>
      </div>
      </body>
      </html
      
      CSS部分
      body{ margin:0; padding:0; font-size:20px; font-weight:bold}
      div{ text-align:center; line-height:50px}
      .main{ 80%; height:400px; margin:0 auto}
      .left{ 20%; height:400px; background:#e6686a; float:left}
      .right{ 80%; height:400px; background:#fae1e1; float:right}
    • 效果图如下:

    3 三列布局

    • 三列布局(即左中右布局),三列布局有多种方法,float+margin(两侧定宽,中间自适应)、position+margin(两侧定宽,中间自适应)、float+负margin(两侧定宽,中间自适应)、float+position+margin(两侧自动,中间定宽)、position+margin(两侧自动,中间定宽),本篇用的是float+margin(两侧定宽,中间自适应),代码如下:
      HTML部分
      <!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <title>JS Bin</title>
      </head>
      <body>
      <div class="left">left</div>
      <div class="center">main</div>
      <div class="right">right</div>
      </body>
      </html>
      
      CSS部分
      body{ margin:0; padding:0; font-weight:bold}
      div{ line-height:40px}
      .left{height:400px; 200px; position: absolute; left:0; top:0;background:#fae1e1;}
      .right{ height:400px; 200px; position:absolute; top:0;right:0;; background:#fae1e1}
      .center{ height:400px; margin:0 200px; background:#e6686a}
    • 效果图如下:

  • 相关阅读:
    显存与纹理内存详解
    UE4 编译虚幻引擎
    利用Lua脚本语言制作魔兽WOW插件
    详解液晶面板制造全过程
    游戏引擎剖析
    数据库常见面试题
    Selenium Webdriver元素定位的八种常用方式
    Windows 安装 Mongodb
    Redis在windows下安装过程
    python 关于一个懒惰和非懒惰的
  • 原文地址:https://www.cnblogs.com/nolaaaaa/p/8849187.html
Copyright © 2011-2022 走看看