• 前端面试题:编写html和css实现三栏布局,其中左,右宽度固定,中间宽度随着外层宽度变化自适应变化


    方法一

    绝对定位

    <!DOCTYPE html>
    <html>
      <head>
        <title>三列布局</title>
        
      </head>
      <body>
    
        <div class="wrap">
          <div>三列布局1</div>
          <div class="one col-3-one">one</div>
          <div class="three col-3-three">three</div>
          <div class="two col-3-two">two</div>
        </div>
    
      </body>
    </html>
    

      css样式

     1 .wrap {
     2   position: relative;
     3 }
     4 
     5 .one{
     6   width: 40px;
     7   height:100px;
     8   background: blue;
     9 }
    10 
    11 .two {
    12   height:100px;
    13   background: yellow;
    14 }
    15 
    16 .three {
    17   height:100px;
    18   width: 40px;
    19   background: red;
    20 }
    21 
    22 .col-3-one {
    23   position: absolute;
    24   left: 0px;
    25 }
    26 
    27 .col-3-three {
    28   position: absolute;
    29   right: 0px;
    30 }
    31 
    32 .col-3-two {
    33   position: static;
    34   margin-left: 40px;
    35   margin-right: 40px;
    36 }

    方法二:

    浮动

     1 <!DOCTYPE html>
     2 <html>
     3   <head>
     4     <title>三列布局</title>
     5   </head>
     6   <body>
     7 
     8 
     9     <div >
    10       <div>三列布局2</div>
    11       <div class="one col-3-one-float">one</div>
    12       <div class="three col-3-three-float">three</div>
    13       <div class="two col-3-two">two</div>
    14     </div>
    15   </body>
    16 </html>

    css代码

     1 .wrap {
     2   position: relative;
     3 }
     4 
     5 .one{
     6   width: 40px;
     7   height:100px;
     8   background: blue;
     9 }
    10 
    11 .two {
    12   height:100px;
    13   background: yellow;
    14 }
    15 
    16 .three {
    17   height:100px;
    18   width: 40px;
    19   background: red;
    20 }
    21 
    22 .col-3-two {
    23   position: static;
    24   margin-left: 40px;
    25   margin-right: 40px;
    26 }
    27 
    28 .col-3-one-float {
    29   float: left;
    30 
    31 }
    32 
    33 .col-3-three-float {
    34   float: right;
    35 }

     注意第二种方法(浮动)

      在html的布局中,第三个(最右边的)div必须放在中间,也就是说第三个浮动流必须放在正常流的上面,否则,会导致第二个div会占满屏幕,而第三个脱离文档流的div被直接挤到下方。

  • 相关阅读:
    ApkAnalyser 一键提取安卓应用中可能存在的敏感信息(URLhash等)
    PostgreSQL创建只读权限的用户
    记一次 Centos7 Postgresql v11 数据库备份、还原
    Linux下安装pgadmin,并外部访问
    CentOS7中安装PostgreSQL客户端
    java.io.FileNotFoundException: Too many open files
    centos批量删除文件
    Centos7下Redis缓存清理_FZlion
    解决启动Apache遇到的问题Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:8888
    CentOS 卸载软件
  • 原文地址:https://www.cnblogs.com/lxk0301/p/6477450.html
Copyright © 2020-2023  润新知