คุณสมบัติ HTML DOM Style alignItems ใช้สำหรับกล่าวถึงการจัดตำแหน่งเริ่มต้นของรายการที่มีอยู่ภายในคอนเทนเนอร์แบบยืดหยุ่น
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ alignItems -
object.style.alignContent = " stretch|center|flex-start|flex-end|baseline|initial|inherit"
คุณค่า
ค่าต่อไปนี้สามารถเป็นค่าได้ -
| ค่า | คำอธิบาย |
|---|---|
| ยืดกล้ามเนื้อ | เป็นค่าเริ่มต้นและใช้เพื่อยืดรายการให้พอดีกับคอนเทนเนอร์ |
| ศูนย์ | ใช้สำหรับวางสินค้าไว้ตรงกลางคอนเทนเนอร์ |
| เริ่มต้นแบบยืดหยุ่น | เพื่อวางตำแหน่งรายการไว้ที่จุดเริ่มต้นของคอนเทนเนอร์ |
| ปลายงอ | การวางตำแหน่งสิ่งของที่ส่วนท้ายของคอนเทนเนอร์ |
| พื้นฐาน | การวางตำแหน่งสิ่งของที่เส้นฐานของคอนเทนเนอร์ |
| เริ่มต้น | สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
ตัวอย่าง
ให้เราดูตัวอย่างของคุณสมบัติ Style alignItems -
<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 180px;
height: 220px;
padding: 10px;
border: 1px solid #333;
display: flex;
align-items:flex-end;
flex-flow: row wrap;
}
.ele {
width: 60px;
height: 60px;
background-color: skyblue;
}
.ele:nth-child(2n) {
background-color: orange;
}
</style>
<script>
function changeAlign(){
document.getElementById("container").style.alignItems="baseline";
}
</script>
</head>
<body>
<h2>Demo Heading</h2>
<div id="container">
<div class="ele"></div>
<div class="ele"></div>
<div class="ele"></div>
</div>
<p>Change the align items property of the above div by clicking the button</p>
<button onclick="changeAlign()">CHANGE</button>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

เมื่อคลิกปุ่ม CHANGE -
