ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

前端一面中看似简单却让人容易忽略的题之(界面布局)

2019-11-22 15:07:47  阅读:271  来源: 互联网

标签:right 界面 center 前端 300px width background 看似 left


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

ps:一般大家开始会想到float布局,定位布局,但这样对于该题是不及格的,至少要3个以上才算是过的,5个才是优秀的。

解一:(float布局)

  <style>
    *{
      padding: 0;margin: 0;
    }
    .layout article div{
      min-height: 200px;
    }
    .left{
      width: 300px;float: left;background: green;
    }
    .right{
      float: right;background:pink;width: 300px;
    }
    .center{background: yellow;}
  </style>
</head>
<body>
  <section class="layout float">
    <article class="left-right-center">
       <div class="left">left</div>
       <div class="right">right</div>
       <div class="center">center</div>
    </article> 
  </section>
</body>

解二:(绝对定位布局)

 *{
      padding: 0;margin: 0;
    }
    .left-center-right>div{
      position: absolute;
      height: 300px;
    }
    .left{
      left:0;width: 300px;background: yellow;
    }
    .center{
      left:300px;right:300px;background: pink;
    }
    .right{
      right:0;
      width: 300px;
      background: red;
    }
  </style>
</head>
<body>
  <section class="layout absolute">
    <article class="left-center-right">
      <div class="left">left</div>
      <div class="center">center</div>
      <div class="right">right</div>
    </article>
  </section>
</body>

解三:(flex布局)

<style>
    *{
      padding: 0;margin: 0;
      height: 300px;
    }
    .left-center-right{
      display: flex;
    }
    .left{
      width:300px;background: yellow;
    }
    .center{
      flex:1;background: pink;
    }
    .right{
      width:300px;background: red;
    }
  </style>
</head>
<body>
  <section class="layout flexbox">
    <article class="left-center-right">
      <div class="left">left</div>
      <div class="center">center</div>
      <div class="right">right</div>
    </article>
  </section>
</body>

解四:(表格布局)

  <style>
    *{
      padding: 0;margin: 0;
    }
    .left-center-right{
      width: 100%;
      display: table;
      height: 200px;
    }
    .left-center-right>div{
      display: table-cell;
    }
    .left{
      width:300px;background: yellow;
    }
    .center{
      background: pink;
    }
    .right{
      width:300px;background: red;
    }
  </style>
</head>
<body>
  <section class="layout table">
    <article class="left-center-right">
      <div class="left">left</div>
      <div class="center">center</div>
      <div class="right">right</div>
    </article>
  </section>
</body>

解五:(网格布局)

  <style>
    *{
      padding: 0;margin: 0;
    }
    .left-center-right{
      width: 100%;
      display: grid;
      grid-template-rows: 200px;
      grid-template-columns: 300px auto 300px;
    }
    .left{
      background: yellow;
    }
    .center{
      background: pink;
    }
    .right{
      background: red;
    }
  </style>
</head>
<body>
  <section class="layout grid">
    <article class="left-center-right">
      <div class="left">left</div>
      <div class="center">center</div>
      <div class="right">right</div>
    </article>
  </section>
</body>

页面布局小结

  • 语义化掌握到位
  • 页面布局理解深刻
  • CSS基础知识扎实
  • 思维灵活且积极上进
  • 代码书写规范

页面布局变通

三栏布局

  • 左右宽度固定,中间自适应
  • 上下高度固定, 中间自适应

两栏布局

  • 左宽度固定,右自适应
  • 右宽固定,左自适应
  • 上高固定,下自适应
  • 下高度固定,上自适应
愿你成为终身学习者

标签:right,界面,center,前端,300px,width,background,看似,left
来源: https://www.cnblogs.com/homehtml/p/11911558.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有