div 容器上的 CSS 框阴影被切断
编辑:更一般的问题: 我喜欢 div 上的 box-shadow,但是当我将 div 直接放置在 box-shadow 的 div 下方时,尽管 z 索引混乱,但阴影的底部部分不会覆盖在顶部。所以看起来 box-shadow 不能覆盖另一个 div ?任何想法都会很棒!
原来的问题—— 我正在使用蓝图进行布局。这意味着有一个 950px
的 .container,其中包含 #content
。
在本例中,#content
填充了整个容器,因此也是 950px
。
我想在 #content
上添加阴影,但问题是阴影被切断,因为 .container
中没有剩余空间可以看到它。
解决方法是减小 #content
的宽度,但这会扰乱我已有的布局定位,而且看起来太窄了。
有没有办法让盒子阴影忽略父容器并出现在它上面?我猜这不是特定于蓝图的,但这就是上下文。谢谢!
编辑:
body .container {
margin: 0 auto;
overflow: hidden;
width: 950px;
}
body .container:after {
clear: both;
content: "";
display: table;
}
#content {
display: inline;
float: left;
margin-right: 0;
width: 950px;
box-shadow: 0 0 4px black;
-moz-box-shadow: 0 0 4px black;
}
#content
直接位于.container
中。如果我在 #content
上放置阴影,则在缩小宽度之前您将看不到它,这会与内部元素混淆。
edit: more general question:
I like the box-shadow on divs, however when I place a div directly below the box-shadow'd div, that bottom part of the shadow doesn't overlay on top despite messing with z-indexes. So it seems like box-shadow cannot overlay another div? Any ideas would be great!
original question-
I am using blueprint for a layout. This means there's a .container of 950px
which then contains a #content
.
In this case the #content
fills the whole container so is also 950px
.
I would like to have a drop shadow on the #content
, but the problem is the shadow gets cut off since there is no space left to see it in the .container
.
A workaround would be to decrease the width of the #content
but that messes up the layout positionings I already have, and it looks too narrow.
Is there a way to get the box shadow to kind of ignore the parent container and appear over it? This isn't blueprint specific I guess, but that's the context. thanks!
EDIT:
body .container {
margin: 0 auto;
overflow: hidden;
width: 950px;
}
body .container:after {
clear: both;
content: "";
display: table;
}
#content {
display: inline;
float: left;
margin-right: 0;
width: 950px;
box-shadow: 0 0 4px black;
-moz-box-shadow: 0 0 4px black;
}
#content
is directly in .container
. If I put a drop shadow on #content
you can't see it until I shrink the width, which messes with the inside elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会向
.container
元素添加一些填充,并确保您的#content
保持所需的宽度。I would add some padding to the
.container
element and ensure that your#content
stays at the width you need.您不需要
.container
上的overflow:hidden
,因为您已经对其使用了清除修复。所以,你可以把它扔掉: http://jsfiddle.net/kizu/gDXLf/You don't need the
overflow: hidden
on the.container
, since you already use clear fix on it. So, you can just throw it away: http://jsfiddle.net/kizu/gDXLf/这完全取决于您想要实现的目标。
我在处理列表项的内联块组时遇到困难。鼠标悬停时,右侧阴影被旁边的列表项切断
一个简单的技巧是将以下内容添加到元素中:
工作示例
尽管如此,这可能仅适用于特定场景。我只在上面的示例中测试过它。
It all depends what you are trying to achieve.
I was having difficulty with an inline-block group of list items. The right shadow was cut off by the list item next to it upon hover
A simple hack is to just add the following to the element:
WORKING EXAMPLE
Although, this may only work for specific scenarios. I have only tested it on my example above.
您可以使 .container 更宽(对于固定宽度,960 完全可以接受)并保持 #content 在 .container 内居中。这对你来说有什么麻烦吗?
You could make the .container wider (960 is perfectly acceptable for a fixed width) and keep the #content centered inside the .container. Does that mess up anything for you?