前端知识点总结
时间:2023-12-29 14:07:05
使用markdown语法: # HTML ## 基本标签 ### 块级标签 * `div` 分区标签 * `p` 段落标签 * 标题标签`` 有强调 ` ` * `pre` 保留格式 * `ul>li` 无序列表 * `ol>li` 有序列表 * dl>dt dd 定义列表 ### 行内标签 - 文本样式标签 - `strong` b 加粗 (strong语义强化,常用strong) - `del` 删除 - `i` em 倾斜 常用i - span 分区标签 - 图片标签 img (宽高可设置,替代元素) 标签属性 src(图片地址) alt(图片出不来提示) title(鼠标提示) 图片路径 - `sub`下标 `sup` 上标 - 超链接 a - target 打开目标的方式 _blank 新标签 _parent 使用框架 _self 默认值 _top 使用框架 ``` 注释快捷键 ctrl / 注释快捷键 ctrl / 空链接 空链接 空链接 ``` ### HTML预留字符 ` ;` 空格 `$gt;` 小于号 < `>` 大于号> `¥` ·¥·元 `©` 版权 ? ## 列表 ### 表格 border 边框 cellspacing 去除单元格间隙 cellpadding 填充单元格 tr 行 td 列 colspan(将列合并,即横合并,横合并减少同行td) rowspan(合并是上下合并,下一个tr中的td减少) > tr 不能写在里面div table等东西,td可以包含 ```html (1)colspan 两个单元格横合并 单元格 单元格 单元格 单元格 本来五个td,两者合并,所以四个td (2)rowspan 上下合并单元格 单元格 单元格 单元格 单元格 上下合并,所以下面少两个td (3) td里面包裹table,上边合并单元格时,下边的td还需要合并单元格,然后包裹table。在写表格样式时,还需要清除所有样式。在写表格样式时,还需要清除所有样式。然后设置宽度,使用margin居中。 单元格 单元格 单元格 ``` caption 表头 thead头 tr>th tbody 身体 tr>td 必须写在表格中tbody tfoot 尾 写表格table tr th(td)必须一起写 ### 类表格 将普通标签转换为表格标签,就可以借用表格的样式布局 常用 的结构:display:table>display:table-cell ``` //设置表格类 main{ display: table; width: 100%; height: 300px; } // 设一行,加上边框 div{ display: table-cell; //一行几个元素,一行分成几个相同的块 border: 3px solid blueviolet; } .div1,.div3{ width: 150px; }
费用报销单 费用项目 ///为开头的文本设置宽度类别 金额 负责人(签字) 总人民币(大写) 拾 万 千 百 拾 元 角 分 (小写)¥ 元
总经理签字: 财务负责人签字: 报销人: ///单加边,否则,很容易重复合并单元线 财务审核: 部门签字: ``` ### 列表 + ul 无序列表 ol有序列表 >li + li 中可嵌套p div 等 ul ol 中不可 > 首先先写一个盒子,定好几个盒子,盒子的内容用什么标签,写CSS时先清除样式,设置宽度,高度,设置margin居中,然后使用弹性布局浮动居中,之后再将宽度等分。弹性布局横向,是使用布局的父级写display:flex,而浮动是是谁布局写谁。 ```html 123``` + dl>dt&dd (dt与dd同级,但是dt写小标算是) dl内可以嵌套一个dt,n个dd ,dt里面不可以不能插入div等一系列标签,dd可以,如果使***用span等一系列的行内元素写class,设置宽高一些东西,需要display:inline-block,转换为行内块元素,不然设置宽高无效***。 ```HTML``` ### 表单 + 表单 input type 类型决定标签 + input 和button对齐常用属性 vertical-align: bottom; 底部对齐 + type: text password 密码 radio(单选)name 名称必须相同 checkbox 复选框 file 选择文件 date 时间 button 按钮 submit 提交按钮 reset 重置按钮 image 图片按钮 不常用 + button type: submit 提交按钮 reset 重置按钮 + 下拉框 lable select > option + placeholder默认提示 + 文本域 textarea ```html ``` ## 常用样式 ### 文本样式 + color 字体颜色 + font-size:字体大小 + font-family:设置字体 + font-weight:字体加粗 + font-style:字体倾斜 + text-align:文本对齐方式 + text-decoration:文本装饰(下划线) + text-transform:lowercase 字母大写变小写 + text-indent:首行缩进 + line-height:行高 + justify-content: space-around; 均匀排列每个元素 *每个元素周围分配相同的空间* + transition: 0.3s;滑动 + opacity: 0.5;背景色透明 + overflow:hidden 隐藏溢出内容 scroll 添加滚动条 + cursor: pointer;鼠标变成手 + word-spacing:设置单词距离 + (/* 下面三句话为组合,/* 文字太长省略出现... */一定要给宽度样式 */ white-space:nowrap; overflow: hidden; text-overflow: ellipsis;) + letter-spacing:字间距 + object-fit: cover:强制图片不变形 + white-space: nowrap; 强制文本不换行 + vertical-align:middle 垂直居中 {display:table-cell搭配用可以} + transition: 2s linear; 过渡:使标签样式按照动画过程变化,1s表示时间 linear表示匀速 注:width/height=content+padding+border + ``` //文字在线上 ``` #### 媒体查询 + 媒体查询,根据条件使用特定的样式集合 ,screen 判断条件,判断展示页面的屏幕是不是普通的显示器(pc,ipad,mobile),max-width 当前浏览器窗口小于指定值。也可使用网格布局设置写出,可参考苹果官网 + 最大最小值:/* 尺寸的最大最小限定 */ max-width: 900px; min-width: 100px; min-height: 100px; max-height:900px ```HTML @media screen and (max-width:1200px) { body { background-color: lightsalmon; height:300px; } @media screen and (max-width:500px) { .col-sm-12{ width: 100%; } }``` ### css样式 #### css选择器 | 选择器 | 例子 | 描述 | | :------------------------------ | -------------------------------------------------------- | :----------------------------------------------------------- | | 通配符选择器 * | *{ } | 选中所有 | | 标签选择器 body p h1-h6 ul li a | body{ } | 根据标签选中范围 | | id选择器 |
| #c 前缀用点 id 选择器不能重名 | | 类名选择器(class) | | .a 前缀用点 | | 并列选择器 | ul,ol{ list-style:none } | 并集 ul和ol全部用此样式,用逗号 | | 后代选择器 | ul li{ } | 使用空格隔开 | | 子选择器 | h1 > strong | 用于选择直接的紧邻子标签/选择器 h1 > strong 可以解释为“选择作为 h1 元素子元素的所有 strong 元素”。(父子关系) | | 相邻选择器 ~ | h1 ~ p { **color:** blue; **font-size:** 18px; } | 兄弟元素之间无需紧邻,二者有相同的父元素 | | 紧邻选择器+ | h1 + p { **color:** blue; **font-size:** 18px; } | 用于选择位置靠后的紧邻兄弟标签,二者有相同的父元素 | | 属性选择器 | input[type="text"] { **color:** blue; } | 属性选择器用来匹配具有特定属性的元素。属性选择器的定义方式与标签选择器相似,只不过需要在标签的后面使用方括号`[ ]`来指定标签具有的属性信息,如下所示: | + 伪元素 利用样式在页面上添加内容,伪造标签 before after #### 伪类选择器 | 选择器 | 例子 | 描述 | | :------------- | ------------------------------------------------------------ | :----------------------------------------------------------- | | :active | a:active{ box-shadow: 0 0 5px #222; } | 鼠标按下效果 | | :hover | a/div:hover{color:red } .box-bttom:hover .select{display: block;} | 鼠标悬停效果 滑动到box-bttom:的层时select的层显示 | | :link | .a:link{ color:red } | 当前地址没有被浏览器访问过颜色红色 | | :visited | .a:visited{ color:red } | 当前的链接地址被访问过(在浏览器中) | | :focus | input:focus{border: 5px solid blue}; | 表单获取焦点(鼠标点上去)时 ,input 框变色 | | :checked | input:checked{color: chartreuse; } | 匹配处于选中状态的 元素 | | :nth-child(n) | ul li:nth-child(3){ } | 选中父元素的第3个子元素 | | nth-of-type(n) | .li:nth-of-type(2){ color: salmon; } | 匹配父元素的第二个子元素/nth-of-type 分类型查找 | | :nth-child(4n) | ul li:nth-child(4n){ text-decoration: overline; } | 选择4的倍数 | | :first-of-type | ul li:first-of-type{ font-weight: bold; } | 匹配父元素中的第一个加粗元素 | | :last-of-type | p:last-of-type | 匹配父元素中的最后一个 元素 | #### 伪元素 | 伪元素 | 例子 | 例子描述 | | ------------ | --------------------------------------------------------- | --------------------------- | | ::after | p::after | 在每个
元素之后插入内容 | | ::before | p::before | 在每个
元素之前插入内容 | | 清除浮动 | .a::before,.a::after{content:"",clear:both,display:block} | | | 点击写小弹框 | 可以写在内容中来写 | | #### 选择器权重 + 浏览器只会展示权重最高的样式 + 行内style>id>class>tag/* + *通配符 全选 权重0 + 标签选择器 (权重1) + 类选择器 (权重10) + id选择器 (权重100) + 父子选择器 #p del (权重叠加) + importment权重无限大 ## 布局 ### 盒模型 + width 宽 + height 高 + padding 内填充(字与盒子距离) + margin外边框 ( [深入理解css中的margin属性 - Wayne-Zhu - 博客园 (cnblogs.com)](https://www.cnblogs.com/zhuzhenwei918/p/6124263.html) ) + border 边框:1px soild red; + border-radious:圆角 + border-collapse: collapse 合并表格相邻边框, 相邻的两个边框会合并为一个单一的边框 + background-color:背景颜色 + background-image:url();背景图片 + background-repeated:no-repeate 图片背景不重复 + background-position: center center; //图片位置 + background-size: auto 70%; // 设置背景图像的尺寸 + outline:1px soild red 轮廓线 + display:block/inline-block/inline + box-sizing: border-box; 边框盒模型 + /*内容溢出:隐藏 */ overflow: hidden; /* ,有内容超出才处理,无法单独使用,允许用户调整大小 */ resize: both; ``` //小三角
小三角 ``` ### 弹性布局 + display:flex 弹性布局 需要浮动的父元素写弹性布局 ``` /* 对齐方式 */ justify-content: center; /* 居中排列 */ justify-content: start; /* 从行首开始排列 */ justify-content: end; /* 从行尾开始排列 */ justify-content: flex-start; /* 从行首起始位置开始排列 */ justify-content: flex-end; /* 从行尾位置开始排列 */ justify-content: left; /* 一个挨一个在对齐容器得左边缘 */ justify-content: right; /* 元素以容器右边缘为基准,一个挨着一个对齐, */ /* 基线对齐 */ justify-content: baseline; justify-content: first baseline; justify-content: last baseline; /* 分配弹性元素方式 */ justify-content: space-between; /* 均匀排列每个元素 首个元素放置于起点,末尾元素放置于终点 */ justify-content: space-around; /* 均匀排列每个元素 每个元素周围分配相同的空间 */ justify-content: space-evenly; /* 均匀排列每个元素 每个元素之间的间隔相等 */ justify-content: stretch; /* 均匀排列每个元素 'auto'-sized 的元素会被拉伸以适应容器的大小 */ /* 溢出对齐方式 */ justify-content: safe center; justify-content: unsafe center; /* 全局值 */ justify-content: inherit; justify-content: initial; justify-content: unset; ``` | 值 | 描述 | 测试 | | :------------ | :----------------------------------------------------------- | :----------------------------------------------------------- | | flex-start | 默认值。从行首起始位置开始排列。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=flex-start) | | flex-end | 从行尾位置开始排列。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=flex-end) | | center | 居中排列。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=center) | | space-between | 均匀排列每个元素,首个元素放置于起点,末尾元素放置于终点。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=space-between) | | space-evenly | 均匀排列每个元素,每个元素之间的间隔相等。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=space-evenly) | | space-around | 均匀排列每个元素,每个元素周围分配相同的空间。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=space-around) | | initial | 设置该属性为它的默认值。请参阅 [*initial*](https://www.runoob.com/cssref/css-initial.html)。 | [测试 »](https://www.runoob.com/try/playit.php?f=playcss_justify-content&preval=initial) | | inherit | 从父元素继承该属性。请参阅 [*inherit*](https://www.runoob.com/cssref/css-inherit.html)。 | | ### 浮动 + 指定元素脱离原本的文档流沿着容器的左侧或右侧进行排列,允许其他行内(块)对自身进行行环绕排列(MDN)float:left/right 浮动,浮动是谁要浮动则写在哪里,不写父类。 eg:ul>li li写浮动,ul写清除浮动 + 使用原则1.如果使用浮动,就要将同级的标签全部设为浮动 2.一定要记得清除浮动 + 浮动会造成容器的高度塌陷 1.容器标签使用overfiow 2.容器标签在前后缀上转成block并添加clear样式,需要清除浮动的父类写清除。如下代码,div需要清除浮动,使用main来写清除浮动样式。 .a::before, .a::after{content:"",clear:both,display:block} · ``` // 当左边是图片,右边是文字时,可以写图片左浮动,使文字围绕图片在右边 如果中间自适应,则两边需要左浮动,右浮动,如果横排并列,直接都左浮动就可以 双飞翼布局 /* main{ background-color: rgb(224, 183, 183); height: 300px; } .div1{ float: left; width: 150px; height: 200px; border: 5px solid blue; overflow: hidden; } .div2{ float: right; width: 150px; height: 200px; border: 5px solid orange; } .div3{ height: 200px; border: 5px solid blueviolet; margin: 0 150px; } main::before; main::before{ content:""; display:block; clear:both } 123