คุณสมบัติ HTML DOM justifyContent ใช้สำหรับจัดแนวรายการดิ้นในแนวนอนบนแกนหลัก เมื่อไม่ได้ใช้พื้นที่ทั้งหมดที่มี
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ justifyContent -
object.style.justifyContent = "flex-start|flex-end|center|space-between|space-around|initial|inherit"
อธิบายคุณสมบัติข้างต้นดังนี้ −
| ค่า | คำอธิบาย |
|---|---|
| flex-start | ตำแหน่งนี้จะวางตำแหน่งรายการไว้ที่จุดเริ่มต้นคอนเทนเนอร์และเป็นค่าเริ่มต้น |
| flex-end | จัดตำแหน่งสิ่งของที่ส่วนท้ายของคอนเทนเนอร์ |
| center | วางตำแหน่งสินค้าไว้ที่ศูนย์กลางคอนเทนเนอร์ |
| ช่องว่างระหว่าง | จัดตำแหน่งรายการด้วยช่องว่างระหว่างบรรทัด |
| ช่องว่างรอบ ๆ | จัดตำแหน่งรายการด้วยช่องว่างระหว่าง ก่อนและหลัง thelines |
| ค่าเริ่มต้น | การตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
ให้เราดูตัวอย่างคุณสมบัติ justifyContent -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#demo {
margin: auto;
width: 400px;
height: 120px;
box-shadow: 0 0 0 5px brown;
display: flex;
flex-wrap: wrap;
}
#demo div {
padding: 0;
width: 50px;
height: 50px;
border: 5px solid;
border-radius: 15%;
}
#demo div:nth-child(even) {
border-color: black;
}
#demo div:nth-child(odd) {
border-color: red;
}
</style>
<script>
function changeJustifyContent() {
document.getElementById("demo").style.justifyContent="space-between";
document.getElementById("Sample").innerHTML="The justify-content property is now set to space between";
}
</script>
</head>
<body>
<div id="demo">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<p>Change the above container justify-content property by clicking the below button</p>
<button onclick="changeJustifyContent()">Change Justify Content</button>
<p id="Sample"></p>
</body> ผลลัพธ์

เมื่อคลิกปุ่ม “เปลี่ยน Justify Content ปุ่ม −
