Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

องค์ประกอบระดับอินไลน์ (Inline-level) และกล่องอินไลน์ (Inline Boxes) ใน CSS


องค์ประกอบระดับอินไลน์ (Inline-level elements) มีคุณสมบัติ CSS display ตั้งค่าเป็น 'inline', 'inline-table', หรือ 'inline-block' และองค์ประกอบเหล่านี้ไม่บังคับให้เกิดการขึ้นบรรทัดใหม่ด้านบนและด้านล่าง กล่องอินไลน์ (Inline-level boxes) ถูกสร้างขึ้นโดยแต่ละองค์ประกอบระดับอินไลน์ ซึ่งเป็นส่วนหนึ่งของระบบการจัดตำแหน่ง และมีกล่องลูกอยู่ภายใน

กล่องอินไลน์ (Inline boxes) คือกล่องที่มีเนื้อหาปฏิบัติตามบริบทการจัดรูปแบบอินไลน์ กล่องอินไลน์ถูกแบ่งออกเป็นกล่องอินไลน์หลายกล่อง ในขณะที่กล่องอินไลน์ที่ไม่เคยถูกแบ่งเรียกว่า atomic inline-level boxes

กล่องอินไลน์แบบไม่ระบุชื่อ (Anonymous inline boxes) คือกล่องที่นักพัฒนาไม่มีการควบคุม หากกล่องบล็อกมีข้อความเปล่าๆ และกล่องระดับอินไลน์อื่นๆ ข้อความเปล่ารอบๆ กล่องระดับอินไลน์จะปฏิบัติตามบริบทการจัดรูปแบบอินไลน์และถูกล้อมรอบด้วยกล่องอินไลน์แบบไม่ระบุชื่อ

ตัวอย่าง

ลองดูตัวอย่างสำหรับ Inline-level Elements และ Inline Boxes:

<!DOCTYPE html> <html> <head> <title>CSS Inline-level Elements and Inline Boxes</title> <style> form {    width:70%;    margin: 0 auto;    text-align: center; } * {    padding: 2px; } input[type="button"] {    border-radius: 10px; } .child{    color: white;    border: 4px solid black; } .child:nth-of-type(1){    background-color: #FF8A00; } .child:nth-of-type(2){    background-color: #F44336; } .child:nth-of-type(3){    background-color: #C303C3; } .child:nth-of-type(4){    background-color: #4CAF50; } .child:nth-of-type(5){    background-color: #03A9F4; } .child:nth-of-type(6){    background-color: #FEDC11; } </style> </head> <body> <form> <fieldset> <legend>CSS Inline-level Elements and Inline Boxes</legend> <div><span class="child">Orange</span> Color<span class="child">Red</span> Color<span class="child">Violet</span> Color</div><br> </body> </html>

ผลลัพธ์

จะได้ผลลัพธ์ดังนี้:

องค์ประกอบระดับอินไลน์ (Inline-level) และกล่องอินไลน์ (Inline Boxes) ใน CSS