Làm thể nào để layout website thay đổi phù hợp trên từng thiết bị? Đó là câu hỏi quan trọng vì hiện nay công nghệ phát triển dẫn đến người lướt web trên thiết bị smart tăng cao không đơn thuần là ở trên thiết bị máy tính nữa.
Và Css3 đã ra đời Query Media giúp chúng ta phân loại các thiết bị và css cho phù hợp, truyền tải nội dung tốt nhất đến người dùng.
Trong video này tôi giới thiệu nhanh bạn tư duy để giúp đổi giao diện từ 2 cột thành một cột khi lướt trên thiết bị nhỏ.
Video hướng dẫn Responsive Layout Website
Video này phù hợp với người đã có kiến thức css cơ bản, nếu bạn là người mới bắt đầu có thể học kỹ năng css website tại Html Css 21 Ngày tại https://unitop.com.vn/htmlcss21ngay
Code Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Web Design - Unitop.vn</title>
</head>
<body>
<style>
body{
font-size: 16px;
}
#wrapper {
max-width: 960px;
margin: 0 auto;
}
#header,
#footer {
background: brown;
padding: 10px;
text-align: center;
color: yellow;
}
#wp-content {
display: flex;
flex-wrap: wrap;
}
#content,
#sidebar {
padding: 10px;
box-sizing: border-box;
}
#content {
flex-basis: 100%;
background: rgb(240, 239, 239);
}
#sidebar {
flex-basis: 100%;
color: #fff;
}
#wp-content {
background: black;
}
/* // Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
#content {
flex-basis: 70%;
}
#sidebar {
flex-basis: 30%;
}
}
/* // Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
}
/* // Large devices (desktops, 992px and up) */
@media (min-width: 992px) {}
/* // Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {}
</style>
<div id="wrapper">
<div id="header">
<h1>Header</h1>
</div>
<div id="wp-content">
<div id="content">
<h1>Content</h1>
<h2>What is Lorem Ipsum?</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
and scrambled it to make a type specimen book. It has survived not only five centuries, but also the
leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h2>Where does it come from?</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of
classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin
professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words,
consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical
literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33
of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This
book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of
Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
<h2>Why do we use it?</h2>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when
looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal
distribution of letters, as opposed to using 'Content here, content here', making it look like
readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their
default model text, and a search for 'lorem ipsum' will uncover many web sites still in their
infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose
(injected humour and the like).
</p>
<h2>Where can I get some?</h2>
<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered
alteration in some form, by injected humour, or randomised words which don't look even slightly
believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't
anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet
tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.
It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures,
to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free
from repetition, injected humour, or non-characteristic words etc.
</p>
</div>
<div id="sidebar">
<h2>Sidebar</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eum, molestias! Laborum corporis, quo nobis id, maxime, velit facilis reprehenderit veniam in necessitatibus cupiditate adipisci similique dicta quisquam ab? Illum, explicabo.</p>
</div>
</div>
<div id="footer">
<h1>Footer</h1>
</div>
</div>
</body>
</html>