flex
布局实现,css控制文字效果
div
的方式控制,当鼠标悬浮的时候展示内层div
看一下代码实现吧👇
<div class="card_view">
<div class="card_view-item" v-for="(card, index) in listData" :key="index">
<card :cardData="{name:card.name}"></card>
</div>
</div>
flex: 0 1 auto; (默认值为0 1 auto, 后两个属性可选) 三个参数分别是:
.card_view {
display: flex;
justify-content: flex-start;
flex-flow: row wrap;
align-items: flex-start;
&-card {
border-radius: 8px;
cursor: pointer;
height: 36px;
position: relative;
margin-left: 16px;
margin-top: 16px;
}
&-item {
flex: 0 0 16.66%;
}
}
全局样式:
//文本溢出省略号
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.clamp_fun(@line: 1) {
overflow: hidden;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
display: -webkit-box;
-webkit-line-clamp: @line;
}
.clamp_1 {
.clamp_fun(1);
}
.clamp_2 {
.clamp_fun(2);
}
.clamp_3 {
.clamp_fun(3);
}
<template>
<div class="textCard">
<div class="ellipsis card-name">{{cardData.name}}</div>
</div>
<template>
<script>
export default {
name:'TextCard',
props:{
cardData: {
type: Object,
require: true
}
},
components: {},
data () {
return {}
},
}
</script>
<style lang='less' rel='stylesheet/less' scoped>
.textCard {
border-radius: 8px;
cursor: pointer;
background-color: aqua;
height: 36px;
position: relative;
margin-right: 16px;
margin-top: 16px;
color: #333;
.card-name {
position: absolute;
top: 0;
left: 0;
display: inline-block;
width: 100%;
padding: 8px 14px;
border-radius: 8px;
line-height: 20px;
box-sizing: border-box;
}
&:hover {
.card-name {
color: #fff;
white-space: normal !important;
overflow: unset !important;
background-color: aqua;
box-shadow: 0 6px 200px rgba(71, 96, 240, 0.2);
z-index: 9;
}
}
}
</style>