CSS布局 水平居中 底部对齐

CSS布局技巧:https://blog.csdn.net/weixin_39829501/article/details/111681956
效果:
在这里插入图片描述
分解:
在这里插入图片描述
使用 flex 布局

display: flex;
justify-content: center;
align-items: flex-end;

代码:

<!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>
    <style>
      .container {
        width: 480px;
        height: 128px;
        background: #fff;
        padding: 0 20px;
        display: flex;
        border: 1px solid #000;
      }
      .con-box {
        width: 33.3%;
        height: 100%;
        display: flex;
        justify-content: center;
      }
      .con-item {
        width: 90px;
        height: 100%;
        background: #ccc;
        display: flex;
        justify-content: center;
        align-items: flex-end;
      }
      .item-ele {
        width: 30px;
        height: 30px;
        background: red;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="con-box">
        <div class="con-item">
          <div class="item-ele"></div>
        </div>
      </div>
      <div class="con-box">
        <div class="con-item">
          <div class="item-ele"></div>
        </div>
      </div>
      <div class="con-box">
        <div class="con-item">
          <div class="item-ele"></div>
        </div>
      </div>
    </div>
  </body>
</html>

效果图完整实现:

<template>
  <div class="wraP_">
    <div class="container">
      <div v-for="(item, index) in imgList" :key="index" class="con-box">
        <div class="con-item">
          <div class="item-ele">
            <div class="text-top" :style="{ color: item.color }">
              {{ item.value }}
            </div>
            <img
              :src="item.img"
              alt=""
              :style="{ width: '90px', height: height(item.value) + 'px' }"
              class="img-class"
            />
            <div class="text-bottom">{{ item.text }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "ExcessRateChart",
  components: {},
  data() {
    return {
      max: 0,
      imgList: [
        {
          status: 1,
          value: "20%",
          text: "第一张",
          img: require("@/assets/images/water/kmo.png"),
          color: "#E8C50B",
        },
        {
          status: 2,
          value: "12%",
          text: "第二张",
          img: require("@/assets/images/water/an.png"),
          color: "#0CD7E2",
        },
        {
          status: 3,
          value: "5%",
          text: "第三张",
          img: require("@/assets/images/water/tp.png"),
          color: "#1EAAFE",
        },
      ],
    };
  },
  methods: {
    maxData() {
      for (let i = 0; i < this.imgList.length; i++) {
        if (parseInt(this.imgList[i].value.split("%")[0]) > this.max) {
          this.max = parseInt(this.imgList[i].value.split("%")[0]);
        }
      }
    },
  },
  computed: {
    height() {
      return function (val) {
        this.maxData();
        let h = (val.split("%")[0] / this.max) * 123;
        return h;
      };
    },
  },
};
</script>
<style scoped lang="scss">
.container {
  width: 480px;
  height: 180px;
  padding: 0 20px;
  display: flex;
}
.con-box {
  width: 33.3%;
  height: 100%;
  display: flex;
  justify-content: center;
}
.con-item {
  width: 90px;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.item-ele {
  display: block;
  text-align: center;

  .text-top {
    font-size: 20px;
    font-family: tenxu;
  }
  .text-bottom {
    font-size: 14px;
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Windyluna

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值