Diễn giải trực quan
Thực hành
Code HTML
html
1<!DOCTYPE html>2<html lang="vi">3<head>4 <meta charset="UTF-8">5 <meta name="viewport" content="width=device-width, initial-scale=1.0">6 <meta name="keywords" content="Nền tảng,HTML,CSS,XML,JavaScript, Lập trình C#, Lập trình, Web, Kiến thức, Đồ án">7 <meta name="author" content="Dương Nguyễn Phú Cường">8 <meta name="description"9 content="Cung cấp các kiến thức Nền tảng, cơ bản về Lập trình, Lập trình web, Lập trình di động, Cơ sở dữ liệu, ...">10 <title>Thiết kế bố cục layout trang web bằng thẻ div, css float và kỹ thuật sử dụng điểm ngắt clearfix | NenTang.vn</title>11 12 <link href="app.css" type="text/css" rel="stylesheet" />13</head>14<body>15 16 <div class="container">17 <!-- Header start -->18 <div class="div-1">19 DIV 120 </div>21 <div class="div-2">22 DIV 223 </div>24 <div class="div-3">25 DIV 326 </div>27 <!-- Header end -->28 29 <div class="clear-fix"></div><!-- Điểm ngắt xóa bỏ float -->30 31 <!-- Menu start -->32 <div class="div-4">33 DIV 434 </div>35 <!-- Menu end -->36 37 <div class="clear-fix"></div><!-- Điểm ngắt xóa bỏ float -->38 39 <!-- Content start -->40 <div class="div-5">41 DIV 542 </div>43 <div class="div-6">44 DIV 645 </div>46 <!-- Content end -->47 48 <div class="clear-fix"></div><!-- Điểm ngắt xóa bỏ float -->49 50 <!-- Footer start -->51 <div class="div-7">52 DIV 753 </div>54 <div class="div-8">55 DIV 856 </div>57 <!-- Footer end -->58 59 <div class="clear-fix"></div><!-- Điểm ngắt xóa bỏ float -->60 </div>61 62</body>63</html>Code CSS
css
1.container {2 width: 900px;3 border: 1px solid red;4 margin: 20px auto;5}6.div-1 {7 background: #FFE6CC;8 width: 300px;9 height: 150px;10 text-align: center;11 float: left;12}13.div-2 {14 background: #DAE8FC;15 width: 300px;16 height: 150px;17 float: left;18}19.div-3 {20 background: #D5E8D4;21 width: 300px;22 height: 150px;23 float: left;24}25.div-4 {26 background: #E1D5E7;27 width: 900px;28 height: 80px;29}30.div-5 {31 background: #D8007350;32 width: 300px;33 height: 300px;34 float: left;35}36.div-6 {37 background: #1BA1E260;38 width: 600px;39 height: 300px;40 float: left;41}42.div-7 {43 background: #A2002560;44 width: 450px;45 height: 120px;46 float: left;47}48.div-8 {49 background: #F0A30A60;50 width: 450px;51 height: 120px;52 float: left;53}54.clear-fix {55 clear:both;56}
