Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Layout : Continuous images

Tags:

html

css

I have a series of images, which I want to make them showing in a row, i.e.

[img][img][img][img][img][img][img][img][img][img][img][img][img][img][img]

I want the overflow part will be hidden.

My current HTML is as follow:

<div id="gallery">
  <img src="http://www.o2h.com.hk/images/apple_gala.JPG" class="gallery_img" />
  <img src="http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg" class="gallery_img" />
  <img src="http://www.o2h.com.hk/images/apple_gala.JPG" class="gallery_img" />
  <img src="http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg" class="gallery_img" />
  <img src="http://www.o2h.com.hk/images/apple_gala.JPG" class="gallery_img" />
  <img src="http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg" class="gallery_img" />
  <img src="http://www.o2h.com.hk/images/apple_gala.JPG" class="gallery_img" />
  <img src="http://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg" class="gallery_img" />
  <img src="http://www.o2h.com.hk/images/apple_gala.JPG" class="gallery_img" />
</div>

and this is the CSS:

#gallery {
  width: 100%;
  height: 200px;
  overflow: hidden;
}
#gallery .gallery_img {
  width: auto;
  height: 200px;
}

Here is the jsFiddle. I would like to show half image in the edge of the screen, like this:

enter image description here

However, I can only manage to show full images only. How should I modify the HTML / CSS codes ?

like image 925
Raptor Avatar asked Sep 11 '26 22:09

Raptor


1 Answers

Just use overwidth in percentage, and a mask div:

DEMO

#gallery {  
  width: 200%; /* this is the trick */
}
#gallery img {   /* and no need to add class="gallery_img" to IMGs anymore */
  height: 200px;
}

#wrapper {  
  height: 200px;
  overflow: hidden;
}



<div id="wrapper">
  <div id="gallery">
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />    
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />    
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
    <img src="http://www.o2h.com.hk/images/apple_gala.JPG" />        
  </div>
</div>

EDIT

I'll add the simplest solution too (posted by @RupaliShinde), because it shows the correct use of the white-space attribute, and appearently it is hard to reproduce (reading the comments):

#gallery {  
  width: 100%; 
  overflow: hidden;  
  white-space: nowrap; /* this is the trick */
}
#gallery img {  
  height: 200px;
}

DEMO

like image 57
Andrea Ligios Avatar answered Sep 14 '26 12:09

Andrea Ligios