ผู้เขียน หัวข้อ: จะกำหนดให้กล่องแสดงอยู่กลางหน้าจอได้อย่างไร ? [css]  (อ่าน 3195 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Admin

  • Administrator
  • *****
  • กระทู้: 1415
  • Level:
    0%
  • Thank : 61
  • เพศ: ชาย
    • ดูรายละเอียด
    • สะกิดข่าว
layout แบบหนึ่งที่นิยมใช้กัน คืือการใช้กล่องที่มีขนาดตายตัวซึ่งแสดงอยู่กลางหน้าจอในการแสดง content

เราสามารถใช้ css ทำำให้กล่องที่มีขนาดตายตัวแสดงอยู่กลางหน้าจอได้ด้วยการกำหนดค่า properties margin สำหรับด้านซ้ายและด้านขวาให้มีค่าเป็น auto ดังนี้

index.html
โค๊ด: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<link rel="stylesheet" type="text/css" href="center.css" />
</head>
<body>
<div id="content">
<p>จะกำหนดให้กล่องแสดงอยู่กลางหน้าจอได้อย่างไร</p>
</div>
</body>
</html>

center.css
โค๊ด: [Select]
body {
background-color: #000000;
color: #000000;
text-align: center;
}
#content {
width 630px;
margin-left: auto;
margin-right: auto;
border: 2px solid #000000;
background-color: #00000;
color: #000000;
padding: 0 20px 0 20px;
text-align: left;
}

 
แชร์บทความ...
โค้ดแบบ forum
(BBCode)
โค้ดแบบ site/blog
(HTML)