DIV完美等分的CSS样式实现
一、问题场景
传统使用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>
相关推荐
zhanghao 2020-06-16
tichangde 2020-05-19
xsgnzb 2020-03-09
lixiaotao 2020-03-02
bertzhang 2019-12-25
RexLeee 2019-12-23
wangjie 2019-11-10
谢恩铭 2016-01-10
时间猎人 2019-09-06
Jolestar 2016-06-02
gigipop 2019-07-01
标题 2019-07-01
jianqi 2019-07-01
RLanffy 2019-07-01
VVVinegar 2019-07-01
GeolageWu 2019-06-30
CoderChang 2019-06-30
zeweig 2015-06-29