ในการยืดองค์ประกอบให้พอดีกับความสูงทั้งหมดของหน้าต่างเบราว์เซอร์ด้วย CSS โค้ดจะเป็นดังนี้ -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
*{
box-sizing: border-box;
}
html, body {
height: 100%;
margin: 0;
}
.fullHeight{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
height: 100%;
background: rgb(135, 27, 207);
color:white;
font-size: 40px;
padding: 40px;
}
</style>
</head>
<body>
<div class="fullHeight">This div element will stretch to the whole height and width of the
window</div>
</body>
</html> ผลลัพธ์
รหัสข้างต้นจะสร้างผลลัพธ์ต่อไปนี้ -
