We can use CSS to create accordion photo galleries. Here is an example for horizontal accordion photo gallery. Please click on the images to view the photo gallery in Google Chrome browser.
Steps followed to create the above gallery that slides horizontally, are given below.
1. We assign a main div which holds all the images.
#gallery { |
The above height and width parameters would depend on the size of our images.
2. Second, we place a container inside it to give a background image
#div_container |
Note: This step is optional, to enhance the look of our gallery.
3. Thirdly, we assign separate divs to our images, as given in the style below
#div_img |
![]() |
4. In this step, we assign the hover effect to our image container, wherein we expand it in width, to the actual size of our image. In this case, the actual width of the image is 320 pixels
#div_img:hover { |
4. Next, we assign style to the images, and give the hover effect
.img { .img:hover { |
As obvious, in this step the image would be compressed before hovering .On hovering , it would retain actual size.
The HTML code for the above styles given is shown below
<div id="gallery"> |
With this we come to an end of this tutorial. You can also try out creating vertical sliding gallery. For that too, same logic can be used, with the only difference that our images would be compressed in height instead of width. The example for the same is shown below.
Tags: CSS3 photo gallery, CSS3 accordion photo gallery, CSS3 horizontal accordion photo gallery, CSS3 vertical accordion photo gallery