flex布局实现色子
来源:互联网 发布:linux hostname命令 编辑:程序博客网 时间:2024/05/21 11:05
1、色子数:1
思路:让圆点(即子元素)在横轴上居中在竖轴上居中,分别用justify-content和align-items
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 200px; height: 200px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 25px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; justify-content: center; align-items:center; } .main >div{ width:40px; height:40px; background:#000; border-radius:40px; } </style></head><body><div class="main"> <div class="item"></div></div></body></html>2、色子数:2
思路:竖列布局且在主轴方向采用justify-content的两端对齐布局,这样两个圆点会在左边呈现,然后采用align-items让其居中
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 200px; height: 200px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 25px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; flex-direction: column; justify-content: space-between; align-items:center; } .main >div{ width:40px; height:40px; background:#000; border-radius:40px; } </style></head><body><div class="main"> <div class="item"></div> <div class="item"></div></div></body></html>3、色子数:3
思路:用到align-self属性让第二个和第三个圆点有自己的属性设置,分别在纵轴方向上居中和低端对齐
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 180px; height: 180px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 25px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; } .main >div{ width:40px; height:40px; background:#000; border-radius:40px; } .item:nth-child(2){ align-self:center; } .item:nth-child(3){ align-self:flex-end; } </style></head><body><div class="main"> <div class="item"></div> <div class="item"></div> <div class="item"></div></div></body></html>4、色子数:4
思路:先竖着放两行圆点,每行圆点里横着放两个圆点,所以最外层父元素设置align,里面的父元素设置justify-content
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 180px; height: 180px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 25px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; flex-wrap:wrap; align-content:space-between; } .column >div{ width:40px; height:40px; background:#000; border-radius:40px; } .column{ flex-basis:100%; display:flex; justify-content: space-between; } </style></head><body><div class="main"> <div class="column"> <div class="item"></div> <div class="item"></div> </div> <div class="column"> <div class="item"></div> <div class="item"></div> </div></div></body></html>5、色子数:5
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 180px; height: 180px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 25px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; flex-wrap:wrap; align-content:space-between; } .column > div{ width:40px; height:40px; background:#000; border-radius:40px; } .column{ flex-basis:100%; display:flex; justify-content: space-between; } .column:nth-child(2){ justify-content: center; } </style></head><body><div class="main"> <div class="column"> <div class="item"></div> <div class="item"></div> </div> <div class="column"> <div class="item"></div> </div> <div class="column"> <div class="item"></div> <div class="item"></div> </div></div></body></html>6、色子数:6
思路:跟四点的一样,先竖放三行在每行横放两个圆点
实现代码:
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{ margin:0; padding:0; } body{ background:#000; } .main { width: 180px; height: 180px; background: #fff; border-radius: 20px; margin: 100px auto; padding: 15px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; display: flex; align-content:space-between; flex-wrap:wrap; } .column > div{ width:40px; height:40px; background:#000; border-radius:40px; } .column{ flex-basis:100%; display:flex; justify-content: space-between; } </style></head><body><div class="main"> <div class="column"> <div class="item"></div> <div class="item"></div> </div> <div class="column"> <div class="item"></div> <div class="item"></div> </div> <div class="column"> <div class="item"></div> <div class="item"></div> </div></div></body></html>
0 0
- flex布局实现色子
- 用弹性布局实现色子
- Flex布局——色子的小案例
- flex色子练习
- Flex实现环绕布局
- flex布局实现小标题
- FLex布局实现导航
- css实现Flex布局
- flex布局实现双飞翼
- box-flex实现三等分布局
- 使用flex实现页面布局
- 用flex实现弹性布局
- Flex布局实现圣杯布局和网格布局
- CSS3 中FLEX快速实现BorderLayout布局
- 自己动手实现一个 Flex 布局框架
- 用Flex实现的百分比布局
- 使用flex布局实现div垂直居中
- flex实现经典的sticky footer布局
- MacOS安装Brew
- css2.5_类选择器
- Web架构师成长之路(转载)
- win10+opencv3.1+CS2013环境搭建
- Git使用问题,最近天天碰到 头疼的 Git 问题 记录
- flex布局实现色子
- iOS10 录音崩溃(设置info.plist)
- 电脑故障——WIN10系统安装浏览器
- eclipse中的Console控制台视图脱离主窗口解决办法
- 进制之间的转换
- 知乎变现之路
- Tessera简要教程
- 学习使用按位异或 ^
- java Web Service Axis调用参数问题