CSS 框阴影问题

发布于 2024-09-27 05:04:32 字数 396 浏览 9 评论 0原文

我正在构建此页面: http://ss.rsportugal.org/

如您所见,有页面中的两个 10 像素阴影。一个位于菜单下方,另一个位于页脚栏上方。 这些阴影是使用 box-shadow: 0 0 10 rgba(...); 制作的,

它在 WebKit 引擎中按预期工作,由于某种原因,我无法弄清楚,我可以使用一些新鲜的注意到这一点,Gecko 和 Opera 在 #header 宽度上添加了 5 个额外像素,而不是在 #footer-container 上,使水平滚动条出现在 body 上。如果我删除盒子阴影也可以正常工作,但我想保留它。 ):

I'm building this page: http://ss.rsportugal.org/

As you can see, there are two 10 pixel shadows in the page. One just bellow the menu and the other just above the footer bar.
These shadows are made using box-shadow: 0 0 10 rgba(...);

It works as expected in WebKit engine and for some reason that I am unable to figure out and I could use some fresh eyes on this, Gecko and Opera add 5 extra pixels to #header width and not to #footer-container, making a horizontal scrollbar appear on the body. Also works fine if I remove the box-shadow but I kind of want to keep it. ):

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

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

发布评论

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

评论(3

很快妥协 2024-10-04 05:04:32

那是因为您已将宽度设置为 100%,因此在添加盒阴影后,其宽度为 100%+10px(10px 在两侧之间划分)。如果您也在标题上使用 position:fixed; ,则不会出现此问题。顺便说一下,它在 Safari 中做了同样的事情,所以 webkit 受到影响。你可以做的是将它们包装在一个容器中,并使用 overflow:hidden 将其设置为 100%,然后在内部元素上根据需要使用框阴影将其设置为 100% ..这样它就会得到剪掉左/右侧。

像这样的东西:

<style type="text/css">
  #header {
    background:none repeat scroll 0 0 rgba(0, 0, 0, 0.7);
    left:0;
    overflow:hidden;
    position:absolute;
    top:0;
    width:100%;
    z-index:4;
  }
  #header-inner {
     width: 100%; 
     -moz-box-shadow: 0pt 0pt 10px rgb(0, 0, 0);
  }
</style>
<div id="header">
<div id="header-inner">
    <div id="logo">
        ...
    </div>
    <div id="menu-background"></div>
    <div id="menu-wrapper">
        ...
    </div>
</div>
</div>

Thats because youve set the width to 100% so after the box-shadow is added its 100%+10px (the 10px beign divided between the two sides). If you used position:fixed; on the header as well you wouldnt have the issue. Its doing the same thing in Safari by the way, so webkit IS effected. What you could do is wrap them in a container and set that to 100% with overflow:hidden then on the inner element make it also 100% with the box shadow as desired.. this way it will get clipped off the left/right sides.

Something like:

<style type="text/css">
  #header {
    background:none repeat scroll 0 0 rgba(0, 0, 0, 0.7);
    left:0;
    overflow:hidden;
    position:absolute;
    top:0;
    width:100%;
    z-index:4;
  }
  #header-inner {
     width: 100%; 
     -moz-box-shadow: 0pt 0pt 10px rgb(0, 0, 0);
  }
</style>
<div id="header">
<div id="header-inner">
    <div id="logo">
        ...
    </div>
    <div id="menu-background"></div>
    <div id="menu-wrapper">
        ...
    </div>
</div>
</div>
国产ˉ祖宗 2024-10-04 05:04:32

尝试检查 box-sizing 属性。

Webkit 使用与 FF 不同的盒子模型来调整盒子大小。 IE 与两者不同。

确保为所有浏览器声明相同的类型,并且所有内容都应该在相同的盒子模型中处理,因此,不会产生任何令人厌恶的惊喜。

Try checking box-sizing property.

Webkit uses different box-model for box-sizing than FF. IE differ from both.

Ensure you declare the same kind for all browsers, and everything should be processed in the same box-model, thus, not making any disgusting surprises.

知你几分 2024-10-04 05:04:32

It looks like you've already fixed the site, but it sounds like this is a known bug that I landed the fix for last week (so the fix should be in Firefox 4 beta 8, though we haven't shipped beta 7 yet).

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