คุณสมบัติCSS flex
ตัวอย่าง
ให้รายการยืดหยุ่นทั้งหมดมีความยาวเท่ากัน โดยไม่คำนึงถึงเนื้อหา:
#main div {
-ms-flex: 1; /* IE 10 */
flex: 1;
}
เคล็ดลับ:ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
flex
ทรัพย์สินเป็นทรัพย์สินชวเลขสำหรับ:
คุณสมบัติกำหนด ความflex
ยาวที่ยืดหยุ่นได้ในรายการที่ยืดหยุ่นได้
หมายเหตุ:หากองค์ประกอบไม่ใช่รายการที่ยืดหยุ่นflex
คุณสมบัติจะไม่มีผล
ค่าเริ่มต้น: | 0 1 อัตโนมัติ |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ใช่ดูคุณสมบัติแต่ละรายการ อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS3 |
ไวยากรณ์ JavaScript: | วัตถุ .style.flex="1" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
ตัวเลขตามด้วย -webkit-, -ms- หรือ -moz- ระบุเวอร์ชันแรกที่ทำงานกับคำนำหน้า
Property | |||||
---|---|---|---|---|---|
flex | 29.0 21.0 -webkit- |
11.0 10.0 -ms- |
28.0 18.0 -moz- |
9.0 6.1 -webkit- |
17.0 |
ไวยากรณ์ CSS
flex: flex-grow flex-shrink flex-basis|auto|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description |
---|---|
flex-grow | A number specifying how much the item will grow relative to the rest of the flexible items |
flex-shrink | A number specifying how much the item will shrink relative to the rest of the flexible items |
flex-basis | The length of the item. Legal values: "auto", "inherit", or a number followed by "%", "px", "em" or any other length unit |
auto | Same as 1 1 auto. |
initial | Same as 0 1 auto. Read about initial |
none | Same as 0 0 auto. |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ใช้flex
ร่วมกับคิวรี่สื่อเพื่อสร้างเลย์เอาต์ที่แตกต่างกันสำหรับขนาดหน้าจอ/อุปกรณ์ต่างๆ:
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-item-left {
flex: 50%;
}
.flex-item-right {
flex: 50%;
}
/* Responsive layout - makes a one column layout (100%) instead of a two-column
layout (50%) */
@media (max-width: 800px) {
.flex-item-right,
.flex-item-left {
flex: 100%;
}
}
หน้าที่เกี่ยวข้อง
บทช่วยสอน CSS: CSS Flexible Box
การอ้างอิง CSS: คุณสมบัติพื้นฐานแบบยืดหยุ่น
การอ้างอิง CSS: คุณสมบัติ flex-direction
การอ้างอิง CSS: คุณสมบัติ flex-flow
การอ้างอิง CSS: คุณสมบัติ flex-grow
การอ้างอิง CSS: คุณสมบัติ flex-shrink
การอ้างอิง CSS: คุณสมบัติ flex-wrap
การอ้างอิง HTML DOM: flex property