diff --git "a/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241017-\346\265\256\345\212\250.md" "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241017-\346\265\256\345\212\250.md" index abdfd71dde9ea64e9300a9c2d97cce339ab4e586..99adfedb5f54d0edda8f025c1c803515f96aa77c 100644 --- "a/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241017-\346\265\256\345\212\250.md" +++ "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241017-\346\265\256\345\212\250.md" @@ -211,7 +211,8 @@ ## 练习 -### 效果: +### 效果: + diff --git "a/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241021-css\345\256\232\344\275\215.md" "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241021-css\345\256\232\344\275\215.md" new file mode 100644 index 0000000000000000000000000000000000000000..1c0682644a03e6e5cf93b5417c51312599148abb --- /dev/null +++ "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241021-css\345\256\232\344\275\215.md" @@ -0,0 +1,124 @@ +## CSS定位 + +CSS的定位属性有三种,分别是绝对定位、相对定位、固定定位。 + +``` + position: absolute; + + position: relative; + + position: fixed; + +``` + +### 相对定位 + +**相对定位**:让元素相对于自己原来的位置,进行位置调整(可用于盒子的位置微调)。 + +相对定位不脱标,**别人不会把它的位置挤走**。 + +***相对定位的用途*** +- 微调元素 +- 做绝对定位的参考,子绝父相 + +### 绝对定位 + +**绝对定位**:定义横纵坐标。原点在父容器的左上角或左下角。横坐标用left表示,纵坐标用top或者bottom表示。 + +**绝对定位的盒子脱离了标准文档流。** + +所以,所有的标准文档流的性质,绝对定位之后都不遵守了。 + + + +### 子绝父相 +子元素绝对定位,父元素相对定位 +“**子绝父相**”有意义:这样可以保证父亲没有脱标,儿子脱标在父亲的范围里面移动。于是,工程上经常这样做: + +> 父亲浮动,设置相对定位(零偏移),然后让儿子绝对定位一定的距离。 + +对于父元素的定位,具有优先级。在一个父级元素中嵌套的话,选取绝对定位子元素的上一个拥有定位的元素为父级。(就近原则) + +### 固定定位 + +**固定定位**:就是相对浏览器窗口进行定位。无论页面如何滚动,这个盒子显示的位置不变。 + +### z-index +z-index属性的应用还是很广泛的。当好几个已定位的标签出现覆盖的现象时,我们可以用这个z-index属性决定,谁处于最上方。也就是**层级**的应用。 +**使用这个属性的元素必须具有定位** + +## 练习 + +### 效果: + + + +### 代码: + +```css + div { + height: 200px; + width: 300px; + position: absolute; + border: 1px solid black; + left: 0; + top: 0; + right: 0; + bottom: 0; + margin: auto; + } +``` + +### 效果: + + + +### 代码: +```css + #top { + width: 100%; + height: 50px; + position: fixed; + background-color: black; + top: 0; + + } +``` + + +### 效果: + + + +### 代码: +```css + p { + position: relative; + display: inline-block; + cursor: pointer; + width: 120px; + height: 100px; + } + + .tooltip { + display: none; + width: 120px; + background-color: #555; + color: #fff; + text-align: center; + border-radius: 5px; + padding: 5px; + position: absolute; + z-index: 1; + bottom: 25px; + left: 50%; + margin-left: -60px; + opacity: 0; + transition: opacity 0.3s; + } + + p:hover .tooltip { + display: block; + opacity: 1; + } +``` \ No newline at end of file diff --git "a/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241023-\347\262\276\347\201\265\345\233\276.md" "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241023-\347\262\276\347\201\265\345\233\276.md" new file mode 100644 index 0000000000000000000000000000000000000000..8e1adeaf8dc24eec2631538712494f674c7ab9c1 --- /dev/null +++ "b/\347\216\213\350\212\267\345\256\201/\347\254\224\350\256\260/20241023-\347\262\276\347\201\265\345\233\276.md" @@ -0,0 +1,245 @@ +## 精灵图 +精灵图(Sprite),也被称为雪碧图或CSS Sprite,是一种有效的网页图片应用处理方式。 + +将多个小图标或图片合并到一张大图中,然后通过CSS定位来显示需要显示的图片部分。 + +作用:**减少网页的HTTP请求数量**,因为所有小图标或图片都整合在一张大图中,只需要一次HTTP请求就可以加载。 + +使用:首先,将制作好的精灵图上传到网站的服务器或静态资源文件夹中。然后,在CSS中通过**background-image**属性设置元素的背景图片为精灵图。 + + +假设有一个包含多个服务图标的精灵图,需要在网页上显示这些图标。可以使用以下CSS代码来实现: + +``` +css +.service { + /* 其他样式设置 */ +} + +.service ul { + display: flex; +} + +.service li { + display: flex; + /* 其他样式设置 */ +} + +.service li h5 { + width: 36px; + height: 42px; + background: url(./images/sprite.png) 0 -192px no-repeat; /* 精灵图路径和定位 */ +} + +.service li:nth-child(2) h5 { + background-position: -41px -192px; /* 第二个图标的定位 */ +} + +.service li:nth-child(3) h5 { + background-position: -82px -192px; /* 第三个图标的定位 */ +} + + +``` +## 属性选择器 +1. 存在选择器: + +**[指定属性]** + +选择所有具有指定属性的元素,不论其属性值为何。 + +2. 完全匹配选择器: + + **[指定属性 = "值" ]** + +选择属性值完全等于指定值的元素。 + +3. 开始匹配选择器: + +**[指定属性 ^ = " 值" ]** + +选择属性值以指定值开始的元素。 + +4. 结束匹配选择器: + +**[指定属性 $ = " 值" ]** + +选择属性值以指定值结束的元素。 + +5. 包含匹配选择器: + +**[指定属性 * = " 值" ]** + +选择属性值包含指定字符串的元素。 + +6. 词匹配选择器: + +**[指定属性 ~ = " 值" ]** + +选择属性值中包含指定单词的元素,单词由空格分隔。 + + 7.前缀匹配选择器(主要用于语言代码或文档类型等属性): + +**[指定属性 | = " 值" ]** + +选择属性值以指定值开始或者完全等于指定值的元素。 + +## 练习 + +### 效果: + + + +### 代码: + +```css + div{ + height: 32px; + width: 35px; + background-size: 100px; + background-image: url(./img/20231010113053.png); + background-repeat: no-repeat; + } + p{ + margin-top: -30px; + margin-left: 40px; + padding-top: 5px; + } + + .l1{ + background-position: 0 0; + } + .l2{ + background-position: -32px 0; + } + .l3{ + background-position: 0 -32px; + } + .l4{ + background-position: -32px -32px; + } + .l5{ + background-position: -64px 0; + } + .l6{ + background-position: -64px -32px; + } +``` + +### 效果: + + + +### 代码: + +```html + + + +
+ + +广东深圳宝安区建安一路海雅缤纷城4楼
+单人电影票,可观看2D
+¥35¥80 + 225已售 +
+