Pages

Sunday, April 8, 2012

Thiết kế Layout 3 Cột(Column) bằng CSS

Bài viết này hướng dẫn các bạn thực hiện một layout web có 3 cột dùng HTML/ CSS.

Cấu trúc HTML
- Hình sau mô tả các phần tử HTML/ CSS mà tôi đã thêm vào trang :
Bước 1 : Tạo một trang HTML và thêm phần code này vào trong thẻ <body>
<div id="container">
<div id="topbar">Top Bar/Logo Layer</div>
<div id="navbar">
<a href="index.html?home">Home</a>
<a href="index.html?about">About</a>
<a href="mailto:myemailaddres@email.com">Contact me</a>
</div>
<div id="main">
<div id="column_left">
<h1>Post Title</h1>
<h2>09/04/2012</h2>
<p>Thêm text ở đây</p>
</div>
<div id="column_right">
<h3>Categories</h3>
Thêm mục lục
</div>
<div id="column_right_adsense">
<h3>AdSense</h3>
Adsense 120 X 600
</div>
<!-- Không xóa thẻ div bởi vì nó giải quyết vấn đề về chiều cao của div #container-->
<div class="spacer"></div>
</div>
<div id="footer">© 2012 Thông tin về website</div>
</div>
Ta lưu tập tin trên lại thành index.html

 Bước 2 : Tạo một tập tin CSS và liên kết nó với tập tin index.html bằng thẻ <link/>
/* ------------------------------
HTML Redefine Tags
------------------------------ */
body{font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px; padding:0;}

input, form, textarea
h1, h2, h3, h4, h5, h6{margin:0; padding:0;}
h1{font-size:18px;}
h2{font-size:14px; color:#999999;}
h3{font-size:13px; border-bottom:solid 1px #DEDEDE; padding:4px 0; margin-bottom:10px;}

a:link, a:visited{color:#0033CC;}
a:hover{text-decoration:none;}

/* ------------------------------
PAGE STRUCTURE
------------------------------ */

/* #container  */

#container{width:780px; margin:0 auto;}
#topbar{width:auto; display:block; height:60px;}
#navbar{width:auto; display:block; height:28px;}
#navbar a{heigth:28px; line-height:28px; padding:0 8px; display:inline;}

#main{width:auto; display:block; padding:10px 0;}
#column_left{width:460px; margin-right:20px; float:left;}
#column_right{width:160px; margin-right:20px; float:left;}
#column_right_adsense{width:120px; float:left;}
div.spacer{clear:both; height:10px; display:block;}

#footer{width:auto; display:block; padding:10px 0; font-size:11px; color:#666666;}

/* ------------------------------
CUSTOM CLASSES
------------------------------ */

/* Tùy chỉnh ... */
                                                                                                                               nguyenloi

No comments:

Post a Comment