0

here is what I created http://jsfiddle.net/ZygnV/

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.main-content-wrapper {
  height: 100%;
  overflow-y: hidden;
  white-space: nowrap;
}

.main-sidebar {
  display: inline-block;
  height: 100%;
  width: 220px;
  background-color: rgb(0, 0, 0);
}

.main-content {
  display: inline-block;
  height: 100%;
  width: 10000px;
}
<div class="main-content-wrapper">
  <nav class="main-sidebar">
  </nav>
  <section id="main-content" class="main-content">

  </section>
</div>

the problem is that little vertical scroll: I would like to not have it.

Why this little bug? And how can I fix it? I thought to set overflow-y:hidden but I don't think it's the best solution: if I would set a min-height and then display the scroll it would be always hidden (unless I act with a js script)

Gangula
  • 5,193
  • 4
  • 30
  • 59
marco
  • 1,152
  • 1
  • 9
  • 20

3 Answers3

3

There shouldn't be vertical scroll in the first place.

The reason behind it is that both nav and sectionare display: inline-block, so spaces in code formatting affect layout. There are various ways to solve the problem, one of them would be to set font-size: 0 on .main-content-wrapper and desired font-size on children.

JSFiddle.

Alternatively, you can use different approach to place sidebar and content, flexible boxes perform extremely good in this scenario.

Community
  • 1
  • 1
  • great. I used `display: inline-block` for `nav` and `section` to achieve my objective: a horizontal layout. But I never thought to set `font-size` property to their container. Thank you ;) – marco Jan 02 '14 at 10:18
1

This could help you

    .main-content {
    display: inline-block;
    height: 100%;
    position: absolute;
    width: 10000px;
   }
   .main-sidebar {
    background-color: #000000;
    display: inline-block;
    height: 100%;
    position: absolute;
    width: 220px;
    }
Green Wizard
  • 3,507
  • 4
  • 18
  • 29
0

Add overflow:hidden to main div

.main-content-wrapper{
            height: 100%;
            white-space: nowrap;
            overflow:hidden
        }

DEMO

Sowmya
  • 26,684
  • 21
  • 96
  • 136
  • excuse me, maybe I was not enough clear, in fact I forgot to say that I would like to have the horizontal scroll (that's the reason why the main-content has 10000px of width (just to show the horizontal scroll). Then, as I have already said, I could set overflow-y:hidden but then how to show the vertical scrollbar when a certain min-height is reached? I should act with js, ok, but is there a simpler way(only css, not javascript)? – marco Jan 02 '14 at 10:09