如何用DIV+CSS布局例子

html-css011

如何用DIV+CSS布局例子,第1张

举例(两列布局):

<!DOCTYPE html>

<html>

 

    <head>

        <meta charset="utf-8">

        <title>练习使用HTML</title>

        <link rel="stylesheet" href="css/index.css" />

    </head>

 

    <body>

        <!-- DIV -->

        <div id="d1">

            <span>DIV</span>

        </div>

        <div id="d2">

            <span>DIV</span>

        </div>

        <div id="d3">

            <span>DIV</span>

        </div>

    </body>

 

</html>

css代码:

css文件:

#d1{

    position: absolute

    width: 100px

    height: 100px

    background-color: red

}

#d2{

    position: absolute

    margin-left: 100px

    width: 500px

    height: 100px

    background-color: blue

}

#d3{

    position: absolute

    margin-top: 100px

    width: 600px

    height: 100px

    background-color: yellow

}

效果:

四种方式

比如想要做这样一个布局,有哪几种方式。

最简单、最快捷的方式。

element-ui提供的布局容器,el-header头标签,有height属性。el-aside左侧边栏标签,有width属性。el-footer底部标签,有height属性。其他样式可以通过class进行控制。

相对简单的方式。

利用el-col将每行分为24等分的特性,进行布局。其他属性通过class进行控制。

原生css布局的方式,float布局,也是最基础的方式。

将aside向左浮动,固定好宽度。main向右浮动,注意固定好宽度是 100vw - 左侧边栏的宽度 ,注意高度是 100vh - 上下header和footer高度之和 。footer也由于浮动而被挤到到最下面,这边指定float为left、right都是可以的,都可以达到浮动到最下方的效果。

原生css布局的方式,position布局,也是最基础的方式。

sideBar设置好宽度,利用绝对定位将固定在最左边(由于是绝对定位,所以注意已经脱离了文档流)。main设置margin-left为侧边栏宽度,这样就可以使得main不会被遮挡。footer设置为固定定位,bottom为0固定在底部。其他height、width的值也要注意计算哦~