Skip to content

Commit d5968a5

Browse files
author
wangpl
committed
first commit🚀
0 parents  commit d5968a5

File tree

52 files changed

+26875
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+26875
-0
lines changed

CSS/CSS的基础知识.md

Lines changed: 622 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## position: fixed什么时候会失效?
2+
我们知道,设置了`position: fixed`固定定位属性的元素会脱离文档流,达到“超然脱俗”的境界。
3+
也就是说此时给这种元素设置`top, left, right, bottom`等属性是根据**浏览器窗口**定位的,与其上级元素的位置无关。
4+
但是有一种情况例外:
5+
若是设置了`position: fixed`属性的元素,它的上级元素设置了`transform`属性则会导致固定定位属性失效。
6+
无论你的`transform`设置的是什么属性都会影响到`position: fixed`
7+
看下面的案例1:
8+
```html
9+
<style>
10+
.father {
11+
width: 300px;
12+
height: 300px;
13+
background: yellow;
14+
transform: translate(100px);
15+
/* transform: scale(0.5); */
16+
/* transform: rotate(-45deg); */
17+
}
18+
.son {
19+
width: 100px;
20+
height: 100px;
21+
background: red;
22+
position: fixed;
23+
top: 400px;
24+
}
25+
</style>
26+
<body>
27+
<div class="father">
28+
<div class="son"></div>
29+
</div>
30+
</body>
31+
```
32+
给父级加上了`transform`属性之后就会影响子级的固定定位了。如下图:
33+
![没加transform.png](https://upload-images.jianshu.io/upload_images/7190596-38462e3ec67bd654.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
34+
35+
![加了transform.png](https://upload-images.jianshu.io/upload_images/7190596-5bcc360baa0d652b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
36+
37+
**其实不仅仅是给父级加`transform`属性会失效,只要上级存在`transform`属性都会导致`position: fixed`失效。**
38+
39+
案例2:
40+
```html
41+
<style>
42+
.content{
43+
transform: translate(100px);
44+
}
45+
.father {
46+
width: 300px;
47+
height: 300px;
48+
background: yellow;
49+
}
50+
.son {
51+
width: 100px;
52+
height: 100px;
53+
background: red;
54+
position: fixed;
55+
top: 400px;
56+
}
57+
</style>
58+
<body>
59+
<div class="content">
60+
<div class="father">
61+
<div class="son"></div>
62+
</div>
63+
</div>
64+
</body>
65+
```
66+
上面的案例也会影响`position: fixed`属性。

CSS/伪类.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# nth伪类选择器
2+
3+
## 1 :nth-child(){ }
4+
5+
> 作用: 选择父元素的第几个子元素
6+
7+
```html
8+
<body>
9+
<div>
10+
<p></p>
11+
<p></p>
12+
<p></p>
13+
</div>
14+
</body>
15+
```
16+
17+
### 用法1:所有子元素:
18+
19+
```css
20+
div:nth-child(n){
21+
color: red;
22+
}
23+
```
24+
25+
26+
27+
### 用法2:所有奇数子元素:
28+
29+
```css
30+
div:nth-child(2n+1){
31+
color: red;
32+
}
33+
```
34+
35+
36+
37+
### 用法3:所有偶数子元素 :
38+
39+
```css
40+
div:nth-child(2n){
41+
color: red;
42+
}
43+
```
44+
45+
46+
47+
### 用法4:选择父元素的第几个子元素
48+
49+
```css
50+
div:nth-child(2){
51+
color: red;
52+
}
53+
```
54+
55+
56+
57+
### 用法5:选择父元素标签内部第n个元素
58+
59+
**第n个元素必须的是:前面的这个标签才能生效 如果匹配失败,则不生效**
60+
61+
例:
62+
63+
```html
64+
<style>
65+
ul p:nth-child(2) {
66+
background: red;/*无效:想选择的是ul下的第二个p标签,但ul标签中没有p标签 所以不能生效;*/
67+
}
68+
ul li:nth-child(2) {/*有效:想选择的是ul下的第二个li标签,nth-child(2)前面也是li 所以能生效;*/
69+
background: red;
70+
}
71+
</style>
72+
<body>
73+
<ul>
74+
<li>我是li1</li>
75+
<li>我是li2</li>
76+
</ul>
77+
</body>
78+
```
79+
80+
### 用法6 :nth-child(n+m){}
81+
82+
> 表示从第m个值开始,取包裹m的之后的所有项
83+
84+
例:
85+
86+
```
87+
:nth-child(n+2){} 表示选取除了第一项的所有项
88+
89+
:nth-child(-n+m){} 表示选取前m项(包裹m)
90+
如::nth-child(-n+2) 表示选取第一第二项;
91+
```
92+
93+
94+
95+
## 2 :nth-last-child(){}
96+
97+
> 用法:与`:nth-child()`用法相似,不过是从后往前
98+
99+
如:
100+
101+
选择父元素的倒数第二个子元素的 div 标签
102+
103+
```css
104+
div:nth-last-child(2){ }
105+
```
106+
107+
108+
109+
## 3 :nth-of-type(){ }
110+
111+
> 作用:选择属于其父元素的 第几个标签元素
112+
113+
例:选择父元素的第二个p标签和第二个li标签
114+
115+
```html
116+
<style>
117+
ul p:nth-of-type(2) {
118+
background: red;
119+
}
120+
ul li:nth-of-type(2) {
121+
background: red;
122+
}
123+
</style>
124+
<body>
125+
<ul>
126+
<p>我是p1</p>
127+
<p>我是p2</p><!--红色-->
128+
<li>我是li1</li>
129+
<li>我是li2</li><!--红色-->
130+
</ul>
131+
</body>
132+
```
133+
134+
135+
136+
## 4 :nth-last-of-type(){ }
137+
138+
> 选择属于其父元素的倒数 第几个标签元素
139+
140+
141+

0 commit comments

Comments
 (0)