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

การสร้างหน้าเว็บพร้อม Sidebar และพื้นที่เนื้อหาหลักด้วย HTML และ CSS

หน้าเว็บที่มี Sidebar แบบ fluid และพื้นที่เนื้อหาหลัก สร้างได้โดยการตั้งค่าขนาด html และ body ให้เป็น 100%

ตัวอย่าง

<!DOCTYPE html> 
<html> 
<head> 
<style> 
html,body { 
  height: 100%; 
  color: white; 
  font-size: 2em; 
  line-height: 200px; 
} 
#parent { 
  display: table; 
  width: 100%; 
  height: 100%; 
} 
#side { 
  display: table-cell; 
  background-color: turquoise; 
  width: 20%; 
  vertical-align: top; 
  box-shadow: inset 0 0 10px black; 
} 
#main { 
  display: table-cell; 
  width: 80%; 
  background: url("https://images.unsplash.com/photo-1611944444060-b50a1d80cfe6?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=800&ixlib=rb1.2.1&q=80&w=600"); 
} 
</style> 
</head> 
<body> 
<div id="parent"> 
<div id="side">Side</div> 
<div id="main">Main</div> 
</div> 
</body> 
</html>

ผลลัพธ์

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

การสร้างหน้าเว็บพร้อม Sidebar และพื้นที่เนื้อหาหลักด้วย HTML และ CSS