一、問題場景
傳統使用width屬性配合float總是最右邊出現間隙,需要實現任意個DIV的完美等分,包括橫向和縱向
二、實現
父元素樣式
/*盒模型*/
display: -webkit-box;
display: -moz-box;
display: box;
/*橫向or縱向*/
-webkit-box-orient: horizontal; /* 垂直是vertical */
-moz-box-orient: horizontal; /* 垂直是vertical */
box-orient: horizontal;
子元素樣式
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
三、完整代碼
<template>
<div class="main-box">
<div class="main-box-content">1</div>
<div class="main-box-content">2</div>
<div class="main-box-content">3</div>
</div>
</template>
<script>
import serialport from 'serialport'
export default {
name: "MainPage",
data: function () {
return {
serialPortList: []
}
},
methods: {
handleScanSerialPortList: function () {
serialport.list().then(
ports => {
console.log(ports)
}
)
}
}
}
</script>
<style scoped>
.main-box {
/*盒模型*/
display: -webkit-box;
display: -moz-box;
display: box;
/*橫向or縱向*/
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
}
.main-box-content {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
}
</style>