移动端文字垂直居中向上偏移解决方案
解决方案:
不使用line-height进行垂直居中
使用 transform scale 缩放操作
注意:既然使用缩放,则所有的大小,宽高数值扩大一倍;
基于vue封装的badge组件,作用: 给一个值,自动定位到右上角,如果值大于99,则显示 99+, 如果为空或者零,则不显示角标
显示效果
;
border-radius: 100%;
background-color: $red;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
>i {
font-style: normal;
font-size: 30px;
}
}
}
</style>
<template lang="html">
<div class="c-badge">
<span class="c-num-content" v-if="num && display">{{currentValue}}<i v-if="show">+</i></span>
<slot name="content"></slot>
</div>
</template>
<script>
export default {
name: 'Badge',
props: {
num: [Number, String],
display: {
type: Boolean,
default: true
}
},
data () {
return {
show: false
};
},
computed: {
currentValue: function () {
if (this.num === '') return
if (this.num > 99) {
this.show = true
return '99'
} else {
this.show = false
return this.num
}
}
},
methods: {
}
}
</script>