当前位置: 首页 > news >正文

圣杯布局的实现方式

1.什么是圣杯布局?

左右盒子固定,中间盒子自适应

2.实现方式

(1)flex布局

思路:左右盒子给固定的宽高,中间盒子flex:1

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  .box {
    display: flex;
    width: 100vw;
    height: 100vh;
  }

  .one {
    width: 20vw;
    height: 20vh;
    background-color: yellowgreen;
  }

  .two {
    flex: 1;
    height: 20vh;
    background-color: plum;
  }

  .three {
    width: 20vw;
    height: 20vh;
    background-color: pink;
  }

</style>

<body>

<div class="box">
  <div class="one">盒子1</div>
  <div class="two">盒子2</div>
  <div class="three">盒子3</div>
</div>

</body>

</html>

(2)浮动

思路:左盒子左浮,右盒子右浮,中间盒子不动,要注意布局顺序,盒子3在盒子2前面

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  .box {
    width: 100vw;
    height: 100vh;
  }

  .one {
    float: left;
    width: 20vw;
    height: 20vh;
    background-color: yellowgreen;
  }

  .two {
    height: 20vh;
    background-color: yellow;
  }

  .three {
    float: right;
    width: 20vw;
    height: 20vh;
    background-color: pink;
  }
</style>

<body>

<div class="box">
  <div class="one">盒子1</div>
  <div class="three">盒子3</div>
  <div class="two">盒子2</div>
</div>

</body>

</html>

(3)定位

思路:父级相对定位、左右绝对定位,中间盒子不动

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  .box {
    position: relative;
    width: 100vw;
    height: 100vh;
  }

  .one {
    position: absolute;
    top: 0;
    left: 0;
    width: 20vw;
    height: 20vh;
    background-color: yellowgreen;
  }

  .two {
    height: 20vh;
    background-color: plum;
  }

  .three {
    position: absolute;
    top: 0;
    right: 0;
    width: 20vw;
    height: 20vh;
    background-color: pink;
  }
</style>

<body>
  <div class="box">
    <div class="one">盒子1</div>
    <div class="two">盒子2</div>
    <div class="three">盒子3</div>
  </div>
</body>

</html>

http://www.lryc.cn/news/26080.html

相关文章:

  • RecastDemo用法
  • IIC总线式驱动开发(mpu6050)(二)
  • 盘点一下那些远程办公的神仙公司
  • Spring Cloud Alibaba全家桶(四)——微服务调用组件Feign
  • 安装pytorch
  • 自动化测试 Appium之Python运行环境搭建 Part2
  • LeetCode 2 - 两数相加
  • 用Python实现九九乘法表的几种方式,最简单只需一行代码
  • 入职外包三个月,我提桶跑路了
  • 企业邮箱对企业有哪些好处以及便捷性
  • ConvNeXt V2实战:使用ConvNeXt V2实现图像分类任务(一)
  • 3.2 报错整理
  • 从0开始学python -46
  • JavaScript事件委托机制详解
  • 【项目实战】MySQL中union和union all的相同点与不同点
  • ChatGPT最牛应用,让它帮你更新网站新闻吧!
  • 乌班图安装kvm并配置网络
  • 蓝库云|ERP系统在企业数字化转型中最常用的八大功能
  • Pytorch学习笔记#1:拟合函数/梯度下降
  • 挑战图像处理100问(24)——伽玛校正
  • 高级信息系统项目管理师(高项)软考论文评分标准(附历年高项论文题目汇总)
  • MySQL实战记录篇2
  • C++实现AVL树
  • 高并发语言erlang编程初步
  • springboot 问题记录
  • 【PAT甲级题解记录】1034 Head of a Gang (30 分)
  • Python搭建一个steam钓鱼网站,只要免费领游戏,一钓一个准
  • maven 私服nexus安装与使用
  • 详解数据结构中的顺序表的手动实现,顺序表功能接口【数据结构】
  • 【二】kubernetes操作