设置flex布局的元素,其子元素宽度和超过其本身时,其宽度值未被撑起问题

 

<script setup lang="ts">
import { onMounted, ref } from 'vue'

onMounted(() => {})
</script>

<template>
  <div>
    <!-- m-list没有被撑开 -->
    <!-- <div class="m-list">
      <div class="m-item" v-for="item in Array.from({ length: 20 }, (_, index) => index)">
        {{ item }}
      </div>
    </div> -->
    <!-- 在m-list外层在包裹一个display:flex,m-list被撑开 -->
    <div class="m-list-wrap">
      <div class="m-list">
        <div class="m-item" v-for="item in Array.from({ length: 20 }, (_, index) => index)">
          {{ item }}
        </div>
      </div>
    </div>
  </div>
</template>

<style>
.m-list-wrap {
  display: flex;
  height: 400px;
  overflow-y: auto;
}
.m-list {
  display: flex;
  height: 200px;
  flex: 1;
  background: #ddd;
}
.m-item {
  width: 300px;
  flex-shrink: 0;
  display: inline-flex;
}
</style>

参考链接

https://blog.****.net/qq_43231248/article/details/140657678

人工智能学习网站

https://chat.xutongbao.top

上一篇:将后端返回的网络url转成blob对象,实现pdf预览


下一篇:虚拟电厂(2)