Thuộc tính CSS
position =1 đặt cách một phần tử được định vị trong tài liệu. Các thuộc tính
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5 xác định vị trí cuối cùng của các phần tử được định vị
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position: static;
position: relative;
position: absolute;
position: fixed;
position: sticky;
/* Global values */
position: inherit;
position: initial;
position: revert;
position: revert-layer;
position: unset;
position =6
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Phần tử được định vị theo quy trình bình thường của tài liệu. Các thuộc tính
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
One
Two
Three
Four
1 không có hiệu lực. Đây là giá trị mặc địnhOne
Two
Three
Four
2Phần tử được định vị theo quy trình bình thường của tài liệu, sau đó bù tương đối với chính nó dựa trên các giá trị của
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5. Phần bù không ảnh hưởng đến vị trí của bất kỳ phần tử nào khác;
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Giá trị này tạo ngữ cảnh xếp chồng mới khi giá trị của
One
Two
Three
Four
1 không phải là One
Two
Three
Four
9. Ảnh hưởng của nó đối với các phần tử * {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
0, * {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
1, * {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
2, * {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
3 và * {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
4 là không xác định* {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
5Phần tử bị xóa khỏi luồng tài liệu thông thường và không có khoảng trống nào được tạo cho phần tử trong bố cục trang. Nó được định vị so với tổ tiên gần nhất của nó, nếu có; . Vị trí cuối cùng của nó được xác định bởi các giá trị của
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Giá trị này tạo ngữ cảnh xếp chồng mới khi giá trị của
One
Two
Three
Four
1 không phải là One
Two
Three
Four
9. Lề của hộp được định vị tuyệt đối không sụp đổ với các lề khácAbsolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
2Phần tử bị xóa khỏi luồng tài liệu thông thường và không có khoảng trống nào được tạo cho phần tử trong bố cục trang. Nó được định vị tương đối so với khối chứa ban đầu được thiết lập bởi khung nhìn, ngoại trừ khi một trong các tổ tiên của nó có thuộc tính
Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
3, Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
4 hoặc Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
5 được đặt thành một thứ khác với Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
6 [xem phần ], hoặc thuộc tính Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
7 được đặt thành Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
3, trong . [Lưu ý rằng có sự không nhất quán của trình duyệt với Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
4 và Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
5 góp phần ngăn chặn sự hình thành khối. ] Vị trí cuối cùng của nó được xác định bởi các giá trị của position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Giá trị này luôn tạo bối cảnh xếp chồng mới. Trong các tài liệu in, phần tử được đặt ở cùng một vị trí trên mỗi trang
* {
box-sizing: border-box;
}
body {
width: 500px;
margin: 0 auto;
}
p {
background: aqua;
border: 3px solid blue;
padding: 10px;
margin: 10px;
}
span {
background: red;
border: 1px solid black;
}
.positioned {
position: absolute;
background: yellow;
top: 30px;
left: 30px;
}
5Phần tử được định vị theo quy trình bình thường của tài liệu, sau đó bù tương ứng với tổ tiên cuộn gần nhất của nó và khối chứa [tổ tiên cấp khối gần nhất], bao gồm các phần tử liên quan đến bảng, dựa trên các giá trị của
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4, . Phần bù không ảnh hưởng đến vị trí của bất kỳ phần tử nào khác
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Giá trị này luôn tạo bối cảnh xếp chồng mới. Lưu ý rằng phần tử dính "dính" vào tổ tiên gần nhất của nó có "cơ chế cuộn" [được tạo khi
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
One
0 là
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
One
1,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
One
2, One
Two
Three
Four
9 hoặc
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
One
4], ngay cả khi tổ tiên đó không phải là tổ tiên cuộn thực sự gần nhất- Phần tử được định vị là phần tử có giá trị
position =
1 được tính toán là
static |
relative |
absolute |
sticky |
fixed |
running[ ]
2,One Two Three Four
5,* { box-sizing: border-box; } .box { display: inline-block; width: 100px; height: 100px; background: red; color: white; } #two { position: relative; top: 20px; left: 20px; background: blue; }
2 hoặcAbsolute positioning I am a basic block level element. My adjacent block level elements sit on new lines below me. By default we span 100% of the width of our parent element, and we are as tall as our child content. Our total width and height is our content + padding + border width/height. We are separated by our margins. Because of margin collapsing, we are separated by the width of one of our margins, not both. inline elements like this one and this one sit on the same line as one another, and adjacent text nodes, if there is space on the same line. Overflowing inline elements wrap onto a new line if possible — like this one containing text, or just go on to a new line if not, much like this image will do:
5. [Nói cách khác, đó là bất cứ điều gì ngoại trừ* { box-sizing: border-box; } body { width: 500px; margin: 0 auto; } p { background: aqua; border: 3px solid blue; padding: 10px; margin: 10px; } span { background: red; border: 1px solid black; } .positioned { position: absolute; background: yellow; top: 30px; left: 30px; }
position =
6. ]
static |
relative |
absolute |
sticky |
fixed |
running[ ] - Phần tử được định vị tương đối là phần tử có giá trị
position =
1 được tính toán là
static |
relative |
absolute |
sticky |
fixed |
running[ ]
2. Các thuộc tínhOne Two Three Four
position =
2 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
4 chỉ định phần bù dọc từ vị trí bình thường của nó;
static |
relative |
absolute |
sticky |
fixed |
running[ ] - Một phần tử được định vị tuyệt đối là một phần tử có giá trị
position =
1 được tính toán là
static |
relative |
absolute |
sticky |
fixed |
running[ ]
5 hoặc* { box-sizing: border-box; } .box { display: inline-block; width: 100px; height: 100px; background: red; color: white; } #two { position: relative; top: 20px; left: 20px; background: blue; }
2. Các thuộc tínhAbsolute positioning I am a basic block level element. My adjacent block level elements sit on new lines below me. By default we span 100% of the width of our parent element, and we are as tall as our child content. Our total width and height is our content + padding + border width/height. We are separated by our margins. Because of margin collapsing, we are separated by the width of one of our margins, not both. inline elements like this one and this one sit on the same line as one another, and adjacent text nodes, if there is space on the same line. Overflowing inline elements wrap onto a new line if possible — like this one containing text, or just go on to a new line if not, much like this image will do:
position =
2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
4 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
5 chỉ định độ lệch từ các cạnh của khối chứa phần tử. [Khối chứa là tổ tiên liên quan đến phần tử được định vị. ] Nếu phần tử có lề, chúng sẽ được thêm vào phần bù. Phần tử thiết lập bối cảnh định dạng khối mới [BFC] cho nội dung của nó
static |
relative |
absolute |
sticky |
fixed |
running[ ] - Phần tử được định vị dính là phần tử có giá trị
position =
1 được tính toán là
static |
relative |
absolute |
sticky |
fixed |
running[ ]
5. Nó được coi là ở vị trí tương đối cho đến khi khối chứa nó vượt qua một ngưỡng đã chỉ định [chẳng hạn như đặt* { box-sizing: border-box; } body { width: 500px; margin: 0 auto; } p { background: aqua; border: 3px solid blue; padding: 10px; margin: 10px; } span { background: red; border: 1px solid black; } .positioned { position: absolute; background: yellow; top: 30px; left: 30px; }
position =
2 thành giá trị khác với tự động] trong gốc luồng của nó [hoặc vùng chứa mà nó cuộn bên trong], tại thời điểm đó, nó được coi là "bị kẹt" cho đến khi đáp ứng
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Hầu hết thời gian, các yếu tố được định vị tuyệt đối có
#one {
position: sticky;
top: 10px;
}
7 và #one {
position: sticky;
top: 10px;
}
8 được đặt thành One
Two
Three
Four
9 có kích thước sao cho phù hợp với nội dung của chúng. Tuy nhiên, các phần tử không được thay thế, được định vị tuyệt đối có thể được tạo để lấp đầy khoảng trống theo chiều dọc có sẵn bằng cách chỉ định cả position =2 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 và để lại
static |
relative |
absolute |
sticky |
fixed |
running[ ]
#one {
position: sticky;
top: 10px;
}
7 không được chỉ định [nghĩa là, One
Two
Three
Four
9]. Tương tự như vậy, chúng có thể được tạo để lấp đầy khoảng trống theo chiều ngang có sẵn bằng cách chỉ định cả position =5 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3 và để lại
static |
relative |
absolute |
sticky |
fixed |
running[ ]
#one {
position: sticky;
top: 10px;
}
8 là One
Two
Three
Four
9Ngoại trừ trường hợp vừa được mô tả [của các phần tử được định vị tuyệt đối lấp đầy không gian có sẵn]
- Nếu cả
position =
2 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
4 đều được chỉ định [về mặt kỹ thuật, không phải
static |
relative |
absolute |
sticky |
fixed |
running[ ]
9], thìOne Two Three Four
position =
2 sẽ thắng
static |
relative |
absolute |
sticky |
fixed |
running[ ] - Nếu cả
position =
5 và
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
3 đều được chỉ định, thì
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
5 thắng khi
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
05 là
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
06 [tiếng Anh, tiếng Nhật ngang, v.v. ] và
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
3 thắng khi
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
05 là
static |
relative |
absolute |
sticky |
fixed |
running[ ]position =
09 [tiếng Ba Tư, tiếng Ả Rập, tiếng Do Thái, v.v. ]
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Đảm bảo rằng các thành phần được định vị bằng giá trị
* {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
5 hoặc Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
2 không che khuất nội dung khác khi trang được thu phóng để tăng kích thước văn bản- Trình bày trực quan. Hiểu SC 1. 4. số 8. Hiểu về WCAG 2. 0
Các phần tử cuộn chứa nội dung
Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
2 hoặc * {
box-sizing: border-box;
}
body {
width: 500px;
margin: 0 auto;
}
p {
background: aqua;
border: 3px solid blue;
padding: 10px;
margin: 10px;
}
span {
background: red;
border: 1px solid black;
}
.positioned {
position: absolute;
background: yellow;
top: 30px;
left: 30px;
}
5 có thể gây ra các vấn đề về hiệu suất và khả năng truy cập. Khi người dùng cuộn, trình duyệt phải vẽ lại nội dung dính hoặc cố định ở một vị trí mới. Tùy thuộc vào nội dung cần vẽ lại, hiệu suất của trình duyệt và tốc độ xử lý của thiết bị, trình duyệt có thể không quản lý được các lần sơn lại ở tốc độ 60 khung hình/giây, gây lo ngại về khả năng truy cập cho những người nhạy cảm và gây khó khăn cho mọi người. Một giải pháp là thêm position =14 vào các phần tử đã định vị để hiển thị phần tử trong lớp riêng của nó, cải thiện tốc độ vẽ lại và do đó cải thiện hiệu suất và khả năng truy cập
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Giá trị ban đầu_______0_______6Áp dụng cho tất cả các phần tửKế thừakhôngGiá trị tính toánnhư đã chỉ địnhKiểu hoạt ảnhrời rạcTạo bối cảnh xếp chồngcó
position =
static |
relative |
absolute |
sticky |
fixed |
running[ ]
Các phần tử được định vị tương đối được bù một lượng nhất định so với vị trí bình thường của chúng trong tài liệu nhưng không có phần bù ảnh hưởng đến các phần tử khác. Trong ví dụ dưới đây, lưu ý cách các phần tử khác được đặt như thể "Hai" đang chiếm không gian của vị trí bình thường của nó
HTML
One
Two
Three
Four
CSS
* {
box-sizing: border-box;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background: red;
color: white;
}
#two {
position: relative;
top: 20px;
left: 20px;
background: blue;
}
Các yếu tố được định vị tương đối vẫn nằm trong luồng thông thường của tài liệu. Ngược lại, một phần tử được định vị tuyệt đối sẽ bị loại khỏi luồng; . Phần tử được định vị tuyệt đối được định vị tương ứng với tổ tiên được định vị gần nhất của nó [i. e. , tổ tiên gần nhất không phải là
position =6]. Nếu tổ tiên được định vị không tồn tại, thì nó được định vị tương ứng với ICB [khối chứa ban đầu — xem thêm phần ], là khối chứa phần tử gốc của tài liệu
static |
relative |
absolute |
sticky |
fixed |
running[ ]
HTML
Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
CSS
* {
box-sizing: border-box;
}
body {
width: 500px;
margin: 0 auto;
}
p {
background: aqua;
border: 3px solid blue;
padding: 10px;
margin: 10px;
}
span {
background: red;
border: 1px solid black;
}
.positioned {
position: absolute;
background: yellow;
top: 30px;
left: 30px;
}
Kết quả
Định vị cố định tương tự như định vị tuyệt đối, ngoại trừ khối chứa phần tử là khối chứa ban đầu được thiết lập bởi khung nhìn, trừ khi bất kỳ tổ tiên nào có thuộc tính
Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
3, Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
4 hoặc Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
5 được đặt thành thứ gì đó khác với Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
6 [xem ], sau đó gây ra . Điều này có thể được sử dụng để tạo một phần tử "nổi" ở cùng một vị trí bất kể cuộn. Trong ví dụ bên dưới, hộp "Một" được cố định ở 80 pixel từ đầu trang và 10 pixel từ bên trái. Ngay cả sau khi cuộn, nó vẫn ở cùng một vị trí so với khung nhìn. Ngoài ra, khi thuộc tính Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
7 được đặt thành Absolute positioning
I am a basic block level element. My adjacent block level elements sit on new
lines below me.
By default we span 100% of the width of our parent element, and we are as tall
as our child content. Our total width and height is our content + padding +
border width/height.
We are separated by our margins. Because of margin collapsing, we are
separated by the width of one of our margins, not both.
inline elements like this one and this one sit on
the same line as one another, and adjacent text nodes, if there is space on
the same line. Overflowing inline elements
wrap onto a new line if possible — like this one containing text,
or just go on to a new line if not, much like this image will do:
3, một khối chứa mới được thiết lậpHTML
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam congue tortor
eget pulvinar lobortis. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam ac dolor augue. Pellentesque mi mi,
laoreet et dolor sit amet, ultrices varius risus. Nam vitae iaculis elit.
Aliquam mollis interdum libero. Sed sodales placerat egestas. Vestibulum ut
arcu aliquam purus viverra dictum vel sit amet mi. Duis nisl mauris, aliquam
sit amet luctus eget, dapibus in enim. Sed velit augue, pretium a sem
aliquam, congue porttitor tortor. Sed tempor nisl a lorem consequat, id
maximus erat aliquet. Sed sagittis porta libero sed condimentum. Aliquam
finibus lectus nec ante congue rutrum. Curabitur quam quam, accumsan id
ultrices ultrices, tempor et tellus.
One
CSS
* {
box-sizing: border-box;
}
.box {
width: 100px;
height: 100px;
background: red;
color: white;
}
#one {
position: fixed;
top: 80px;
left: 10px;
background: blue;
}
.outer {
width: 500px;
height: 300px;
overflow: scroll;
padding-left: 150px;
}
Kết quả
Định vị cố định có thể được coi là sự kết hợp giữa định vị tương đối và cố định khi tổ tiên cuộn gần nhất của nó là chế độ xem. Một phần tử được định vị dính được coi là được định vị tương đối cho đến khi nó vượt qua một ngưỡng xác định, tại thời điểm đó, nó được coi là cố định cho đến khi nó đạt đến ranh giới của phần tử cha của nó. Ví dụ
#one {
position: sticky;
top: 10px;
}
Quy tắc CSS ở trên sẽ định vị phần tử có id một cách tương đối cho đến khi chế độ xem được cuộn sao cho phần tử sẽ nhỏ hơn 10 pixel tính từ trên xuống. Vượt quá ngưỡng đó, phần tử sẽ được cố định thành 10 pixel tính từ trên xuống
Một cách sử dụng phổ biến cho định vị cố định là dành cho các tiêu đề trong danh sách được sắp xếp theo thứ tự bảng chữ cái. Tiêu đề "B" sẽ xuất hiện ngay bên dưới các mục bắt đầu bằng "A" cho đến khi chúng được cuộn ra khỏi màn hình. Thay vì trượt ra khỏi màn hình với phần còn lại của nội dung, tiêu đề "B" sau đó sẽ được cố định ở trên cùng của chế độ xem cho đến khi tất cả các mục "B" đã cuộn ra khỏi màn hình, tại thời điểm đó, nó sẽ bị che bởi chữ "C"
Bạn phải chỉ định một ngưỡng có ít nhất một trong số
position =2,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =3,
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =4 hoặc
static |
relative |
absolute |
sticky |
fixed |
running[ ]
position =5 để định vị cố định hoạt động như mong đợi. Nếu không, nó sẽ không thể phân biệt được với định vị tương đối
static |
relative |
absolute |
sticky |
fixed |
running[ ]