1 - Dự án Natours - Giới thiệu dự án (phần 1)
1.1. Giới thiệu dự án.
- Natours là trang web giới thiệu và bán các Tour du lịch thiên nhiên.
- Link Demo: https://natours.netlify.com/
- Link Start Files: https://gitlab.nal.vn/nal/advanced-frontend-skills , thư mục dự án Natours/starter
1.2. Khởi tạo dự án:
Trong thư mục Start Files, ta có một số thành phần cơ bản như sau:
- Trang index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">
<link rel="stylesheet" href="css/icon-font.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
<title>Natours | Exciting tours for adventurous people</title>
</head>
<body>
</body>
</html>
- Thư mục CSS: chứa các file css của website
- Thư mục img: chứa hình ảnh sử dụng trong website
1.3. Xây dựng Header
Kiến thức cần bổ sung:
- Thực hiện basic reset một cách tốt nhất qua việc sử dụng universal selector. (*** Tại sao phải thực hiện basic reset?)
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Lato, sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #2e2e2e;
}
- Đặt kích thước với đơn vị tính vh & vw.
- Làm việc với các thuộc tính của background:
.header {
height: 95vh;
background-image: linear-gradient(
to right bottom,
rgba(111, 47, 83, 0.8),
rgba(159, 77, 70, 0.8)),
url(../img/hero.jpg);
background-size: cover;
background-position: top;
}
- Cắt các phần của 1 đối tượng qua CSS clip-path. VD: Cắt góc của background image như demo
clip-path: polygon(0 0, 100% 0, 100% 75vh, 0 100%);
// CSS clip-path marker: https://bennettfeely.com/clippy/
- CĂN GIỮA mọi thứ với thuộc tính transfrom, top và left.
<header class="header">
<div class="logo-box">
<img src="img/logo-white.png" alt="Logo" class="logo">
</div>
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">Outdoors</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
</div>
</header>
.logo-box {
position: absolute;
top: 40px;
left: 40px;
}
.logo {
height: 35px;
}
.text-box {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
.heading-primary {
color: #fff;
text-transform: uppercase;
}
.heading-primary-main {
display: block;
font-size: 60px;
font-weight: 400;
letter-spacing: 35px;
}
.heading-primary-sub {
display: block;
font-size: 20px;
font-weight: 700;
letter-spacing: 17.5px;
}
1.4. Tạo hiệu ứng chuyển động đặc biệt trong CSS3
Kiến thức cần bổ sung:
- CSS @keyframes
@keyframes moveInLeft {
0% {
opacity: 0;
transform: translateX(-100px);
}
80% {
transform: translateX(10px);
}
100% {
opacity: 1;
transform: translate(0);
}
}
- Các thuộc tính của CSS animation
.heading-primary-main {
display: block;
font-size: 60px;
font-weight: 400;
letter-spacing: 35px;
animation-name: moveInLeft;
animation-duration: 1s;
}
1.5. Tạo các Button có hiệu ứng phức tạp.
Kiến thức cần bổ sung:
- Tạo hiệu ứng chuyển động đơn giản khi hover button với CSS transition
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">Outdoors</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
<a href="#" class="btn btn-white">Discover our tours</a>
</div>
.btn:link,
.btn:visited {
text-transform: uppercase;
text-decoration: none;
padding: 15px 40px;
transition: all .2s;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 10px 20px rgba(0,0,0,.2);
}
.btn:active {
transform: translateY(-1px);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
.btn-white {
background-color: #fff;
color: #777;
display: inline-block;
margin-top: 60px;
border-radius: 100px;
}
- pseudo-elements & pseudo-class là gì?
- Sử dụng pseudo-element ::after như thế nào?
.btn:after {
position: absolute;
content: '';
width: 100%;
height: 100%;
top: 0;
left: 0;
border-radius: 100px;
z-index: -1;
transition: all .4s;
}
.btn-white:after {
background-color: #fff;
}
.btn:hover:after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
.btn-animated {
animation: moveInBottom .5s ease-out .75s;
animation-fill-mode: backwards;
}
Kiến Thức Cơ Bản
- Thuộc tính Display cho các phần tử: https://thachpham.com/web-development/html-css/tuy-bien-loai-phan-tu-voi-display-trong-css.html
- Các thẻ có ý nghĩa trong HTML5: https://webvn.com/cac-the-co-y-nghia-trong-html5/
- Xác định vị trí của thành phần với Position: absolute/relative/fixed: https://thachpham.com/web-development/html-css/position-absolute-va-relative-trong-css.html
- Hiệu ứng chuyển động với transition: https://thachpham.com/web-development/html-css/hieu-ung-chuyen-dong-css-voi-transition.html
- Thay đổi hình dạng với transform https://thachpham.com/web-development/html-css/transform-va-transform-origin-trong-css.html
- 30 CSS Selector cần nhớ: https://viblo.asia/p/30-css-selectors-can-nho-p1-0bDM6ko6G2X4