元素两端对齐
第一个案例是让两个元素分别向左和向右对齐,如果是过去,我一定会用float来实现,但其实用table可以这么做:
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
|
* {
box-sizing: border-box;
}
.content {
display
: table;
border
:
1px
solid
#06c
;
padding
:
15px
5px
;
max-width
:
1000px
;
margin
:
10px
auto
;
min-width
:
320px
;
width
:
100%
;
}
.box {
width
:
100px
;
height
:
100px
;
border
:
1px
solid
#ccc
;
text-align
:
center
;
display
: inline-
block
;
font-size
:
40px
;
line-height
:
100px
;
}
.
right
{
text-align
:
right
;
display
:
table-cell
}
.
left
{
text-align
:
left
;
display
:
table-cell
}
|
1
2
3
4
5
6
7
8
|
<
div
class="content">
<
div
class="left">
<
div
class="box">B</
div
>
</
div
|