默认的flex
CSS Flex印象(1)文章代码示例二
by lyplba
HTML
<h1>Flex</h1>
<div class="flex-wrapper">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
<div class="flex-item">6</div>
<div class="flex-item">7</div>
<div class="flex-item">8</div>
<div class="flex-item">9</div>
</div>
<h1>Float</h1>
<div class="float-wrapper">
<div class="float-item">1</div>
<div class="float-item">2</div>
<div class="float-item">3</div>
<div class="float-item">4</div>
<div class="float-item">5</div>
<div class="float-item">6</div>
<div class="float-item">7</div>
<div class="float-item">8</div>
<div class="float-item">9</div>
</div>
CSS
.flex-wrapper {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
.flex-item {
height: 36px;
width: 25%;
font-size: 18px;
line-height: 36px;
color: #fff;
text-align: center;
}
.flex-item:nth-of-type(1) {
background-color: #82c12f;
}
.flex-item:nth-of-type(2) {
background-color: #bddb63;
}
.flex-item:nth-of-type(3) {
background-color: #fd7923;
}
.flex-item:nth-of-type(4) {
background-color: #f9b271;
}
.flex-item:nth-of-type(5) {
background-color: #b11a21;
}
.flex-item:nth-of-type(6) {
background-color: #e0474c;
}
.flex-item:nth-of-type(7) {
background-color: #7acfd6;
}
.flex-item:nth-of-type(8) {
background-color: #00c07f;
}
.flex-item:nth-of-type(9) {
background-color: #cd5554;
}
.float-wrapper {
overflow: hidden;
}
.float-item {
float: left;
width: 25%;
height: 36px;
font-size: 18px;
line-height: 36px;
color: #fff;
text-align: center;
}
.float-item:nth-of-type(1) {
background-color: #82c12f;
}
.float-item:nth-of-type(2) {
background-color: #bddb63;
}
.float-item:nth-of-type(3) {
background-color: #fd7923;
}
.float-item:nth-of-type(4) {
background-color: #f9b271;
}
.float-item:nth-of-type(5) {
background-color: #b11a21;
}
.float-item:nth-of-type(6) {
background-color: #e0474c;
}
.float-item:nth-of-type(7) {
background-color: #7acfd6;
}
.float-item:nth-of-type(8) {
background-color: #00c07f;
}
.float-item:nth-of-type(9) {
background-color: #cd5554;
}