องค์ประกอบระดับบล็อก (Block-level elements) มีคุณสมบัติ CSS display ตั้งค่าเป็น 'block', 'list-item', หรือ 'table' และองค์ประกอบเหล่านี้บังคับให้เกิดการขึ้นบรรทัดใหม่ (line break) ด้านบนและด้านล่างของตัวเอง กล่องบล็อก (Block-level boxes) ถูกสร้างขึ้นโดยแต่ละองค์ประกอบระดับบล็อก ซึ่งเป็นส่วนหนึ่งของระบบการจัดตำแหน่ง (positioning scheme) และมีกล่องลูก (child boxes) อยู่ภายใน
กล่องคอนเทนเนอร์บล็อก (Block container boxes) ประกอบด้วยกล่องระดับบล็อกและปฏิบัติตามบริบทการจัดรูปแบบบล็อก (block formatting context) หรือประกอบด้วยกล่องระดับอินไลน์ (inline-level boxes) และปฏิบัติตามบริบทการจัดรูปแบบอินไลน์ (inline formatting context) กล่องบล็อก (Block boxes) เป็นคำที่ใช้เมื่อกล่องระดับบล็อกเป็นกล่องคอนเทนเนอร์ด้วย
กล่องบล็อกแบบไม่ระบุชื่อ (Anonymous block boxes) คือกล่องที่นักพัฒนาไม่มีการควบคุม หากกล่องอินไลน์มีกล่องบล็อกอยู่ภายใน และเนื้อหาอินไลน์รอบๆ กล่องบล็อกนั้นถูกล้อมรอบด้วยกล่องบล็อกแบบไม่ระบุชื่อ
ตัวอย่าง
ลองดูตัวอย่างสำหรับ Block-level Elements และ Block Boxes:
<!DOCTYPE html> <html> <head> <title>CSS Block-level Elements and Block Boxes</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; box-sizing: border-box; /*margin:5px;*/ } input[type="button"] { border-radius: 10px; } .child{ height: 40px; width: 100%; 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 Block-level Elements and Block Boxes</legend> <div id="container">Color Orange <div class="child"></div>Color Red <div class="child"></div>Color Violet <div class="child"></div> </div><br> </body> </html>
ผลลัพธ์
จะได้ผลลัพธ์ดังนี้:
