Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal scroll css?

Tags:

html

css

overflow

I want to have one <div> with id that has horizontal scroll, but the problem is it has to be responsive, not with fixed width.

html, body {margin: 0; padding: 0;}  #myWorkContent{     width:530px;     height:210px;     border: 13px solid #bed5cd;     overflow-x: scroll;     overflow-y: hidden;     white-space: nowrap; }  #myWorkContent a {     display: inline-block;     vertical-align: middle; }  #myWorkContent img {border: 0;} 
<div id="myWorkContent">      <a href="assets/work/1.jpg"><img src="http://placekitten.com/200/200/" height="190"></a>      <a href="assets/work/2.jpg"><img src="http://placekitten.com/120/120/"/></a>      <a href="assets/work/3.jpg"><img src="http://placekitten.com/90/90/" height="90" width="90"></a>      <a href="assets/work/4.jpg"><img src="http://placekitten.com/50/50/" height="190"></a>      <a href="assets/work/5.jpg"><img src="http://placekitten.com/100/100/"></a>      <a href="assets/work/6.jpg"><img src="http://placekitten.com/200/200/" height="190"></a> </div><!-- end myWorkContent --> 

Thanks to http://jsfiddle.net/clairesuzy/FPBWr/

The problem is with that 530px. I would like to use 100% instead. But then I got page scroll and scroll of the DIV goes right, can not get it, any idea?

Here is article in Serbian about solution http://www.blog.play2web.com/index.php?id=18

like image 269
Miomir Dancevic Avatar asked Oct 08 '13 19:10

Miomir Dancevic


People also ask

How do I scroll horizontally in CSS?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.

How do I add a horizontal scroll?

Basic Horizontal Scroll Box To make a scroll box with a horizontal scroll, you need to use the overflow-x property. Specifically, you need to use this code: overflow-x:scroll; . This tells your browser to create scroll bars on the x (horizontal) axis, whenever the contents of the container is too wide.

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.


1 Answers

Just set your width to auto:

#myWorkContent{     width: auto;     height:210px;     border: 13px solid #bed5cd;     overflow-x: scroll;     overflow-y: hidden;     white-space: nowrap; } 

This way your div can be as wide as possible, so you can add as many kitty images as possible ;3

Your div's width will expand based on the child elements it contains.

jsFiddle

like image 117
nkmol Avatar answered Oct 04 '22 16:10

nkmol