Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

html - overflow-x:hidden still can scroll

The problem is:

I have a full width bar menu, which is made by creating a big margin on the right and to the left. This margin should be cropped by overflow-x: hidden, and it is... no scroll bars, everything (visually) is ok...

But, if you drag the page (using Mac Lion) or scroll to the right, the page shows an enormous bar, which should have been cropped by the overflow-x:hidden.

CSS

html {
  margin:0;
  padding:0;
  overflow-x:hidden;
}
body {
  margin: 0 auto;
  width: 950px;
}

.full, .f_right {
  margin-right: -3000px !important;
  padding-right: 3000px !important;
}

.full, .f_left {
  margin-left: -3000px !important;
  padding-left: 3000px !important;
}

Here is a link: http://jsfiddle.net/NicosKaralis/PcLed/1/

You have to open in draft to see... the jsfiddle css somehow makes it work.

@Krazer

i have and structure like this:

body
  div#container
    div#menu_bar
      div#links
      div#full_bar
    div#content_body
    ...

the #container is an centered div and has fixed width of 950px, the #full_bar is an bar that extends on the entire window, from one side to the other

if i put width 100% in #full_bar it will get only the inside width and not the width off the window

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this exact same problem. I solved it by putting overflow-x: hidden; on both the body and html.

html, body {
  margin: 0 auto;
  overflow-x: hidden;
}

html{
  padding: 0;
}

body {
  width: 950px;
}

.full {
  background: red;
  color: white;
  margin-right: -3000px !important;
  margin-left: -3000px !important;
  padding-right: 3000px !important;
  padding-left: 3000px !important;
}
<div>
  <div class="full">
    abc
  </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...