zoukankan      html  css  js  c++  java
  • 两列布局的设置方法总结

    今天看到了这样一道题

    用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定、右侧部分宽度随浏览器宽度的变化而自适应变化 

    自己感觉有好几种方法,再此总结下:

     一、使用position:absolute方法,因为把元素设置为absolute,那元素就脱离了文档流,后面的元素就会占据他原来的位置:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <style type="text/css">    
        .side{width:190px;height:80px;background-color:#F00;position:absolute;}
        .exta{height:80px;background-color:#0f0;margin-left:190px; }        
    </style>
    
    <body>
        <div class="pd">   
            <div class="side">side</div>
            <div class="exta">exta</div>
        </div>
    </body>
    </html>

     

    二、使用float方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <style type="text/css">
        
       .side{width:190px;height:80px;background-color:#F00;
          float:left;
        }
        .exta{height:80px;background-color:#0f0; }//不能添加float:left;否则其宽度就会随内容变窄,不是随浏览器变化了
            
    </style>
    
    <body>
        <div class="pd">
            
            <div class="side">side</div>
            <div class="exta">exta</div>
        </div>
    </body>
    </html>

  • 相关阅读:
    计算机原理 3.4 补码一位乘法
    信号与系统 第二章(2.1)
    信号与系统(1.6、1.7)
    第17章 使用BIOS进行键盘输入和磁盘读写
    第16章 直接定址表
    聚类:主要聚类算法
    机器学习——输入空间、特征空间、输出空间
    机器学习——线性回归
    机器学习——梯度下降法
    深度学习——概率与信息论
  • 原文地址:https://www.cnblogs.com/happyLee/p/5087197.html
Copyright © 2011-2022 走看看