如何实现flex布局下div等宽且内部文字可以溢出显示

效果如图:

HTML结构:

1
2
3
4
5
6
7
8
9
10
11
12
<div class="labels">
<div class="label"><span>1</span></div>
<div class="label"><span>2</span></div>
<div class="label"><span>3</span></div>
<div class="label"><span>4</span></div>
<div class="label"><span>Today</span></div>
<div class="label"><span>6</span></div>
<div class="label"><span>7</span></div>
<div class="label"><span>8</span></div>
<div class="label"><span>9</span></div>
<div class="label"><span>10</span></div>
</div>

CSS样式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.labels {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
.label {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
overflow: hidden;
span {
overflow: visible;
position: absolute;
line-height: 0;
}
}
}

如何实现flex布局下div等宽且内部文字可以溢出显示

https://www.imaegoo.com/2018/flex-same-width-overflow/

作者

iMaeGoo

发布于

2018-03-01

更新于

2018-03-01

许可协议

CC BY 4.0

评论

微信二维码