什么是宽度自适应布局呢?

就是当浏览器窗口大小改变时,浏览器里的元素宽度也随之改变,从而达到自适应布局。

常见的宽度自适应布局有:

1、  两列:左边宽度不变,右边宽度自适应

2、  三列:左右两边宽度不变,中间部分自适应

3、  三列:左右两边宽度自适应,中间部分不变

一、利用div+css实现以上“自适应布局”

(1)两列:左边宽度固定,右边宽度自适应

利用div+float+margin,已在随笔‘float剖析’中讲解,具体代码和效果图见下:

<!DOCTYPE html>
    <head>
        <title>width_layout</title>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
        <style type="text/css">
            .content {
                min-width:300px;
            }
            .div1 {
                width:200px;
                height:300px;
                background:green;
                float:left;
            }
            .div2 {
                height:300px;
                background:pink;
                margin-left:200px;
            }
        </style>
    </head>
    <body>

        <div class="content">
            <div class="div1"></div>
            <div class="div2"></div>
        </div>
        
    </body>
</html>
View Code

相关文章:

  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-27
猜你喜欢
  • 2021-05-15
  • 2021-07-17
  • 2022-01-28
  • 2022-12-23
  • 2021-09-29
  • 2022-01-23
  • 2022-12-23
相关资源
相似解决方案