css - 自适应布局的问题,求解答

查看:127
本文介绍了css - 自适应布局的问题,求解答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如下面截图,每一块是固定的大小,给了一个margin-right是百分比。如何在不用bootstrap如何实现当大小从1200px~1000px,始终保持这样的布局,实现自适应。margin-right可以变化。

解决方案

1.可以使用flex布局
2.使用CSS的calc函数
每一个单元宽度固定

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    /*margin-right值为calc((100% - 4*item宽度/3)*/
    .item{
      width:100px;
      margin-right: calc((100% - 4*100px)/3);
      background-color: green;
      height: 100%;
      display: inline-block;
      font-size: 16px;
    }
    .item:last-child{
        margin-right:0px;
    }

    .container{
      position: absolute;
      left:10px;
      top:10px;
      width: 100%;
      height: 300px;
      font-size:0;
    }
    </style>
</head>
<body>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
  </div>
</body>
</html>

这篇关于css - 自适应布局的问题,求解答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆