DIV 没有比浏览器宽的滚动条

发布于 2024-08-23 16:34:06 字数 429 浏览 6 评论 0原文

我正在使用 Wordpress 作为 CMS 在网站上进行一些测试。在下面的示例中,页面左上角在主要内容区域之外有一个“S”图形,根据浏览器宽度进行相应剪裁。我想对页脚右侧的“L”图形执行类似的操作。

页面宽度设置为 960px,我将页脚容器 DIV 设置为 1088px,以便“L”出现在内容区域之外。问题是,当滚动条超过浏览器的当前宽度时,就会出现滚动条。

我已经尝试过溢出:隐藏在页脚容器DIV上,但这似乎不起作用。我还尝试过在 BODY 元素上使用“overflow:hidden”,这在 IE 中可以正常工作,但在其他浏览器中则不行。

示例: http://unclemort.com/wp/

我真的希望有办法做到这一点,任何帮助感激不尽。

I'm doing some tests on a website using Wordpress as a CMS. In the example below the top left of the page has an "S" graphic outside of the main content area, clipped accordingly depending on the browser width. I would like to do something similar with an "L" graphic to the right in the footer.

The page width is set to 960px, and I've made the footer container DIV 1088px so that the "L" appears outside the content area. The trouble is this makes a scrollbar appear when it exceeds the current width of the browser.

I've tried overflow:hidden on the footer container DIV but this doesn't seem to work. I've also tried overflow:hidden on the BODY element and this works ok in IE, but not in other browsers.

Example: http://unclemort.com/wp/

I really hope there is away to do this, any help gratefully received.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软的没边 2024-08-30 16:34:06

今天我试图自己弄清楚这个问题并偶然发现了答案。
您需要的是围绕具有以下内容的所有内容的周围元素:

#wrapper {
  min-width: 600px; //whatever width you want
  overflow-x: hidden;
}

您的主要内容应具有相同的宽度,并且需要突出的内容应具有负边距。

这是一个完整的示例:

HTML:

<div id="outer">
   <div id="container">
       <div class="row">
           <div class="inner">Hello World</div>
       </div>
    </div>
</div>

CSS:

  #outer {
      min-width: 300px;
      overflow-x: hidden;
  }

  #container {
      width: 300px;
      margin: 0px auto;
      background: gray;
      height: 500px;    
  }

  .row {
      width: 350px;
      background: blue;
      margin-left: -25px;
  }

  .inner {
      background: yellow;
      margin-left: 25px;
      width: 300px;
      height: 100px;
  }

  @media screen and (min-width: 301px) {
      body {
          //overflow-x: hidden;
      }
  }

jsfiddle:

http://jsfiddle.net/aaronjensen/9szhN/

I was trying to figure this out myself today and stumbled upon the answer.
What you need is a surrounding element around everything that has this:

#wrapper {
  min-width: 600px; //whatever width you want
  overflow-x: hidden;
}

Your main content should have that same width, and the things that need to jut out should have a negative margin.

Here's a complete example:

HTML:

<div id="outer">
   <div id="container">
       <div class="row">
           <div class="inner">Hello World</div>
       </div>
    </div>
</div>

CSS:

  #outer {
      min-width: 300px;
      overflow-x: hidden;
  }

  #container {
      width: 300px;
      margin: 0px auto;
      background: gray;
      height: 500px;    
  }

  .row {
      width: 350px;
      background: blue;
      margin-left: -25px;
  }

  .inner {
      background: yellow;
      margin-left: 25px;
      width: 300px;
      height: 100px;
  }

  @media screen and (min-width: 301px) {
      body {
          //overflow-x: hidden;
      }
  }

jsfiddle:

http://jsfiddle.net/aaronjensen/9szhN/

暗恋未遂 2024-08-30 16:34:06

尝试在 style.css 第 65 行添加:

#footer-container {
    border: none;
    overflow: hidden;
}

说明:

#footer-container #footer {
    background: #f5e8f7 url('images/slobraico-footer-pink-full.gif') no-repeat top left;
    width: 1088px;      
    height: 217px;  
    overflow: hidden;   
    }

您隐藏的滚动条实际上​​在那里。
您看到的滚动条是另一个。
问题是页脚宽度为 1088 像素,这会导致出现滚动条。

只要页脚具有固定宽度并且其父级没有溢出:隐藏,如果页脚没有足够的宽度来容纳,您就会得到滚动。
对于任何其他容器也是如此。

Try in style.css, line 65, adding:

#footer-container {
    border: none;
    overflow: hidden;
}

Explanation:

#footer-container #footer {
    background: #f5e8f7 url('images/slobraico-footer-pink-full.gif') no-repeat top left;
    width: 1088px;      
    height: 217px;  
    overflow: hidden;   
    }

The scrollbar you're hiding is effectively not there.
The scrollbar you're seing is another one.
The problem is that the footer is 1088px wide, and that's causing a scrollbar to appear.

As long as the footer has fixed width and it's parent doesn't have overflow: hidden, you'll get a scroll if there's not enough width for the footer to fit.
Same goes for any other container.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文