javascript - how to set a list of images next to eachother - Stack Overflow

I have a list of images but i want all the images next to each other. and than with horizontal scroll.I

I have a list of images but i want all the images next to each other. and than with horizontal scroll.

I tried to set a max height for the scroll menu but that his hide the 2 images below. I also disabled vertical scroll but that doesn't work to.

If it is possible I want only use css. if I need javascript to fix it I use Jquery.

My html:

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
  <link href="css/index.css" rel="stylesheet"/>
  <link href="css/global.css" rel="stylesheet"/>
  <meta charset="UTF-8">
</head>
<body>
    <div id="list">
        <img src="img/1.jpg" class="img">
        <img src="img/2.jpg" class="img">
        <img src="img/3.jpg" class="img">
        <img src="img/4.jpg" class="img">
        <img src="img/5.jpg" class="img">
        <img src="img/6.jpg" class="img">
        <img src="img/7.jpg" class="img">
        <img src="img/8.jpg" class="img">
    </div>
    <div id="output">

    </div>
    <script src="js/jquery.js"></script>
    <script src="js/image.js"></script>

</body>
</html>

my css:

body{
 padding:0px;
 margin:0px;
 overflow-y:hidden;
}
.img{
 height:100px;
 width:200px;
 display:inline-block;
 margin-left:0px;
}

.loaded{
 width:100%;
}
#list{
 overflow-y:hidden;
 width:auto;
}

I have a list of images but i want all the images next to each other. and than with horizontal scroll.

I tried to set a max height for the scroll menu but that his hide the 2 images below. I also disabled vertical scroll but that doesn't work to.

If it is possible I want only use css. if I need javascript to fix it I use Jquery.

My html:

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
  <link href="css/index.css" rel="stylesheet"/>
  <link href="css/global.css" rel="stylesheet"/>
  <meta charset="UTF-8">
</head>
<body>
    <div id="list">
        <img src="img/1.jpg" class="img">
        <img src="img/2.jpg" class="img">
        <img src="img/3.jpg" class="img">
        <img src="img/4.jpg" class="img">
        <img src="img/5.jpg" class="img">
        <img src="img/6.jpg" class="img">
        <img src="img/7.jpg" class="img">
        <img src="img/8.jpg" class="img">
    </div>
    <div id="output">

    </div>
    <script src="js/jquery.js"></script>
    <script src="js/image.js"></script>

</body>
</html>

my css:

body{
 padding:0px;
 margin:0px;
 overflow-y:hidden;
}
.img{
 height:100px;
 width:200px;
 display:inline-block;
 margin-left:0px;
}

.loaded{
 width:100%;
}
#list{
 overflow-y:hidden;
 width:auto;
}
Share Improve this question asked Nov 2, 2014 at 13:05 Vinc199789Vinc199789 1,0461 gold badge11 silver badges32 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

Simply add

  white-space: nowrap;

to #list

Since your .img images are correctly set to inline-block you can now control the parent element's whitespace with https://developer.mozilla/en-US/docs/Web/CSS/white-space (which applies to the inner inline, inline-block children.)

nowrap
Collapses whitespace as for normal, but suppresses line breaks (text wrapping) within text.

As @roko-c-buljan said simply add white-space: nowrap; to the #list. This suppresses line-breaks in the text, which the images are as they have display: inline-block.

body{
 padding:0px;
 margin:0px;
 overflow-y:hidden;
}
.img{
 height:100px;
 width:200px;
 display:inline-block;
 margin-left:0px;
}

.loaded{
 width:100%;
}
#list{
 overflow-y:hidden;
 width:auto;
 white-space:nowrap;
}
<!DOCTYPE html>
<html>
<head>
  <title>test</title>
  <link href="css/index.css" rel="stylesheet"/>
  <link href="css/global.css" rel="stylesheet"/>
  <meta charset="UTF-8">
</head>
<body>
    <div id="list">
        <img src="img/1.jpg" class="img">
        <img src="img/2.jpg" class="img">
        <img src="img/3.jpg" class="img">
        <img src="img/4.jpg" class="img">
        <img src="img/5.jpg" class="img">
        <img src="img/6.jpg" class="img">
        <img src="img/7.jpg" class="img">
        <img src="img/8.jpg" class="img">
    </div>
    <div id="output">

    </div>
    <script src="js/jquery.js"></script>
    <script src="js/image.js"></script>

</body>
</html>

Are you looking for something like this?

http://codepen.io/kozumii/pen/IoAFb

#list{
  overflow-x:scroll;
  white-space:nowrap;
}

If you're familiar with floats,you can add

#list img {
  float:left;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745589150a4634726.html

相关推荐

  • javascript - how to set a list of images next to eachother - Stack Overflow

    I have a list of images but i want all the images next to each other. and than with horizontal scroll.I

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信