peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76perihoki spin mahjong ways 2 pgsoft scatter hitam maxwinsimbol mahjong wins 3 yang sering muncul di awal perihokitrik gampang menang mahjong winscuan mahjong wins 3 tanpa hentipola spin taruhan kecil mahjong winsstrategi kunci scatter hitam beruntungacor total mahjong wayskemenangan maksimal mahjong wayskemenangan pria pekanbaru mahjong waysmahjong wins3 fenomena baru sumatera baratmenangkan mahjong dengan lincahmenembus batas keberuntungan mahjong waysmenjajal keberuntungan di mahjong wayspola gratis mahjong ways1scatter hitam senjata rahasia mahjong winsteknik spinning menguntungkan untuk scatter hitamanalisis rtp tertinggi mahjong winsfenomena scatter hitam mahjong winsibu rumah tangga dan keberuntungan mahjongkeseruan main mahjong wins3menang mahjong pengguna baru di sosial mediamenghargai setiap momen di mahjong waysserunya main mahjong di warung internetspin slow motion mancing scatterstrategi jitu maxwin mahjong waysstrategi jitu menang mahjong modal kecil jackpot besaranak kampung papua menggemparkan mahjongkeajaiban scatter hitam mahjong wayskeberhasilan joni mahjong winskejaiban mahjong ways di ujung jalanketua mahjong wins3 kehadiran kemenangan dimulai dari balimahjong kehadiran yang menguntungkanmahjong menggila adat88panduan kilat raih 108 jutatips memenangkan mahjongbarista kopi menang 110 juta spin mahjongdakota76 scatter hitam mahjong wins 3gagal cpns menang mahjong wins 3 rp120 jutakisah karyawan minimarket dapat thr lebih awal mahjong winskisah pelajar sma kuasai mahjong wins 3 inspirasi sekolahkisah penjaga parkir tanah abang motor baru mahjong winskisah sukses ibu rumah tangga bandung mahjong winsmahasiswa kkn beli iphone15 mahjong wins3 dakotamantan anak band influencer mahjong scatter hitampola rtp senin gates of olympus guru matematikatukang cuci motor menemukan keberuntungan di mahjong

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

Tạo HTML danh sách bài viết đơn giản - Freetuts
HTML
HTML5
CANVAS
HEADING TAGS
FORM TAGS
LIST TAGS
PARAGRAPH TAGS
p br pre
COMMON TAGS
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Tạo HTML danh sách bài viết đơn giản

Trong bài này mình sẽ hướng dẫn cách tạo danh sách bài viết bằng HTML, qua bài này bạn sẽ hiểu và áp dụng được một số thẻ heading, thẻ p, thẻ div, và nhiều thuộc tính CSS liên quan khác.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Mục đích mình đưa ra bài tập này là giúp các bạn hiểu được cách xây dựng giao diện HTML dạng danh sách. Mình sẽ không hướng dẫn làm một giao diện cute, mà chỉ làm theo một mô hình chuẩn để các bạn thực hành thôi nhé. Sau này muốn style kiểu gì thì tùy các bạn.

1. Giao diện HTML danh sách bài viết sẽ làm

Mình sẽ không hướng dẫn xây dựng bổ cục trang web nữa. Nếu bạn chưa biết cách thì quay lại bài học tạo bổ cục layout HTML nhé.

Trong bài này mình sẽ làm một giao diện có dạng như sau:

Bài viết này được đăng tại [free tuts .net]

danh sach html 1 jpg

Đây là cách hiển thị chuẩn mà các bạn sẽ gặp trên hầu hết các trang web hiện nay.

Chúng ta sẽ cần một thẻ div#list_post để bao quanh toàn bộ bài viết lại. Với mỗi bài viết thì chúng ta cũng cần tạo thêm một thẻ div.post. Mình sử dụng class thì vì chúng ta có nhiều bài viết và chúng có chung một kiểu style CSS. Lúc này cấu trúc cơ bản của phần này sẽ như sau:

<div id="list_post">
    <div class="post">
        POST 1
    </div>
    <div class="post">
        POST 2
    </div>
    <div class="post">
        POST ..
    </div>
</div>

Mỗi bài viết chúng ta lại chia thành 2 phần. Thứ nhất là hình ảnh đại diện cho bài viết, nó sẽ nằm phía bên trái. Thứ 2 là nội dung sẽ nằm phía bên phải. Mình sẽ tạo 2 thẻ div như sau:

Demo RUN
<div id="list_post">
    <div class="post">
        <div class="thumb">
            <img src="URL HÌNH 1" alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT 1">Tiêu đề 1</a></h3>
            <p>
                Nội dung mô tả 1
            </p>
        </div>
    </div>
    <div class="post">
        <div class="thumb">
            <img src="URL HÌNH 2" alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT 1">Tiêu đề 2</a></h3>
            <p>
                Nội dung mô tả 2
            </p>
        </div>
    </div>
    <div class="post">
        <div class="thumb">
            <img src="URL HÌNH .." alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT ..">Tiêu đề ..</a></h3>
            <p>
                Nội dung mô tả ..
            </p>
        </div>
    </div>
</div>

Chạy lên chúng ta sẽ có giao diện như sau:

post 1 JPG

Bây giờ ta sẽ cần một chút CSS để giúp giao diện trông đẹp hơn nhé.

2. Dùng CSS để xây dựng giao diện danh sách bài viết

Bước 1: Mình sẽ giới hạn chiều rộng của thẻ div#list_post khoảng 600px nhé các bạn, đồng thời cho thêm một chút đường viền để dễ dàng nhận biết. Ta cũng nên canh giữa cho nó bằng cách sử dụng CSS margin: 0px auto.

Demo RUN
#list_post{
    border: solid 1px #ddd;
    width: 600px;
    margin: 0px auto;
}

Kết quả:

post 2 JPG

Bước 2: Mình cũng tạo đường viền cho mỗi bài viết bằng cách style cho div.post. Sử dụng thêm thuộc tính margin để tăng khoảng cách giữa bài viết và đường biên bên ngoài.

Demo RUN
.post{
    border: solid 1px #ddd;
    margin: 10px 20px;
}

Kết quả:

post 3 JPG

Bước 3: Mình sẽ bổ sung link hình ảnh cho 3 bài viết.

<div id="list_post">
    <div class="post">
        <div class="thumb">
            <img src="https://freetuts.net/upload/tut_series/images/2015/12/14/39/html-can-ban.jpg" alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT 1">Tiêu đề 1</a></h3>
            <p>
                Nội dung mô tả 1
            </p>
        </div>
    </div>
    <div class="post">
        <div class="thumb">
            <img src="https://freetuts.net/upload/tut_series/images/2015/12/14/39/html-can-ban.jpg" alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT 1">Tiêu đề 2</a></h3>
            <p>
                Nội dung mô tả 2
            </p>
        </div>
    </div>
    <div class="post">
        <div class="thumb">
            <img src="https://freetuts.net/upload/tut_series/images/2015/12/14/39/html-can-ban.jpg" alt=""/>
        </div>
        <div class="infor">
            <h3><a href="URL BÀI VIẾT ..">Tiêu đề ..</a></h3>
            <p>
                Nội dung mô tả ..
            </p>
        </div>
    </div>
</div>

Bước 4: Bây giờ ta sẽ style cho phần hình ảnh. Mình sẽ dùng float để treo nó về góc trái, sau đó thiết lập chiều rộng cho nó khoảng 200px. Đối với hình ảnh thì mình sẽ thiết lập max-width là 200px (tức là 100%).

Demo RUN
.post .thumb{
    float:left;
    width: 200px;
}
.post .thumb img{
    max-width: 100%;
    display: inherit;
}

post 4 JPG

Kết quả giao diện bị vỡ. Lý do là ta sử dụng float:left cho phần hình ảnh (float left treo ở góc trái), nên khoảng không sẽ phụ thuộc vào phần content. Để khắc phục vấn đề này thì bạn chỉ cần thêm thuộc tính overflow:hidden vào .post là được.

.post{
    border: solid 1px #ddd;
    margin: 10px 20px;editor html id 1629
    overflow: hidden;
}

post 5 JPG

Bước 5: Thay đổi nội dung cho phần tiêu đề bài viết.

Mình sẽ cho margin bên trái tầm 220px để giữa hình ảnh và tiêu đề có khoảng trống, và thay đổi font chữ, màu chữ cho phần tiêu đề.

Demo RUN
.post .infor{
    margin-left: 220px;
}
.post .infor h3{
    margin: 15px 0px 20px 0px;
}
.post .infor h3 a{
    font-size: 18px;
    text-decoration: none;
    color: blue;
    text-transform: uppercase;
}

post 6 JPG

Bây giờ trông có vẻ ok hơn rồi đấy. Bạn muốn thay đổi kiểu gì thì tự thêm CSS nhé.

Qua bài này mình đã hướng dẫn xong cách xây dựng danh sách bài viết bằng HTML và CSS. Đây là bài mẫu nên cực kì đơn giản, mục đích giúp những bạn mới học CSS tiếp cận với nhiều loại giao diện khác nhau. Hẹn gặp lại các bạn ở bài tiếp theo nhé.

Cùng chuyên mục:

Tạo Trang web E-commerce  từ HTML & CSS

Tạo Trang web E-commerce từ HTML & CSS

Validate form bằng HTML5

Validate form bằng HTML5

Trước đây chúng ta hay validate form bằng Javascript, nhưng ...

Thẻ aside trong HTML5

Thẻ aside trong HTML5

Mình cũng không rõ người ta tạo ra thẻ này làm gì, nhưng nếu xét…

Thẻ hgroup trong HTML5

Thẻ hgroup trong HTML5

hgroup là một thẻ được thêm vào kể từ phiên bản ...

Thẻ header trong HTML5

Thẻ header trong HTML5

Nếu nhìn qua một trang web được xây dựng bằng HTML5 thì bạn ...

Các thẻ HTML tạo form thu thập dữ liệu

Các thẻ HTML tạo form thu thập dữ liệu

Trước khi bắt đầu thì bạn phải hiểu khái niệm form dữ liệu là ...

Tạo background và đường viền cho thẻ HTML

Tạo background và đường viền cho thẻ HTML

Để tạo màu nền cho một thẻ HTML bất kì thì ta sử dụng thuộc…

Tạo menu một cấp bằng HTML đơn giản

Tạo menu một cấp bằng HTML đơn giản

Để làm menu 1 cấp thì có rất nhiều giải pháp. Bạn có thể sử…

Tạo bổ cục layout HTML đơn giản

Tạo bổ cục layout HTML đơn giản

Qua bài học này bạn sẽ biết cách tạo một file style riêng để ..

Phân biệt ID và Class trong HTML

Phân biệt ID và Class trong HTML

Mỗi thẻ HTML đều có những thuộc tính riêng và khác nhau. Tuy nhiền ..

Cách dùng thẻ div trong HTML để tạo các khối giao diện

Cách dùng thẻ div trong HTML để tạo các khối giao diện

Thẻ div đóng vai trò rất quan trọng, nó được dùng để tạo ...

Phân biệt thẻ HTML Block và Inline

Phân biệt thẻ HTML Block và Inline

Có bao giờ bạn thắc mắc rằng, tại sao nội dung ...

Thuộc tính style trong HTML

Thuộc tính style trong HTML

Do chúng ta chưa học CSS nên mình sẽ không nói ...

Thẻ title trong HTML

Thẻ title trong HTML

Cách sử dụng thẻ title html ...

Thẻ style trong HTML

Thẻ style trong HTML

Style là một thẻ HTML bình thường, nó có công dụng là xác ...

Thẻ base trong HTML

Thẻ base trong HTML

Cách sử dụng thẻ base trong html ...

Thẻ link trong HTML

Thẻ link trong HTML

Cách sử dụng thẻ html ...

Thẻ meta trong HTML

Thẻ meta trong HTML

Cách sử dụng thẻ meta html ...

Thẻ script trong HTML

Thẻ script trong HTML

Cách sử dụng thẻ script html ...

Thẻ noscript trong HTML

Thẻ noscript trong HTML

Cách sử dụng thẻ noscript html ...

Top