Blogger Information
Blog 10
fans 0
comment 0
visits 5565
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex项目上的三个属性
手机用户1615433136
Original
811 people have browsed it

flex项目上的三个属性

<!DOCTYPE html>

<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>设置某一个项目在交叉轴上的对齐方式</title>
<style>
{
box-sizing: border-box;
}

:root {
font-size: 10px;
}
body {
font-size: 1.6rem;
}
### 转为flex弹性布局元素
```

.container {
display: flex;
height: 20rem;
border: 1px solid #000;

/
position: relative; /
}
.container > .item {
/
width: 5em; /
background-color: lightcyan;
border: 1px solid #000;
}

###例如设置第2个项目与其它项目的对齐方式不一样
.container > .item:nth-of-type(2) {
align-self: stretch;
align-self: flex-start;
align-self: flex-end;
align-self: center;
}
###flex项目支持定位 定位父级
.container {
position: relative;
}
.container > .item:nth-of-type(2) {
position: absolute;
left: 3rem;
top: 3rem;
/
通过定位,可以许多非常复杂,甚至匪夷所思的布局 */
}
```
</style>
</head>

<body>
<div class="container">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
</div>
</body>
</html>

设置项目在主轴上的显示顺序

  1. * {
  2. box-sizing: border-box;
  3. }
  4. :root {
  5. font-size: 10px;
  6. }
  7. body {
  8. font-size: 1.6rem;
  9. }
  10. .container {
  11. /* 转为flex弹性布局元素 */
  12. display: flex;
  13. height: 20rem;
  14. border: 1px solid #000;
  15. position: relative;
  16. }
  17. .container > .item {
  18. flex: auto;
  19. background-color: lightcyan;
  20. border: 1px solid #000;
  21. }

显示顺序:默认按书写的源码顺序排列 默认序号越小越靠前,越大越靠后

  1. .container > .item:first-of-type {
  2. order: 1;
  3. order: 5;
  4. background-color: yellow;
  5. }
  6. .container > .item:nth-of-type(2) {
  7. order: 2;
  8. background-color: lightgreen;
  9. }
  10. .container > .item:nth-of-type(3) {
  11. order: 3;
  12. order: 0;
  13. }
  14. .container > .item:last-of-type {
  15. order: 4;
  16. /* 支持负值 */
  17. order: -1;
  18. background-color: #ccc;
  19. }
  1. </style>

</head>

<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post