Navigation với border

Trở về

  • 3,190

Navigation với border, thêm định dạng mới đơn giản dễ sử dụng.

Navigation – border

Navigation với border cả bốn hướng.

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<style>
* { /* reset lại margin và padding cho các tag */
    margin: 0;
    padding: 0;
}
div#navigation ul { list-style: none; }
div#navigation ul li {
    float: left;
    margin-right: 5px;
}
div#navigation ul li a {
    color: #333;
    border: 1px solid #333;
    display: block;
    padding: 3px 15px;
    text-decoration: none;
}
div#navigation ul li a:hover {
    border: 1px solid red;
    color: red;
}
.clearfix {
    zoom: 1;
}
.clearfix:after {
    clear: both;
    content: ".";
    display: block;
    height: 0;
    line-height: 0;
    visibility: hidden;
}
</style>
</head>
<body>
<div id="navigation">
<ul class="clearfix">
<li><a href="http://hocwebchuan.com">Trang chủ</a></li>
<li><a href="http://hocwebchuan.com">Giới thiệu</a></li>
<li><a href="http://hocwebchuan.com">Sản phẩm</a></li>
<li><a href="http://hocwebchuan.com">Dịch vụ</a></li>
<li><a href="http://hocwebchuan.com">Liên hệ</a></li>
</ul>
</div>
</body>
</html>

Hiển thị trình duyệt:

 

clearfix là thủ thuật được dùng kèm với thuộc tính float, bạn có thể xem thêm về clearfix ở phần hướng dẫn học.

Download file để thực hành

Navigation với border dạng border bên trong.

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<style>
* { /* reset lại margin và padding cho các tag */
    margin: 0;
    padding: 0;
}
div#navigation ul { list-style: none; }
div#navigation ul li {
    border: 1px solid #333;
    float: left;
    margin-right: 5px;
}
div#navigation ul li a {
    color: #333;
    border-left: 3px solid #f00;
    display: block;
    padding: 3px 15px;
    text-decoration: none;
}
div#navigation ul li a:hover {
    border-left: 3px solid blue;
}
.clearfix {
    zoom: 1;
}
.clearfix:after {
    clear: both;
    content: ".";
    display: block;
    height: 0;
    line-height: 0;
    visibility: hidden;
}
</style>
</head>
<body>
<div id="navigation">
<ul class="clearfix">
<li><a href="http://hocwebchuan.com">Trang chủ</a></li>
<li><a href="http://hocwebchuan.com">Giới thiệu</a></li>
<li><a href="http://hocwebchuan.com">Sản phẩm</a></li>
<li><a href="http://hocwebchuan.com">Dịch vụ</a></li>
<li><a href="http://hocwebchuan.com">Liên hệ</a></li>
</ul>
</div>
</body>
</html>

Hiển thị trình duyệt:

 

Thay đổi dạng border bên trên và thêm padding cho <li> ta sẽ có nhiều dạng navigation khác nhau.

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<style>
* { /* reset lại margin và padding cho các tag */
    margin: 0;
    padding: 0;
}
div#navigation ul { list-style: none; }
div#navigation ul li {
    border: 1px solid #333;
    float: left;
    margin-right: 5px;
    padding: 1px;
}
div#navigation ul li a {
    color: #333;
    border-top: 3px solid #f00;
    display: block;
    padding: 3px 15px;
    text-decoration: none;
}
div#navigation ul li a:hover {
    border-top: 3px solid blue;
}
.clearfix {
    zoom: 1;
}
.clearfix:after {
    clear: both;
    content: ".";
    display: block;
    height: 0;
    line-height: 0;
    visibility: hidden;
}
</style>
</head>
<body>
<div id="navigation">
<ul class="clearfix">
<li><a href="http://hocwebchuan.com">Trang chủ</a></li>
<li><a href="http://hocwebchuan.com">Giới thiệu</a></li>
<li><a href="http://hocwebchuan.com">Sản phẩm</a></li>
<li><a href="http://hocwebchuan.com">Dịch vụ</a></li>
<li><a href="http://hocwebchuan.com">Liên hệ</a></li>
</ul>
</div>
</body>
</html>

Hiển thị trình duyệt:

 

Navigation với border-right.

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<style>
* { /* reset lại margin và padding cho các tag */
    margin: 0;
    padding: 0;
}
div#navigation ul { list-style: none; }
div#navigation ul li {
    border: 1px solid #333;
    float: left;
    margin-right: 5px;
    padding: 1px;
}
div#navigation ul li a {
    color: #333;
    border-right: 3px solid #f00;
    display: block;
    padding: 3px 15px;
    text-decoration: none;
}
div#navigation ul li a:hover {
    border-right: 3px solid blue;
}
.clearfix {
    zoom: 1;
}
.clearfix:after {
    clear: both;
    content: ".";
    display: block;
    height: 0;
    line-height: 0;
    visibility: hidden;
}
</style>
</head>
<body>
<div id="navigation">
<ul class="clearfix">
<li><a href="http://hocwebchuan.com">Trang chủ</a></li>
<li><a href="http://hocwebchuan.com">Giới thiệu</a></li>
<li><a href="http://hocwebchuan.com">Sản phẩm</a></li>
<li><a href="http://hocwebchuan.com">Dịch vụ</a></li>
<li><a href="http://hocwebchuan.com">Liên hệ</a></li>
</ul>
</div>
</body>
</html>

Hiển thị trình duyệt:

 

Navigation với border-bottom.

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Học Web Chuẩn</title>
<style>
* { /* reset lại margin và padding cho các tag */
    margin: 0;
    padding: 0;
}
div#navigation ul { list-style: none; }
div#navigation ul li {
    border: 1px solid #333;
    float: left;
    margin-right: 5px;
    padding: 1px;
}
div#navigation ul li a {
    color: #333;
    border-bottom: 3px solid #f00;
    display: block;
    padding: 3px 15px;
    text-decoration: none;
}
div#navigation ul li a:hover {
    border-bottom: 3px solid blue;
}
.clearfix {
    zoom: 1;
}
.clearfix:after {
    clear: both;
    content: ".";
    display: block;
    height: 0;
    line-height: 0;
    visibility: hidden;
}
</style>
</head>
<body>
<div id="navigation">
<ul class="clearfix">
<li><a href="http://hocwebchuan.com">Trang chủ</a></li>
<li><a href="http://hocwebchuan.com">Giới thiệu</a></li>
<li><a href="http://hocwebchuan.com">Sản phẩm</a></li>
<li><a href="http://hocwebchuan.com">Dịch vụ</a></li>
<li><a href="http://hocwebchuan.com">Liên hệ</a></li>
</ul>
</div>
</body>
</html>

Hiển thị trình duyệt:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.