1# div 2 3基础容器,用作页面结构的根节点或将内容进行分组。 4 5> **说明:** 6> 7> 该组件从从API version 4 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8 9 10## 子组件 11 12支持。 13 14 15## 属性 16 17| 名称 | 类型 | 默认值 | 必填 | 描述 | 18| -------- | -------- | -------- | -------- | -------- | 19| id | string | - | 否 | 组件的唯一标识。 | 20| style | string | - | 否 | 组件的样式声明。 | 21| class | string | - | 否 | 组件的样式类,用于引用样式表。 | 22| ref | string | - | 否 | 用来指定指向子元素的引用信息,该引用将注册到父组件的$refs 属性对象上。 | 23 24 25## 事件 26 27| 名称 | 参数 | 描述 | 28| -------- | -------- | -------- | 29| click | - | 点击动作触发该事件。 | 30| longpress | - | 长按动作触发该事件。 | 31| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | 组件上快速滑动后触发。 | 32 33 34## 样式 35 36| 名称 | 类型 | 默认值 | 必填 | 描述 | 37| -------- | -------- | -------- | -------- | -------- | 38| flex-direction | string | row | 否 | flex容器主轴方向。可选项有:<br/>- column:垂直方向从上到下<br/>- row:水平方向从左到右 | 39| flex-wrap | string | nowrap | 否 | flex容器是单行还是多行显示,该值暂不支持动态修改。可选项有:<br/>- nowrap:不换行,单行显示。<br/>- wrap:换行,多行显示。 | 40| justify-content | string | flex-start | 否 | flex容器当前行的主轴对齐格式。可选项有:<br/>- flex-start:项目位于容器的开头。<br/>- flex-end:项目位于容器的结尾。<br/>- center:项目位于容器的中心。<br/>- space-between:项目位于各行之间留有空白的容器内。<br/>- space-around:项目位于各行之前、之间、之后都留有空白的容器内。 | 41| align-items | string | stretch<sup>5+</sup><br/>flex-start<sup>1-4</sup> | 否 | flex容器当前行的交叉轴对齐格式,可选值为:<br/>- stretch:弹性元素被在交叉轴方向被拉伸到与容器相同的高度或宽度。<sup>5+</sup><br/>- flex-start:元素向交叉轴起点对齐。<br/>- flex-end:元素向交叉轴终点对齐。<br/>- center:元素在交叉轴居中。 | 42| display | string | flex | 否 | 确定该元素视图框的类型,该值暂不支持动态修改。可选值为:<br/>- flex:弹性布局<br/>- none:不渲染此元素 | 43| width | <length> \| <percentage><sup>5+</sup> | - | 否 | 设置组件自身的宽度。<br/><br/>未设置时组件宽度默认为0。 | 44| height | <length> \| <percentage><sup>5+</sup> | - | 否 | 设置组件自身的高度。<br/><br/>未设置时组件高度默认为0。 | 45| padding | <length> | 0 | 否 | 使用简写属性设置所有的内边距属性。<br/> 该属性可以有1到4个值:<br/>- 指定一个值时,该值指定四个边的内边距。<br/>- 指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。<br/>- 指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。<br/>- 指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。 | 46| padding-[left\|top\|right\|bottom] | <length> | 0 | 否 | 设置左、上、右、下内边距属性。 | 47| margin | <length> \| <percentage><sup>5+</sup> | 0 | 否 | 使用简写属性设置所有的外边距属性,该属性可以有1到4个值。<br/>- 只有一个值时,这个值会被指定给全部的四个边。<br/>- 两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。<br/>- 三个值时,第一个值被匹配给上, 第二个值被匹配给左和右,第三个值被匹配给下。<br/>- 四个值时,会依次按上、右、下、左的顺序匹配 (即顺时针顺序)。 | 48| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | 否 | 设置左、上、右、下外边距属性。 | 49| border-width | <length> | 0 | 否 | 使用简写属性设置元素的所有边框宽度。 | 50| border-color | <color> | black | 否 | 使用简写属性设置元素的所有边框颜色。 | 51| border-radius | <length> | - | 否 | border-radius属性是设置元素的外边框圆角半径。 | 52| background-color | <color> | - | 否 | 设置背景颜色。 | 53| opacity<sup>5+</sup> | number | 1 | 否 | 元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。 | 54| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | 否 | left\|top确定元素的偏移位置。<br/>- left属性规定元素的左边缘。该属性定义了定位元素左外边距边界与其包含块左边界之间的偏移。<br/>- top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。 | 55 56 57## 示例 58 591. Flex样式 60 61 ```html 62 <!-- xxx.hml --> 63 <div class="container"> 64 <div class="flex-box"> 65 <div class="flex-item color-primary"></div> 66 <div class="flex-item color-warning"></div> 67 <div class="flex-item color-success"></div> 68 </div> 69 </div> 70 ``` 71 72 73 ```css 74 /* xxx.css */ 75 .container { 76 flex-direction: column; 77 justify-content: center; 78 align-items: center; 79 width: 454px; 80 height: 454px; 81 } 82 .flex-box { 83 justify-content: space-around; 84 align-items: center; 85 width: 400px; 86 height: 140px; 87 background-color: #ffffff; 88 } 89 .flex-item { 90 width: 120px; 91 height: 120px; 92 border-radius: 16px; 93 } 94 .color-primary { 95 background-color: #007dff; 96 } 97 .color-warning { 98 background-color: #ff7500; 99 } 100 .color-success { 101 background-color: #41ba41; 102 } 103 ``` 104 105  106 1072. Flex Wrap样式 108 109 ```html 110 <!-- xxx.hml --> 111 <div class="container"> 112 <div class="flex-box"> 113 <div class="flex-item color-primary"></div> 114 <div class="flex-item color-warning"></div> 115 <div class="flex-item color-success"></div> 116 </div> 117 </div> 118 ``` 119 120 121 ```css 122 /* xxx.css */ 123 .container { 124 flex-direction: column; 125 justify-content: center; 126 align-items: center; 127 width: 454px; 128 height: 454px; 129 } 130 .flex-box { 131 justify-content: space-around; 132 align-items: center; 133 flex-wrap: wrap; 134 width: 300px; 135 height: 250px; 136 background-color: #ffffff; 137 } 138 .flex-item { 139 width: 120px; 140 height: 120px; 141 border-radius: 16px; 142 } 143 .color-primary { 144 background-color: #007dff; 145 } 146 .color-warning { 147 background-color: #ff7500; 148 } 149 .color-success { 150 background-color: #41ba41; 151 } 152 ``` 153 154  155