CSS box-sizingคุณสมบัติ
ตัวอย่าง
รวมช่องว่างภายในและเส้นขอบในความกว้างและความสูงทั้งหมดขององค์ประกอบ:
#example1 {
box-sizing: border-box;
}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติbox-sizing
กำหนดวิธีคำนวณความกว้างและความสูงขององค์ประกอบ: ควรรวมช่องว่างภายในและเส้นขอบหรือไม่
ค่าเริ่มต้น: | กล่องเนื้อหา |
---|---|
รับการถ่ายทอด: | ไม่ |
เคลื่อนไหวได้: | ไม่. อ่านเกี่ยวกับแอนิเมชั่น |
รุ่น: | CSS3 |
ไวยากรณ์ JavaScript: | วัตถุ .style.boxSizing="border-box" |
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์
ตัวเลขตามด้วย -webkit- หรือ -moz- ระบุเวอร์ชันแรกที่ทำงานกับคำนำหน้า
Property | |||||
---|---|---|---|---|---|
box-sizing | 10.0 4.0 -webkit- |
8.0 | 29.0 2.0 -moz- |
5.1 3.2 -webkit- |
9.5 |
ไวยากรณ์ CSS
box-sizing: content-box|border-box|initial|inherit;
มูลค่าทรัพย์สิน
Value | Description |
---|---|
content-box | Default. The width and height properties (and min/max properties) includes only the content. Border and padding are not included |
border-box | The width and height properties (and min/max properties) includes content, padding and border |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ระบุกล่องที่มีเส้นขอบสองกล่องเคียงข้างกัน:
div
{
box-sizing: border-box;
width: 50%;
border: 5px solid red;
float: left;
}
ตัวอย่าง
ตั้งค่า "universal box-sizing":
* {
box-sizing: border-box;
}
หน้าที่เกี่ยวข้อง
กวดวิชา CSS: CSS Box Sizing
การอ้างอิง HTML DOM: คุณสมบัติ boxSizing