CSS justify-เนื้อหาคุณสมบัติ
ตัวอย่าง
จัดแนวรายการแบบยืดหยุ่นที่กึ่งกลางของคอนเทนเนอร์:
div
{
display: flex;
justify-content: center;
}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติjustify-content
จะจัดเรียงรายการของคอนเทนเนอร์แบบยืดหยุ่นเมื่อรายการไม่ได้ใช้พื้นที่ว่างทั้งหมดบนแกนหลัก (ในแนวนอน)
เคล็ดลับ:ใช้คุณสมบัติalign-itemsเพื่อจัดแนวรายการในแนวตั้ง
ค่าเริ่มต้น: | flex-start |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ไม่. อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS3 |
ไวยากรณ์ JavaScript: | วัตถุ .style.justifyContent="space-between" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
ตัวเลขตามด้วย -webkit- หรือ -moz- ระบุเวอร์ชันแรกที่ทำงานกับคำนำหน้า
Property | |||||
---|---|---|---|---|---|
justify-content | 29.0 21.0 -webkit- |
11.0 | 28.0 18.0 -moz- |
9.0 6.1 -webkit- |
17.0 |
ไวยากรณ์ CSS
justify-content: flex-start|flex-end|center|space-between|space-around|space-evenly|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description | Play it |
---|---|---|
flex-start | Default value. Items are positioned at the beginning of the container | |
flex-end | Items are positioned at the end of the container | |
center | Items are positioned in the center of the container | |
space-between | Items will have space between them | |
space-around | Items will have space before, between, and after them | |
space-evenly | Items will have equal space around them | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
จัดแนวรายการ flex ที่จุดเริ่มต้นของคอนเทนเนอร์ (ซึ่งเป็นค่าเริ่มต้น):
div
{
display: flex;
justify-content: flex-start;
}
ตัวอย่าง
จัดแนวรายการแบบยืดหยุ่นที่ส่วนท้ายของคอนเทนเนอร์:
div
{
display: flex;
justify-content: flex-end;
}
ตัวอย่าง
แสดงรายการแบบยืดหยุ่นพร้อมช่องว่างระหว่างบรรทัด:
div
{
display: flex;
justify-content: space-between;
}
ตัวอย่าง
แสดงรายการ flex โดยเว้นวรรคก่อน ระหว่าง และหลังบรรทัด:
div
{
display: flex;
justify-content: space-around;
}
หน้าที่เกี่ยวข้อง
การอ้างอิง CSS: คุณสมบัติการจัดตำแหน่งเนื้อหา
การอ้างอิง CSS: align-items property
การอ้างอิง CSS: align-self property
การอ้างอิง HTML DOM: justifyContent คุณสมบัติ