องค์ประกอบ HTML ทั้งหมดมีการตั้งค่าเริ่มต้นสำหรับคุณสมบัติ CSS Display คุณสมบัตินี้ระบุว่าจะแสดงผลองค์ประกอบในเอกสารอย่างไร
หมายเหตุ − คุณสมบัติการแสดงผลเริ่มต้นสามารถแทนที่ได้ แต่นั่นจะไม่เปลี่ยนประเภทขององค์ประกอบเพียงแค่ลักษณะการแสดงผลในเอกสาร
ต่อไปนี้เป็นค่าบางส่วนสำหรับคุณสมบัติ CSS Display -
- บล็อค
- อินไลน์
- อินไลน์-บล็อก
- ไม่มี
ตัวอย่าง
มาดูตัวอย่างคุณสมบัติ CSS Display กัน −
<!DOCTYPE html>
<html>
<head>
<title>CSS Display</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
box-sizing: border-box;
}
input[type="button"] {
border-radius: 10px;
}
.child{
display: block; /*default value for <div>*/
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-Display</legend>
<div id="container">
<div class="child"></div><div class="child"></div><div class="child"></div><div class="child"></div><div class="child"></div><div class="child"></div>
</div><br>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

ตัวอย่าง
มาดูตัวอย่างอื่นของคุณสมบัติ CSS Display กัน −
<!DOCTYPE html>
<html>
<head>
<title>CSS Display</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
box-sizing: border-box;
}
input[type="button"] {
border-radius: 10px;
}
.child{
height: 40px;
color: white;
border: 4px solid black;
display: inline;
}
.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-Display</legend>
<div id="container">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div><br>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
