Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make content horizontally scroll inside a div

Tags:

html

css

I have a division in which I wanna show images and on click open them in a lightbox. I have floated them left and displayed them inline. set overflow-x to scroll but it still puts the images below once the row space is not enough. I wanna get them to be inline and display a horizontal scroll when needed.

NOTE: I can't change the structure of the images inside. It has to be a img inside an anchor. My lightbox requires it like that.

HTML:

<div id="myWorkContent">     <a href="assets/work/1.jpg"><img src="assets/work/1.jpg" height="190" /></a>     <a href="assets/work/2.jpg"><img src="assets/work/2.jpg" height="190" /></a>     <a href="assets/work/3.jpg"><img src="assets/work/3.jpg" height="190" /></a>     <a href="assets/work/4.jpg"><img src="assets/work/4.jpg" height="190" /></a>     <a href="assets/work/5.jpg"><img src="assets/work/5.jpg" height="190" /></a>     <a href="assets/work/6.jpg"><img src="assets/work/6.jpg" height="190" /></a> </div><!-- end myWorkContent --> 

CSS:

#myWorkContent{     width:530px;     height:210px;     border: 13px solid #bed5cd;     overflow-x: scroll;     overflow-y: hidden; } #myWorkContent a {     display: inline;     float:left } 

I know this is very basic but I just can't get it done. Don't know what's wrong.

like image 530
Aayush Avatar asked Jun 27 '11 18:06

Aayush


People also ask

How do I create a content scroll in a div?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I make a div scrollable vertically and horizontally?

We can use a combination of overflow-x and overflow-y to place the scrollbar vertically, horizontally, or both. For the vertical scrollbar, overflow-x:hidden and overflow-y:auto will be set in the CSS file, and vice versa for the horizontal scrollbar.

How do I make text scroll horizontally in HTML?

The HTML <marquee> tag defines a scrolling text area in the HTML document that moves across the page in a horizontal or vertical direction. By default, text found within the <marquee> tag will scroll from right to left.

How do I make my scroll horizontal?

Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.


1 Answers

It may be something like this in HTML:

<div class="container-outer">    <div class="container-inner">       <!-- Your images over here -->    </div> </div> 

With this stylesheet:

.container-outer { overflow: scroll; width: 500px; height: 210px; } .container-inner { width: 10000px; } 

You can even create an intelligent script to calculate the inner container width, like this one:

$(document).ready(function() {    var container_width = SINGLE_IMAGE_WIDTH * $(".container-inner a").length;    $(".container-inner").css("width", container_width); }); 
like image 162
Daniel O'Hara Avatar answered Sep 20 '22 05:09

Daniel O'Hara