批改状态:合格
老师批语:写博客的时候建议带上图例
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><style>/* 这里是全局设置,padding内边距0,margin外边距0,并且设置盒子的大小只由width宽和height高决定 */* {padding: 0;margin: 0;box-sizing: border-box;}/* 这里设置html根元素字号的大小 */html {font-size: 10px;}/* 这里我们给class名为btn的button元素添加一些样式 */button.btn {/* 背景色:红色 */background-color: red;/* 按钮文本颜色:白色 */color: white;/* 边框:无 */border: none;/* 轮廓线:无 */outline: none;}/* 这里我们给按钮添加些鼠标移动上去后的一些效果 */.btn:hover {/* 光标:小手 */cursor: pointer;/* 透明度:50% */opacity: 0.5;/* 延迟0.3秒 */transition: 0.3s;/* 内边框左右0.4rem 上下0.8rem */padding: 0.4rem 0.8rem;}/* 小按钮的字号大小=1.2*html根元素字号的大小 */.btn.small {font-size: 1.2rem;}/* 中按钮的字号大小=1.6*html根元素字号的大小 */.btn.middle {font-size: 1.6rem;}/* 大按钮的字号大小=2*html根元素字号的大小 */.btn.large {font-size: 2rem;}/* 这里是使用媒体查询电脑屏幕的适配,宽度为1025以上的是电脑屏,屏幕大字号就大 */@media (min-width: 1025px) {/* 这里是通过改变html根元素的字号来调整按钮的字号大小从而实现在不同的屏幕宽度下按钮的大小不一样 */html {/* 调整html根元素字号大小 */font-size: 12px;}}/* 这里是使用媒体查询平板电脑的适配区间,屏幕宽度小字号就小点 */@media only screen and (min-width: 800px) and (max-width: 1024px) {/* 这里是通过改变html根元素的字号来调整按钮的字号大小从而实现在不同的屏幕宽度下按钮的大小不一样 */html {/* 调整html根元素字号大小 */font-size: 10px;}}/* 这里是使用媒体查询手机适配,屏幕宽度小于799时字号就小点 */@media only screen and (max-width: 799px) {/* 这里是通过改变html根元素的字号来调整按钮的字号大小从而实现在不同的屏幕宽度下按钮的大小不一样 */html {/* 调整html根元素字号大小 */font-size: 8px;}}</style></head><body><button class="btn small">提交1</button><button class="btn middle">提交2</button><button class="btn large">提交3</button></body></html>
定位类型
1.相对定位:position:relative相对自身在文档流中偏移
2.绝对定位:position:absolute相当于他的包含快偏移,不在文档流中
3.固定定位:position:fixed绝对定位的一个子集,只不过它的包含块是固定的,永远是body
实例代码演示
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>定位实战</title><style>/* 初始化 */* {/* 内边距:0 */padding: 0;/* 外边距:0 */margin: 0;/* 设置盒子大小只由宽高决定 */box-sizing: border-box;}/* 顶部样式 */.header {padding: 0.5em 1em;background-color: blue;display: flex;}.header > .title {font-weight: lighter;font-style: italic;color: red;text-shadow: 10px 10px 10px green;}.header button {margin-left: auto;background-color: hotpink;width: 5em;border: none;border-radius: 0.5em;}.header button:hover {cursor: pointer;background-color: green;color: wheat;box-shadow: 0 0 8px red;transition: 0.3s;}fieldset {padding: 0.8em 0.5em 1.2em;border: 1px dashed red;}/* 模态框 *//* 登陆表单 */.modal > .modal-form > fieldset > legend {padding: 5px 1em;background-color: red;color: wheat;}.modal > .modal-form {position: fixed;top: 10em;left: 20em;right: 20em;}/* 半透明罩 */.modal > .modal-bg {position: fixed;top: 0px;right: 0px;bottom: 0px;left: 0px;background-color: rgba(0, 0, 0, 0.7);}</style></head><body><div class="header"><h3 class="title">小夫的个人博客</h3><button onclick="document.querySelector('.modal').style.display='block'">login</button></div><div class="modal"><!-- 1.透明罩 --><divclass="modal-bg"onclick="this.parentNode.style.display='none'"></div><form action="" class="modal-form"><fieldset><legend>user login:</legend><label for="username">username:</label><inputtype="text"id="username"name="username"value=""placeholder="please input passwprd"/><label for="password">password:</label><inputtype="password"id="password"name="password"value=""placeholder="please input password"/><button>login</button></fieldset></form></div></body></html>
| 序号 | 种类 | 定义 | 
|---|---|---|
| 1 | 弹性容器 | 拥有 display:flex/display:inline-flex 属性,使用 flex 弹性布局的区块 | 
| 2 | 弹性项目 | 弹性容器中的子元素 | 
| 3 | 主轴 | 弹性项目排列时参考的轴线有水平和垂直两种 | 
| 4 | 交叉轴 | 与主轴垂直的布局参考线 | 
弹性容器的语法
1.flex 布局术语,容器主轴属性
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>flex布局术语,容器主轴属性</title><style>* {padding: 0;margin: 0;box-sizing: border-box;}/* flex容器 */.container {display: flex;height: 20em;border: 1px solid red;/* 控制flex容器内项目:主轴方向:水平 允许换行:否 */flex-flow: row nowrap;/* 控制flex容器内项目:主轴方向:水平 允许换行:是 */flex-flow: row wrap;/* 控制flex容器内项目:主轴方向:垂直 允许换行:否 */flex-flow: column nowrap;/* 控制flex容器内项目:主轴方向:垂直 允许换行:是 *//* 控制flex容器内项目:主轴方向:水平 允许换行:否 */flex-flow: column wrap;/* 这里如果我们设置成了可以换行的话项目的高度就不会等于容器的高度了,而是会由项目自身内的内容撑开 */flex-flow: row wrap;/* 起始对齐:把项目放在起始位置,项目剩余空间在右边 */place-content: start;/* 结尾对齐:把项目放在结束位置,剩余空间在左边 */place-content: end;/* 居中对齐:把项目放在start和end中间剩余空间分配在项目左右 */place-content: center;/* 两端对齐:把第一个项目和最后一个项目分别放在起始位置和结束位置,剩余空间围绕着容器里其他项目进行分配 */place-content: space-between;/* 分散对齐:把每个项目分散开对齐,每个项目左右的剩余空间相等 */place-content: space-around;/* 平均对齐:把项目平均分布在在起始位置和结束位置之间 */place-content: space-evenly;}/* flex下的子元素(项目) */.container > .item {width: 10em;height: 20em;padding: 1em;background-color: seagreen;border: 1px solid blue;}</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>
2.flex 容器交叉轴属性
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>flex容器交叉轴属性</title><style>* {padding: 0;margin: 0;box-sizing: border-box;}/* flex容器 */.container {display: flex;height: 20em;border: 1px solid red;flex-flow: row wrap;/* 交叉轴默认值 */place-items: stretch;/* 靠近交叉轴起始边 */place-items: start;/* 靠近交叉轴末尾边 */place-items: end;/* 在交叉轴中间 */place-items: center;}/* flex下的子元素(项目) */.container > .item {min-width: 10em;/* height: 20em; */padding: 1em;background-color: seagreen;border: 1px solid blue;}</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>
3.flex 项目属性
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>flex项目属性</title><style>* {padding: 0;margin: 0;box-sizing: border-box;}/* flex容器 */.container {display: flex;height: 20em;border: 1px solid red;}/* flex下的子元素(项目) */.container > .item {/* min-width: 10em; *//* height: 20em; */padding: 1em;background-color: seagreen;border: 1px solid blue;/* flex:1.放大因子 2.收缩因子 3.计算宽度 */flex: 0 1 10em;}.item:nth-of-type(1) {background-color: yellow;/* 序号:越小越高前 */order: 1;}.item:nth-of-type(2) {/* 序号:越小越高前 */order: 2;}.item:nth-of-type(3) {background-color: blue;/* 序号:越小越高前 */order: 3;}</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>
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号