2

I want to make a scroll horizontal when there's to many of article , not make them jump down. So I want it to be able to scroll so you can see the rest. but it doesn't work.

Snippet:

#latest {
  background: #eee;
  border-bottom: 1px solid #ccc;
  border-top: 1px solid #ccc;
  overflow-x: scroll;
  overflow-y: hidden;
  height: 150px
}
article {
  width: 250px;
  height: 150px;
  background: #ccc;
  margin-right: 30px;
  float: left
}
<div id="latest">
  <div id="wrapper">
    <article></article>
    <article></article>
    <article></article>
    <article></article>
    <article></article>
    <article></article>
  </div>
</div>

2
  • What exactly doesn't work about it? Can you make an example on JSFiddle to show us? Commented Oct 2, 2015 at 13:15
  • The #latest doesn't list the article with a scroll horizontaly Commented Oct 2, 2015 at 13:18

4 Answers 4

3

Make your articles display:inline-block instead of float:left and set wrapper to be white-space:nowrap like so:

http://jsfiddle.net/andyfurniss/tobrbf7q/

Sign up to request clarification or add additional context in comments.

Comments

0

#latest{
background: #eee;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
overflow-x: scroll;
overflow-y: hidden;
height: 150px
}

#wrapper {
white-space:nowrap;
}

article{
width: 250px;
height: 150px;
background: #ccc;
margin-right: 30px;
display: inline-block;
}
<div id="latest">
  <div id="wrapper">
    <article></article>
    <article></article>
    <article></article>
    <article></article>
    <article></article>
    <article></article>
  </div>
</div>

Comments

0

You can use display:inline-block with white-space:nowrap

#latest {
 overflow-x: scroll;
 overflow-y: hidden;
 height: 80px;
 white-space:nowrap
}
article{
box-shadow: 1px 1px 10px #999;
margin: 2px;
max-height: 150px;
cursor: pointer;
display:inline-block;
*display:inline;/* For IE7*/
*zoom:1;/* For IE7*/
vertical-align:top;

}

Comments

0

Taking inspiration from @Andy Fumiss' answer, I integrated it some improvement:

display:inline-block has a little drawback because empty spaces due to code indentation has effect like space characters.

To show this effect, I slightly edit his example reducing margin-right separation to only 5px and avoiding indentantion in html code of first two article tags.

As you can see, first margin is lesser than following, because from second one, there is 5px + empty space.

To avoid this undesired behaviour, you can set font-size:0 on container and then restore its original value on content, like in this updated example

Here, relevant portion of changed code:

HTML:

<div id="latest">
    <div id="wrapper">
        <article></article><article></article>
        <article></article>
        ...
    </div>
</div>

CSS:

#wrapper {
    ...
    font-size:0;
}

article {
    ...
    font-size:13px;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.