css实现平行四边形

需求:
在这里插入图片描述
要点:通过transform: skew(-20deg); //设置倾斜度
注意点:不要直接给最外层容器设置倾斜角度,否则会导致容器里的子元素也会随之倾斜,如下图:(文字会跟随倾斜)
在这里插入图片描述
实现:

<template>
  <div class="parallelogram">
    <div class="parallelogram-1">平行四边形</div>
    <div class="parallelogram-2">
      <span class="bg"></span>
      <span class="title">平行四边形</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {};
  },
  created() {},
  mounted() {},
  methods: {},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
.parallelogram {
  height: 100px;
  .parallelogram-1 {
    width: 100px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    transform: skew(-20deg); //设置倾斜度为-20
    background: #4f9efd;
    margin-left: 20px;
  }
  .parallelogram-2 {
    margin-top: 20px;
    margin-left: 20px;
    width: 100px;
    height: 30px;
    line-height: 30px;
    // background: #4f9efd;
    position: relative;
    .bg {
      position: absolute;
      left: 0;
      top: 0;
      display: inline-block;
      width: 100px;
      height: 30px;
      transform: skew(-20deg); //设置倾斜度为-20
      background: #4f9efd;
    }
    .title {
      position: absolute;
      left: 0;
      top: 0;
      width: 100px;
      height: 30px;
      display: inline-block;
      text-align: center;
    }
  }
}
</style>  

最终效果对比:
在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值