zoukankan      html  css  js  c++  java
  • css常用布局

    1.一列布局

    html:

    <div class="header"></div>
    <div class="body"></div>
    <div class="footer"></div>

    css:

          .header{
            height: 100px;
            background: pink;
        }
        .body{
            height:500px;
            background: blue;
        }
        .footer{
            height:100px;
            background: #ddd;
        }

     2.两列布局(指定宽度)

    html:

        <div class="left"></div>
        <div class="right"></div>

    css:

           .left{
            width:20%;
            height: 500px;
            float: left;
            background:#333;
        }
        .right{
            width:80%;
            height:500px;
            float: left;
            background: pink
        }

    3.双飞翼布局(中间自适应,左右列固定宽度)

    html:

        <div class="main">
        <div class="cont"></div>
        </div>
        <div class="left"></div>
        <div class="right"></div>

    css:

           .main {
    	    float: left;
    	     100%;
    	    height: 500px;
    	}
    	.cont {
    	    height: 500px;
    	    background-color: aqua;
    	    margin-left: 300px;
    	    margin-right: 300px;
    	}
    	.left {
    	    float: left;
    	     300px;
    	    height: 500px;
    	    margin-left: -100%;
    	    background-color: pink;
    	}
    	.right {
    	    float: left;
    	     300px;
    	    height: 500px;
    	    margin-left: -300px;
    	    background-color: yellow;
    	}
    

     4.多栏布局

    栅格系统,是bootstrap常用的布局模式,下列就举个简单四栏例子

    html:

        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>

    css:

        .col{
            width:25%;
            height:500px;
            float: left;
            background: #ccc;
        }
        .col:nth-child(1){
            background: red;
        }
        .col:nth-child(2){
            background: green;
        }
        .col:nth-child(3){
            background: black;
        }
        .col:nth-child(4){
            background: yellow;
        }

    常见还有column-count、column-gap、column-rule、columns

    5.弹性布局(flex)
    html:
       <ul>
            <li><a href="#">菜单1</a></li>
            <li><a href="#">菜单2</a></li>
            <li><a href="#">菜单3</a></li>
            <li><a href="#">菜单4</a></li>
        </ul>

      css:

        ul{
            display: flex;
            height:100px;
            100%;
        }
        ul li{
            flex: auto;
            list-style:none;
            text-align:center;
            border:1px solid red;
        }
    

      6.瀑布式布局

  • 相关阅读:
    4.8日学习
    Apache安装
    HTML5 review
    个人阅读作业LAST
    个人阅读作业Week7
    结对编程:界面模块总结
    个人博客作业Week3
    结对编程博客
    个人博客week2
    软工第一次作业简单总结
  • 原文地址:https://www.cnblogs.com/yewook/p/8456596.html
Copyright © 2011-2022 走看看