# HTML+CSS2020603 **Repository Path**: nieps/html--css2020603 ## Basic Information - **Project Name**: HTML+CSS2020603 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-02 - **Last Updated**: 2026-03-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HTML+CSS大纲 目标: * 会排版页面 * 掌握主流的CSS排版方法 * flex布局 ## 什么是 HTML、CSS * html hyper text markup language 超文本标记语言 搭建页面结构 > xml: 可扩展的标记语言 描述数据 * css Cascading Style Sheets,层叠样式表 装饰 > scss * javascript 脚本语言 前端页面的动态交互 > 浏览器兼容问题-----jquery ---- vue ( react ) ## 编辑器 * hbuilder-----我个人 H5 uniapp * vs code (更专业 ---提供了很多插件)---- > 安装插件: > > * live server 可以在线预览页面效果 ## HTML基础结构 - 文档声明、html/head/body 根标签 - 字符编码、页面标题、SEO 基础 meta 标签 ### 页面结构 * html 根元素 * head 头部 里面存放的 元素 (与页面显示无关 如标题 元数据(seo搜索优化、页面刷新 作者)css 定义 js定义) > * title 标题 > > * meta 元数据 > > > viewport: > > > > ![image-20260302105254729](assets/image-20260302105254729.png) > > ~~~html > > > > > > > > > > > > > HTML页面结构 > > ~~~ > > * body 主体 所有页面的排版元素 都在这里 ## 文本标签 - 标题 (h1-h6)、段落 (p)、换行 (br)、分割线 (hr) - 注释写法 ### 块元素 * 独占一行 * 宽度默认是100% > 还有其它:粗体 斜体 ## 链接与图片 - 超链接 a 标签:页面跳转、新窗口打开、锚点链接 - 图片 img 标签:路径(相对 / 绝对)、alt 属性、宽高设置 ### 图片 * img > image > > 属性: > > * src 图片路径 > * width 宽度 一般指定后高度会自动调整 > * height 高度 > * alt 指定文本 在图片不可用时替换的内容 > * title 鼠标放上去显示的文本 电商中的图片: 1. 上传时图片大小有限制 kb 2. 宽高有限制 建议width*height 3. 实际开发中,用户上传后的图片,后台会对图片统一处理 > * 保留原图 (做修改) > * 在原图基础上 生成缩略图 图片路径: * 相对路径 > * ./ 代表当前目录 可以省略 > * ../ 代表上一级目录 > * ../../ 代表上上级目录 * 绝对路径 完整的地址 ### 行内元素 * 允许多个元素在同一行内显示 不换行 ### a元素属性 * href 连接跳转的目标 可以是相对或绝对路径 * target 目标打开的方式 > 1. **_blank 在新窗口打开** > 2. _self 替换当前窗口 > 3. _parent 在父窗口打开 > 4. _top 在顶部窗口打开 > 5. 显示在自定义窗口 iframe指定name属性 * 锚点 ## 列表 > 表格table 了解 - 无序列表 ul/li、有序列表 ol/li(导航栏、菜单必备) ### 无序列表 ul/li (排版用的多) ul: unordered list li: list item ![image-20260302150340855](assets/image-20260302150340855.png) ### 有序列表 ol: ordered list ![image-20260302150948465](assets/image-20260302150948465.png) ## div span元素 常用 的 ,排版 ## 表单(用户交互基础) - input、button、textarea、select 下拉框 - 表单属性:占位符、必填、密码框、单选 / 复选框 ## CSS 基础 - CSS 三种引入方式:行内、内嵌、外部样式表 - 语法规则:选择器 + 声明块 - 注释 ### 样式引用方式 #### 行内样式 在任何元素上通过属性style 定义,如下: ~~~html

这是一个段落

~~~ 优先级最高,通常适用于少量的css定义,或者覆盖默认的样式 #### 内嵌样式 通过style标签,在html文档内部直接定义样式,这样定义的样式整个html文档可以复用. #### 外部样式 * 单独定义在css文件中 * 在html文档中通过link标签引入 * 适用于多文件复用样式 ~~~html ~~~ 属性: * rel 值为stylesheet 不能省略 否则无效 * href 不能省略 指定引入的样式路径 (相对或绝对路径) #### 总结 * 三种定义的样式 如果不冲突 会合并样式效果 * 如果冲突了,行内样式拥有最高优先级 * 外部样式与内嵌样式优先级一样,后面定义 的样式会覆盖前面的样式 ### css定义结构 ~~~html 元素选择器 { 属性名1 : 属性值1; 属性名2 : 属性值2; } ~~~ #### 元素选择器 用于指明当前的样式,应用到的目标 常见元素选择器: ##### 元素选择器 直接指定元素名称 ~~~html
这是div块元素
~~~ ##### id 选择器 id值都是唯一 标识 #id值 {} ~~~html

这是段落元素


这个是有id的段落

~~~ ##### 类选择器 通过class属性 引用样式对象 ,定义如下: ~~~css .类名{ 属性:属性值 } ~~~ ##### 多元素选择器 允许同时给多个元素或其它选择器,定义相同的样式 ,多个选择器用,隔开 p,div,#info,.ft {} ##### 子元素选择器 body>div body元素下的div元素 ##### 后代元素 el1 el2 ##### 伪选择器 * 元素::before { content:"" } 在指定元素前面插入内容 * 元素::after {content :""} 指定元素后面插入内容 上面的元素只能插入文本、图片 ~~~css .box::before { content: "我是插入的文本"; /* 直接写内容 */ color: red; margin-right: 8px; } .box::before { content: url("icon.png"); /* 直接插图片 */ display: inline-block; width: 16px; height: 16px; } ~~~ ## ul 新闻列表 vertical-align: 元素内内容垂直对齐方式 (在大部分情况下无效) * top 顶部对齐 * middle 垂直居中 * bottom 底部对齐 ### 颜色 16进制颜色值: # rgb * r red 红色 16进度表示 ff * g green 绿色 16进度表示 ff * b blue 蓝色 示例: * 红色 #ff0000 #f00 * 绿色 #00ff00 * 蓝色 #0000ff * 白色 #ffffff * 黑色 #000000 * 灰色 #333 #666 #999 #ccc ### 文本装饰 text-decoration: * **none** 禁用 通常是去掉a超连接的下滑线 * line-through 删除线 常用 删除市场价格 > ![image-20260302170002181](assets/image-20260302170002181.png) * underline 下滑线 > ![image-20260302170050130](assets/image-20260302170050130.png) * overline 上滑线 (用的少) > ![image-20260302170141628](assets/image-20260302170141628.png) ### 伪类选择器 * a:link 连接 的样式 (用的少) * a:visited 连接访问后的样式 (用的少) * **a:hover 鼠标悬停的样式** (常用 ) * a:active 激活活的颜色(鼠标点击未松开的颜色) (用的少) ## 选择器(精准控制元素) - 基础:元素选择器、类选择器、id 选择器 - 高级:后代、子元素、并集、伪类、属性选择器 | 选择器 | 示例 | 示例说明 | CSS | | :----------------------------------------------------------- | :-------------------- | :----------------------------------------------------------- | :--- | | [.*class*](https://www.runoob.com/cssref/sel-class.html) | .intro | 选择所有class="intro"的元素 | 1 | | [#*id*](https://www.runoob.com/cssref/sel-id.html) | #firstname | 选择所有id="firstname"的元素 | 1 | | [*](https://www.runoob.com/cssref/sel-all.html) | * | 选择所有元素 | 2 | | *[element](https://www.runoob.com/cssref/sel-element.html)* | p | 选择所有

元素 | 1 | | *[element,element](https://www.runoob.com/cssref/sel-element-comma.html)* | div,p | 选择所有

元素和

元素 | 1 | | [element*.class*](https://www.runoob.com/cssref/sel-element-class.html) | p.hometown | 选择所有 class="hometown" 的

元素 | 1 | | [*element* *element*](https://www.runoob.com/cssref/sel-element-element.html) | div p | 选择

元素内的所有

元素 | 1 | | [*element*>*element*](https://www.runoob.com/cssref/sel-element-gt.html) | div>p | 选择所有父级是

元素的

元素 | 2 | | [*element*+*element*](https://www.runoob.com/cssref/sel-element-pluss.html) | div+p | 选择所有紧跟在

元素之后的第一个

元素 | 2 | | [[*attribute*\]](https://www.runoob.com/cssref/sel-attribute.html) | [target] | 选择所有带有target属性元素 | 2 | | [[*attribute*=*value*\]](https://www.runoob.com/cssref/sel-attribute-value.html) | [target=-blank] | 选择所有使用target="-blank"的元素 | 2 | | [[*attribute*~=*value*\]](https://www.runoob.com/cssref/sel-attribute-value-contains.html) | [title~=flower] | 选择标题属性包含单词"flower"的所有元素 | 2 | | [[*attribute*\|=*language*\]](https://www.runoob.com/cssref/sel-attribute-value-lang.html) | [lang\|=en] | 选择 lang 属性等于 **en**,或者以 **en-** 为开头的所有元素 | 2 | | [:link](https://www.runoob.com/cssref/sel-link.html) | a:link | 选择所有未访问链接 | 1 | | [:visited](https://www.runoob.com/cssref/sel-visited.html) | a:visited | 选择所有访问过的链接 | 1 | | [:active](https://www.runoob.com/cssref/sel-active.html) | a:active | 选择活动链接 | 1 | | [:hover](https://www.runoob.com/cssref/sel-hover.html) | a:hover | 选择鼠标在链接上面时 | 1 | | [:focus](https://www.runoob.com/cssref/sel-focus.html) | input:focus | 选择具有焦点的输入元素 | 2 | | [:first-letter](https://www.runoob.com/cssref/sel-firstletter.html) | p:first-letter | 选择每一个

元素的第一个字母 | 1 | | [:first-line](https://www.runoob.com/cssref/sel-firstline.html) | p:first-line | 选择每一个

元素的第一行 | 1 | | [:first-child](https://www.runoob.com/cssref/sel-firstchild.html) | p:first-child | 指定只有当

元素是其父级的第一个子级的样式。 | 2 | | [:before](https://www.runoob.com/cssref/sel-before.html) | p:before | 在每个

元素之前插入内容 | 2 | | [:after](https://www.runoob.com/cssref/sel-after.html) | p:after | 在每个

元素之后插入内容 | 2 | | [:lang(*language*)](https://www.runoob.com/cssref/sel-lang.html) | p:lang(it) | 选择一个lang属性的起始值="it"的所有

元素 | 2 | | [*element1*~*element2*](https://www.runoob.com/cssref/sel-gen-sibling.html) | p~ul | 选择p元素之后的每一个ul元素 | 3 | | [[*attribute*^=*value*\]](https://www.runoob.com/cssref/sel-attr-begin.html) | a[src^="https"] | 选择每一个src属性的值以"https"开头的元素 | 3 | | [[*attribute*$=*value*\]](https://www.runoob.com/cssref/sel-attr-end.html) | a[src$=".pdf"] | 选择每一个src属性的值以".pdf"结尾的元素 | 3 | | [[*attribute**=*value*\]](https://www.runoob.com/cssref/sel-attr-contain.html) | a[src*="runoob"] | 选择每一个src属性的值包含子字符串"runoob"的元素 | 3 | | [:first-of-type](https://www.runoob.com/cssref/sel-first-of-type.html) | p:first-of-type | 选择每个p元素是其父级的第一个p元素 | 3 | | [:last-of-type](https://www.runoob.com/cssref/sel-last-of-type.html) | p:last-of-type | 选择每个p元素是其父级的最后一个p元素 | 3 | | [:only-of-type](https://www.runoob.com/cssref/sel-only-of-type.html) | p:only-of-type | 选择每个p元素是其父级的唯一p元素 | 3 | | [:only-child](https://www.runoob.com/cssref/sel-only-child.html) | p:only-child | 选择每个p元素是其父级的唯一子元素 | 3 | | [:nth-child(*n*)](https://www.runoob.com/cssref/sel-nth-child.html) | p:nth-child(2) | 选择每个p元素是其父级的第二个子元素 | 3 | | [:nth-last-child(*n*)](https://www.runoob.com/cssref/sel-nth-last-child.html) | p:nth-last-child(2) | 选择每个p元素的是其父级的第二个子元素,从最后一个子项计数 | 3 | | [:nth-of-type(*n*)](https://www.runoob.com/cssref/sel-nth-of-type.html) | p:nth-of-type(2) | 选择每个p元素是其父级的第二个p元素 | 3 | | [:nth-last-of-type(*n*)](https://www.runoob.com/cssref/sel-nth-last-of-type.html) | p:nth-last-of-type(2) | 选择每个p元素的是其父级的第二个p元素,从最后一个子项计数 | 3 | | [:last-child](https://www.runoob.com/cssref/sel-last-child.html) | p:last-child | 选择每个p元素是其父级的最后一个子级。 | 3 | | [:root](https://www.runoob.com/cssref/sel-root.html) | :root | 选择文档的根元素 | 3 | | [:empty](https://www.runoob.com/cssref/sel-empty.html) | p:empty | 选择每个没有任何子级的p元素(包括文本节点) | 3 | | [:target](https://www.runoob.com/cssref/sel-target.html) | #news:target | 选择当前活动的#news元素(包含该锚名称的点击的URL) | 3 | | [:enabled](https://www.runoob.com/cssref/sel-enabled.html) | input:enabled | 选择每一个已启用的输入元素 | 3 | | [:disabled](https://www.runoob.com/cssref/sel-disabled.html) | input:disabled | 选择每一个禁用的输入元素 | 3 | | [:checked](https://www.runoob.com/cssref/sel-checked.html) | input:checked | 选择每个选中的输入元素 | 3 | | [:not(*selector*)](https://www.runoob.com/cssref/sel-not.html) | :not(p) | 选择每个并非p元素的元素 | 3 | | [::selection](https://www.runoob.com/cssref/sel-selection.html) | ::selection | 匹配元素中被用户选中或处于高亮状态的部分 | 3 | | [:out-of-range](https://www.runoob.com/cssref/sel-out-of-range.html) | :out-of-range | 匹配值在指定区间之外的input元素 | 3 | | [:in-range](https://www.runoob.com/cssref/sel-in-range.html) | :in-range | 匹配值在指定区间之内的input元素 | 3 | | [:read-write](https://www.runoob.com/cssref/sel-read-write.html) | :read-write | 用于匹配可读及可写的元素 | 3 | | [:read-only](https://www.runoob.com/cssref/sel-read-only.html) | :read-only | 用于匹配设置 "readonly"(只读) 属性的元素 | 3 | | [:optional](https://www.runoob.com/cssref/sel-optional.html) | :optional | 用于匹配可选的输入元素 | 3 | | [:required](https://www.runoob.com/cssref/sel-required.html) | :required | 用于匹配设置了 "required" 属性的元素 | 3 | | [:valid](https://www.runoob.com/cssref/sel-valid.html) | :valid | 用于匹配输入值为合法的元素 | 3 | | [:invalid](https://www.runoob.com/cssref/sel-invalid.html) | :invalid | 用于匹配输入值为非法的元素 | 3 | | [:has](https://www.runoob.com/cssref/css-sel-has.html) | :has | 允许根据其后代元素来选择一个元素。 | 3 | | [:is](https://www.runoob.com/cssref/css-sel-is.html) | :is | 接收任何数量的选择器作为参数,并且返回这些选择器匹配的元素的并集。 | 3 | ## 文字与文本样式 - 字体、大小、颜色、粗细、行高 - 文本对齐、缩进、装饰、换行 * font-size :字体 大小 默认16px * font-family 字体 * font-weight: bold 加粗=700 可以自己调整 * line-height 行高 * color 字体颜色 * 文本对齐 > 1. 水平对齐 text-align 默认是left左对齐 center 居中 right 靠右 > > 2. 垂直对齐 vertical-align top 靠上 middle 靠中 bottom 靠下 (如果控制容器内容 大多数无效) > > > 解决办法: 通常设置行高 line-height=容器的高度 > > > > ~~~css > > .btn{ > > width: 200px; > > /*height=line-height 实现垂直方向居中对齐*/ > > height: 40px; > > line-height: 40px; > > background-color: #f00; > > color: #FFF; > > text-align: center; > > > > } > > ~~~ > > > > 垂直对齐 什么情况 有效果? > > > > 在同一容器内,有图片和文本,通过设置图片的居中对齐,达到与文本垂直方向 的对齐效果 缩进: > 单位: > > * px 像素 > * em 相对单位 相对于父容器 不好用 > * rem 参照根元素字体大小 换行: 应用场景: 1. 单行文本溢出 > ~~~css > /*不换行*/ > white-space: nowrap; > /*溢出的内容隐藏*/ > overflow: hidden; > /*文本溢出后 显示 ... */ > text-overflow: ellipsis; > ~~~ > > 2. 多行文本溢出 > ~~~css > div{ > width: 300px; > line-height: 30px; > height: 60px; > border: #f00 solid 1px; > > /* 溢出隐藏 */ > overflow: hidden; > /* 显示省略号 */ > text-overflow: ellipsis; > > > /* 核心:弹性盒子模型(必须) */ > display: -webkit-box; > /* 限制显示行数(改数字即可:2行/3行) */ > -webkit-line-clamp: 2; > /* 垂直排列 */ > -webkit-box-orient: vertical; > } > ~~~ > > * overflow 溢出后的行为 > 1. hidden 隐藏 > 2. scroll 滚动 * white-space: nowrap; 不换行 * text-overflow: ellipsis; 文本溢出显示 ... ## 盒子模型 - 内容 (content)、内边距 (padding)、边框 (border)、外边距 (margin) - 圆角、阴影、轮廓美化 ![image-20260303145329003](assets/image-20260303145329003.png) ### 外边距 ![image-20260303150538173](assets/image-20260303150538173.png) * margin简写: margin: 25px 50px 75px 100px ; 依次代表上右下左 边距 margin: 25px 50px 75px; 依次代表上边距 左右边距 下边距 margin: 25px 50px; 依次代表上下边距 左右边距 margin: 25px 代表四个边距 特殊用法: margin: auto ; 水平居中 ### 内边距 ![image-20260303151815288](assets/image-20260303151815288.png) padding简写: padding: 25px 50px 75px 100px ; 依次代表上右下左 内边距 padding: 25px 50px 75px; 依次代表上内边距 左右内边距 下内边距 padding: 25px 50px; 依次代表上下内边距 左右内边距 padding: 25px 代表四个内边距 ### 边框 border 常用属性: * \*-style 边框样式 > 1. dashed 虚线 > 2. dotted 点线 > 3. solid 实线 * \*-color 边框颜色 * \*-width: 边框线的宽度 设置方式 : 1. 4个边框同时设置 > ~~~css > border-style: solid; > border-color: #f00; > border-width: 1px; > > /*简化写法*/ > border: 边框宽度 颜色 样式 ; 三个值任意顺序 > ~~~ 2. 分别设置4个边框 > ~~~css > border-left: #f00 solid 1px; > border-top: #0f0 solid 1px; > border-right: #00f solid 1px; > border-bottom: #000 solid 1px; > ~~~ > > 上面都是简化方法,效果同下: > > border-方向-style: 样式 > > border-方向-color: 颜色 > > border-方向-width: 宽度 > > 方向:left top right bottom > > 对比使用:outline 外边框 属性同上。 ### 弧度/圆角 * border-bottom-left-radius 左下角 * border-bottom-right-radius 右下角 * border-top-left-radius 左上角 * border-top-right-radius 右上角 * border-radius : 4个角 ### 阴影 ~~~ box-shadow: 水平偏移 垂直偏移 模糊半径 扩散半径 颜色 内外阴影; ~~~ #### 参数解释(按顺序) 1. **水平偏移(必选)** - 正数:阴影向右 - 负数:阴影向左 2. **垂直偏移(必选)** - 正数:阴影向下 - 负数:阴影向上 3. 模糊半径(可选,默认 0) - 数值越大,阴影越模糊、越柔和 4. 扩散半径(可选,默认 0) - 正数:阴影整体放大 - 负数:阴影整体缩小 5. 颜色(可选) - 支持十六进制、rgb/rgba、hsl、颜色名 - 带透明度(rgba)效果更自然 6. 内外阴影(可选) - 默认:`outset`(外阴影) - 写 `inset`:**内阴影**(在盒子内部) ## 布局核心(工作 90% 场景) 1. 标准文档流 2. float 浮动(导航、图文环绕) 3. position 定位(固定导航、悬浮按钮、弹窗) 4. flex 弹性布局(**现代布局首选,必学**) ### float 浮动 脱离标准文档流 ,在指定父容器显示,但是它不会影响父容器高度 * left 左浮动 * right 右浮动 通常搭配:clear一起使用 clear作用:清除浮动 * left 如果float的值是left * right 如果float的值是right * both 清除左右浮动 ### position 定位 涉及到4个属性: * left * right * top * bottom * absolute 绝对定位 用的少 相对于文本的位置 * fixed 固定位置 常用于底部导航 * relative 相对于父容器定位 相对于当前所在位置 来调整 ### flex 弹性布局 单位: * vh view height 1vh=1% 高度 100vh=100%高 不考虑父容器 * vw view width 1vw=1%宽度 100vw=100%宽 不考虑父容器 函数: **calc**(100vh - 100px ); 总高-100px 就是计算后的值 ## 背景样式 - 背景颜色、图片 ## 元素显示与隐藏 - display、visibility、opacity 区别与用法 - 行内元素 / 块级元素 / 行内块元素转换