双飞翼和圣杯布局

简介

布局是写一个网页的开始,也是前端的起步,必须要掌握好一些常见的布局,如圣杯布局和双飞翼布局。Flex就不讲了,用flex很简单,下面讲传统的float。

双飞翼布局

直接上代码:

<template>
  <div id="app">
    <div id="header"></div>
    <div id="contain">
      <div id="center">
        能正常显示在中间!!
      </div>
    </div>
    <div id="left"></div>
    <div id="right"></div>

    <div id="footer"></div>
  </div>
</template>

<script>
  import bubble from "./asset/compents/bubble";
  export default {
    name: 'App'
  }

</script>

<style>
  #app{
    min-width: 500px;
  }
  #header{
    width:100%;
    height:40px;
    background: yellow;
  }
  #contain{
    width: 100%;
    float:left;
  }
  #center{
    height: 500px;
    margin-left: 140px;
    margin-right: 240px;
    background: green;
  }
  #left{
    width:140px;
    height: 500px;
    background: blue;
    margin-left: -100%;
    float: left;
  }
  #right{
    width:240px;
    height: 500px;
    background: red;
    margin-left: -240px;
    float: left;
  }
  #footer{
    width:100%;
    height: 40px;
    background: black;
    clear:both;
  }
</style>
要点

使用float进行布局,关键就是要用好margin,取负值时盒子会进行“偏移”,所以这种经典设计的原理也很就很好理解了。

header和footer就不用提了,主要是中间的三栏布局。

三栏均设置浮动,先写中间盒子,用width:100%撑开,然后左栏偏移100%强行嵌入(覆盖)到中间盒子的左边,右栏偏移自身尺寸强行嵌入(覆盖)到中间盒子的右边。这样三栏目就成形了。

但是中间栏有个问题,文字会从最左开始,刚好被挡住了,所以中间栏加一个一个盒子,设置左右边距不被两侧挡住就行。

在这里插入图片描述

圣杯布局

圣杯布局的效果和上面一样。方法略有不同。代码如下:

<template>
  <div id="app">
    <div id="header"></div>
    <div id="container">
      <div id="center">
        能正常显示在中间!!
      </div>
      <div id="left"></div>
      <div id="right"></div>
    </div>
    <div id="footer"></div>
  </div>
</template>

<script>
  import bubble from "./asset/compents/bubble";
  export default {
    name: 'App'
  }

</script>

<style>
  #app{
    min-width: 500px;
  }
  #header {
    width: 100%;
    height: 40px;
    background: yellow;
  }
  #footer{
    width:100%;
    height: 40px;
    background: black;
    clear:both;
  }
  #container{
    padding-left:140px;
    padding-right:240px;
  }
  #center{
    width:100%;
    background: green;
    height: 500px;
    float:left;
  }
  #left{
    width:140px;
    height: 500px;
    background: blue;
    margin-left: -100%;
    position: relative;
    left: -140px;
    float:left;
  }
  #right{
    width:240px;
    height: 500px;
    background: right;
    float:left;
    background: red;
    margin-left: -240px;
    position: relative;
    left: 240px;
  }
</style>
要点

与双飞翼类似,此时用padding撑开位置给左右,而不是直接嵌入。不过要借用relative就行位移。

在这里插入图片描述

List item

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值