Quay về MỤC LỤC TỰ HỌC CSS
1. Thư viện ảnh
Ví dụ:
<html>
<head>
<style>
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: 300px; /*Nếu chiều cao hình bằng nhau thì để auto*/
}
div.desc {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="gallery">
<a target="_blank" href="hinh\hinh01.jpg">
<img src="hinh\hinh01.jpg" alt="Fjords" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh02.jpg">
<img src=" hinh\hinh02.jpg " alt="Forest" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh03.jpg">
<img src="hinh\hinh03.jpg" alt="Northern Lights" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh04.jpg">
<img src="hinh\hinh04.jpg" alt="Mountains" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</body>
</html>
<head>
<style>
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: 300px; /*Nếu chiều cao hình bằng nhau thì để auto*/
}
div.desc {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="gallery">
<a target="_blank" href="hinh\hinh01.jpg">
<img src="hinh\hinh01.jpg" alt="Fjords" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh02.jpg">
<img src=" hinh\hinh02.jpg " alt="Forest" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh03.jpg">
<img src="hinh\hinh03.jpg" alt="Northern Lights" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="hinh\hinh04.jpg">
<img src="hinh\hinh04.jpg" alt="Mountains" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</body>
</html>
2. Thư viện ảnh responsive
<!DOCTYPE html>
<html>
<head>
<style>
/*Chú ý các tấm hình sử dụng phải có kích thước bằng nhau*/
div.gallery {
border: 1px solid
#ccc;
}
div.gallery:hover {
border: 1px solid
#777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align:
center;
}
* {
box-sizing:
border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
@media only screen and (max-width: 700px) {
.responsive {
width:
49.99999%;
margin: 6px 0;
}
}
@media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content:
"";
display: table;
clear: both;
}
</style>
</head>
<body>
<h2>Responsive Image Gallery</h2>
<h4>Resize the browser window to see the
effect.</h4>
<div class="responsive">
<div
class="gallery">
<a
target="_blank" href="hinh\hinh01.jpg">
<img
src="hinh\hinh01.jpg" alt="Trolltunga Norway"
width="300" height="200">
</a>
<div
class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div
class="gallery">
<a
target="_blank" href="hinh\hinh02.jpg">
<img
src="hinh\hinh02.jpg" alt="Forest" width="600"
height="400">
</a>
<div
class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div
class="gallery">
<a
target="_blank" href="hinh\hinh03.jpg">
<img
src="hinh\hinh03.jpg" alt="Northern Lights"
width="600" height="400">
</a>
<div
class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div
class="gallery">
<a
target="_blank" href="hinh\hinh04.jpg">
<img
src="hinh\hinh04.jpg" alt="Mountains" width="600"
height="400">
</a>
<div
class="desc">Add a description of the image here</div>
</div>
</div>
<div class="clearfix"></div>
<div style="padding:6px;">
<p>This
example use media queries to re-arrange the images on different screen sizes:
for screens larger than 700px wide, it will show four images side by side, for
screens smaller than 700px, it will show two images side by side. For screens
smaller than 500px, the images will stack vertically (100%).</p>
<p>You will
learn more about media queries and responsive web design later in our CSS
Tutorial.</p>
</div>
</body>
</html>
Tác giả: #drM
Nguồn: Sưu Tầm
Nguồn: Sưu Tầm
Không có nhận xét nào:
Đăng nhận xét