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

Vue中集中常见的布局方式

  • 布局叠加
    在这里插入图片描述
  • 完整代码
  • 最外层的Container设置为relative,内部的几个box设置为absolute
<template>
  <div class="container">
    <div class="box box1">Box 1</div>
    <div class="box box2">Box 2</div>
    <div class="box box3">Box 3</div>
  </div>
</template>

<script>
export default {
  // 组件逻辑
};
</script>

<style scoped>
.container {
  position: relative;
  width: 300px;
  height: 300px;
  background: #888888;
}

.box {
  position: absolute;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
}

.box1 {
  background-color: red;
  top: 50px;
  left: 50px;
}

.box2 {
  background-color: blue;
  top: 100px;
  left: 100px;
}

.box3 {
  background-color: green;
  top: 150px;
  left: 150px;
}
</style>
  • 如果Container不设置relative则,内部的box则会相对整个页面进行布局
    在这里插入图片描述
  • 使用绝对布局,一个居中,一个居右。
    在这里插入图片描述
  • 其中box1,左上距离父布局50%,然后自身偏移50%,使其居中
.box1 {
  background-color: red;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
  • 完整代码
<template>

  <div class="container">
    <div class="box box1">Box 1</div>
    <div class="box box3">Box 3</div>
  </div>

</template>

<script>
export default {
  // 组件逻辑
};
</script>

<style scoped>
.container {
  position: relative;
  width: 300px;
  height: 300px;
  background: #888888;
}

.box {
  position: absolute;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
}

.box1 {
  background-color: red;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}

.box3 {
  background-color: green;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}
</style>
  • 水平方向线性布局
    在这里插入图片描述
  • 设置父布局 display: flex; flex-direction: row;子布局取消position: absolute;即可
.container {
  display: flex;
  flex-direction: row;
  width: 300px;
  height: 300px;
  background: #888888;
}

.box {
  //position: absolute;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
}

http://www.kler.cn/news/323228.html

相关文章:

  • 赋值运算符重载
  • python 实现harmonic series调和级数算法
  • 现代LLM基本技术整理
  • Android13高通平台拨打/接听只有免提模式,无听筒模式
  • unsqueeze函数、isinstance函数、_VF模块、squeeze函数
  • 爆火!大模型算法岗 100 道面试题全解析,赶紧收藏!
  • STM32CUBEIDE FreeRTOS操作教程(五):mutex互斥信号量
  • Python中的null是什么?
  • 基于SpringBoot+Vue的小儿推拿培训管理系统
  • MySQL按照经纬度排序 查询出商家信息
  • Cisco ASA 9.22.1 发布下载,新增功能概览
  • Mysql—主从复制的slave添加及延迟回放
  • 2024年7月大众点评乌鲁木齐美食店铺基础信息
  • 物理学基础精解【26】
  • .NET MAUI(.NET Multi-platform App UI)上下文菜单
  • 【Redis入门到精通六】在Spring Boot中集成Redis(含配置和操作演示)
  • 机器学习查漏补缺(5)
  • 【刷题5】在排序数组中查找元素的第一个和最后一个位置
  • Android CCodec Codec2 (十五)C2DmaBufAllocator
  • 自动化办公-python中的open()函数
  • 深入理解 Nuxt.js 中的 app:error:cleared 钩子
  • 【hot100-java】【划分字母区间】
  • 消息中间件 Kafka 快速入门与实战
  • 让具身智能更快更强!华东师大上大提出TinyVLA:高效视觉-语言-动作模型,遥遥领先
  • mysql复合查询 -- 合并查询(union,union all)
  • 指令个人记录
  • Lab1:虚拟机kolla安装部署openstack,并创建实例
  • [大语言模型-论文精读] MoRAG - 基于多部分融合的检索增强型人体动作生成
  • 海尔嵌入式硬件校招面试题及参考答案
  • Python in Excel作图分析实战!