display布局实现一侧的盒子高度与另一侧盒子的高度等高

实现两边容器的高度等高主要是用 align-items: stretch 这个属性

stretch 拉伸: 子元素没有高度或高度为auto,将占满整个容器的高度

<template>
	<div>
		<h3>我是测试页面</h3>
		<div class="container">
			<div class="left-column"></div>
			<div class="right-colum">
				<div class="box1" @click="addHeight">添加高度</div>
				<div class="box2"></div>
			</div>
		</div>
	</div>
</template>
<script setup lang="ts">
import { ref, computed } from "vue";
const height = ref(100);
const box1Height = computed(() => {
	return height.value + "px";
})
// 增加高度
const addHeight = () => {
	height.value += 50;
}
</script>
<style lang="scss" scoped>
.container {
	display: flex;
	align-items: stretch; // 拉伸: 子元素没有高度或高度为auto,将占满整个容器的高度
	.left-column {
		width: 400px;
		margin-right: 12px;
		background-color: cadetblue;
	}
	.right-colum {
		width: 200px;
	}
	.box1 {
		height: v-bind(box1Height);
		margin-bottom: 12px;
		background-color: palevioletred;
	}
	.box2 {
		height: 100px;
		background-color: peru;
	}
}
</style>

相关推荐

  1. CSS盒子模型

    2024-01-20 00:18:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-20 00:18:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-20 00:18:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-20 00:18:02       82 阅读
  4. Python语言-面向对象

    2024-01-20 00:18:02       91 阅读

热门阅读

  1. uniapp 学习笔记

    2024-01-20 00:18:02       59 阅读
  2. IDA Pro 7.7和8.3共用方案

    2024-01-20 00:18:02       52 阅读
  3. 小程序显示兼容处理,home键处理

    2024-01-20 00:18:02       47 阅读
  4. 年终总结:我的2023编程之旅

    2024-01-20 00:18:02       55 阅读
  5. 介绍 TensorFlow 的基本概念和使用场景

    2024-01-20 00:18:02       56 阅读
  6. 电阻式电流采样不准?(下篇)

    2024-01-20 00:18:02       63 阅读
  7. 【温故而知新】HTML5的Web Worker

    2024-01-20 00:18:02       60 阅读