簡體   English   中英

溢出-x:隱藏仍然可以滾動

[英]overflow-x:hidden still can scroll

問題是:

我有一個全寬欄菜單,它是通過在右側和左側創建一個大邊距來制作的。 這個邊距應該由overflow-x: hidden裁剪,它是......沒有滾動條,一切(視覺上)都可以......

但是,如果您拖動頁面(使用 Mac Lion)或向右滾動,頁面會顯示一個巨大的欄,它應該被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;
}

這是一個鏈接: http : //jsfiddle.net/NicosKaralis/PcLed/1/

你必須在草稿中打開才能看到...... jsfiddle css 以某種方式使它工作。

@克拉澤

我有這樣的結構:

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

#container 是一個居中的 div,固定寬度為 950px,#full_bar 是一個在整個窗口上從一側延伸到另一側的條形

如果我將寬度 100% 放在 #full_bar 中,它將僅獲得內部寬度而不是窗口外的寬度

我有這個完全相同的問題。 我通過放置overflow-x: hidden;解決了它overflow-x: hidden; 雙方bodyhtml

 html { margin: 0 auto; padding: 0; overflow-x: hidden; } body { margin: 0 auto; overflow-x: hidden; 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>

還有另一種方法可以用一行代碼解決這個問題:

body {
    /* All your regular code including overflow-x: hidden; */
    position:relative;
}

這解決了我在 webkit (Mac) 上的問題

參考: http : //www.tonylea.com/2010/safari-overflow-hidden-problem/

html, body { overflow-x: hidden; width: 100%; }

為我解決了這個問題,除了 IE - 如果您努力這樣做,您仍然可以將站點向右拖動。

使用overflow: hidden; 刪除垂直滾動條,所以這不是解決方案。

我無法使用 JavaScript 找到更好的解決方案。

我在這里找到了解決方案https://stackoverflow.com/a/9399429/622041

必須#wrapper圍繞您的內容。 overflow:hiddenbody不起作用。

#wrapper {position: absolute; width: 100%; overflow-x: hidden}

這里是 HTML:

<html>
  <head>
    <title></title>
  </head>
  <body>
    <div id="wrapper">
      <div class="yourContent"> ... </div>
    </div>
  </body>
</html>

我認為沒有任何方法可以在不使用 JavaScript 的情況下防止元素滾動。 但是,使用 JS,將 scrollLeft 設置為 0 onscroll 非常容易。

來自 Weaver 的 Offcanvas 演示http://jasonweaver.name/lab/offcanvas/

用以下內容包裝內容:

width: 100%; 
overflow: hidden;

這僅限制了寬度,並且在類似情況下也可以防止拖動時滾動。

嘗試固定位置 html 元素,但這會禁用雙向滾動。

html {
    position: fixed;
}

<body><html>標簽上的溢出也對我有用。

如何設置內容正文的寬度,並圍繞#menu_bar#content_body扭曲#container

body
    div#container 
       div#menu_bar (absolute positioned)
          div#links
          div#full_bar
       div#content_body (relative positioned + padding [#menu_bar height])
          ...

CSS 示例

考慮對 html 使用 max-width。

如果它不起作用,請通知我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM