CSS Image Gallery
Use CSS to create an image gallery:
is displayed as follows




##
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php.cn</title>
<style type="text/css">
div.img
{
margin: 2px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}
div.img img
{
display: inline;
margin: 3px;
border: 1px solid #ffffff;
}
div.img a:hover img {border: 1px solid #0000ff;}
div.desc
{
text-align: center;
font-weight: normal;
width: 120px;
margin: 2px;
}
</style>
</head>
<body>
<div class="img">
<a href="#"><img src="http://img.php.cn/upload/image/837/831/318/1476339949246926.jpg"
alt="Klematis" width="110" height="90"></a>
<div class="desc">1</div>
</div>
<div class="img">
<a href="#"><img src="http://img.php.cn/upload/image/153/383/263/1476339955769441.jpg"
alt="Klematis" width="110" height="90"></a>
<div class="desc">2</div>
</div>
<div class="img">
<a href="#"><img src="http://img.php.cn/upload/image/815/625/584/1476339961304990.jpg"
alt="Klematis" width="110" height="90"></a>
<div class="desc">3</div>
</div>
<div class="img">
<a href="#"><img src="http://img.php.cn/upload/image/870/504/597/1476339972616793.jpg"
alt="Klematis" width="110" height="90"></a>
<div class="desc">4</div>
</div>
</body>
</html>Code explanation:
CSS picture gallery, each display uses 2 layers of divs; the outer css class is img, including an <a> tag, in <a> ; The <img> tag in the tag sets the image path, and the alt attribute is the prompt displayed when the mouse is moved over; the inner div displays the image description, and its css class is desc;
div.img, . is the css class Selector, defining the attributes of the "img" class:
Margin: 2px;
Border: 1px, solid line, color;
Height: automatic;
Width: automatic;
Left Floating;
Center alignment of text;
div.img (img tag is an inline element)
Inline element; its own independent space, which exists attached to other block-level elements, therefore, for Setting attributes such as height, width, inner and outer margins for inline elements is invalid;
Margin: 3px;
Border: 1px, solid line, color;
div.desc
Font weight: Normal
Width: 120px
Margin: 2px
div .img a:hover img {border: 1px solid #0000ff;}
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~ 















