父元素的背景色无法覆盖子元素的背景色,怎么办?

zjleon2008 2012-03-26 08:20:27
我想要模拟一个阴影效果,可是红色的fixed无法覆盖灰色的shadow,要怎么设置才得?
fixed必须用absolute,shadow放到fixed里是为了根据fixed的高宽自动变化


#fixed {
background-color:red;
width:100px;
height:100px;
top:50px;
right:20px;
display:block;
position:absolute;
z-index:5;
}
#fixed .shadow{
position:absolute;
top:2px;
left:2px;
display:block;
width:101%;
height:101%;
background-color:#555;
z-index:4;
}


<div id="fixed">
<ul>
<li>asfasfsd</li>
</ul>
<div class="shadow"></div>
</div>

...全文
1187 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

怎么模拟阴影?有阴影就需要光源,如果整个网页多处用到阴影,那么光源就应该一致,这样才看上去比较真实。
如果光源在左上45度,那么阴影就应该在右边和下边,但为了真实还应该同时模拟亮边。而且真实的阴影还和被照面的背景色有关(光的衍射)。
用HTML,CSS技术的语言来说,就是用两个DIV(一个嵌套在另一个中),经过精心设计两个DIV的边框颜色和内层DIV的背景颜色,就可以模拟出相当真实的阴影。
……
[/Quote]
本来还想来 献丑 的 看到这么经典的 就没得说了。这个 很强大。
zhoulina251314 2012-03-29
  • 打赏
  • 举报
回复
给你一个自动延伸背景效果的参考

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{margin:0px auto; padding:0px; font:12px/24px Arial, Helvetica, sans-serif; color:#333;}
a,a:hover{font-size:12px; line-height:24px; color:#333; text-decoration:none;}
a:hover{text-decoration:underline;}
.testDiv{width:400px; margin:20px; float:left; display:inline; position:relative;}
.testDiv_main{width:360px; float:left; display:inline; background:#F00; color:#FFF; padding:10px 20px; position:relative; z-index:2;}
.testDiv_shadow{ position:absolute; left:3px; top:3px; background:#CCC; width:400px; z-index:1;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".testDiv_shadow").height($(".testDiv").height()) ;
})
</script>
</head>

<body>
<div class="testDiv">
<div class="testDiv_main">我想要模拟一个阴影效果,可是红色的fixed无法覆盖灰色的shadow,要怎么设置才得我想要模拟一个阴影效果,可是红色的fixed无法覆盖灰色的shadow,要怎么设置才得我想要模拟一个阴影效果,可是红色的fixed无法覆盖灰色的shadow,要怎么设置才得我想要模拟一个阴影效果,可是红色的fixed无法覆盖灰色的shadow,要怎么设置才得</div>
<div class="testDiv_shadow"></div>
</div>
</div>

</body>
</html>
wzhiyuan 2012-03-27
  • 打赏
  • 举报
回复
怎么模拟阴影?有阴影就需要光源,如果整个网页多处用到阴影,那么光源就应该一致,这样才看上去比较真实。
如果光源在左上45度,那么阴影就应该在右边和下边,但为了真实还应该同时模拟亮边。而且真实的阴影还和被照面的背景色有关(光的衍射)。
用HTML,CSS技术的语言来说,就是用两个DIV(一个嵌套在另一个中),经过精心设计两个DIV的边框颜色和内层DIV的背景颜色,就可以模拟出相当真实的阴影。

我这里给出一个WINDOWS 2003警告对话框的例子。
<div style="position:absolute;left:50%;top:300px;border-top:1px solid #d6d3ce;border-left:1px solid #d6d3ce;border-right:1px solid #424142;border-bottom:1px solid #424142;" >
<div style="background-color:#d6d3ce;width:300px;height:200px;border-top:1px solid #ffffff;border-left:1px solid #ffffff;border-right:1px solid #848284;border-bottom:1px solid #848284;" >
some text
</div>
</div>


我爱小土豆 2012-03-27
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#fixed {
background-color:#555;
width:100px;
height:100px;
top:50px;
right:20px;
display:block;
position:absolute;
z-index:5;
}
#fixed .shadow{
position:absolute;
top:2px;
left:2px;
display:block;
width:101%;
height:101%;
background-color:red;
z-index:4;
}
</style>
</head>

<body>
<div id="fixed">
<ul>
<li>asfasfsd</li>
</ul>
<div class="shadow"></div>
</div>

</body>
</html>
missgd152 2012-03-27
  • 打赏
  • 举报
回复
<style type="text/css">
#fixed {
background-color:red;
width:100px;
height:100px;
top:50px;
right:20px;
display:block;
position:absolute;
z-index:5;
}
#fixed .shadow{
position:absolute;
top:2px;
left:2px;
display:block;
width:101%;
height:97%;
background-color:#555;
z-index:4;
}
</style>
ycproc 2012-03-26
  • 打赏
  • 举报
回复
可以使用 jquery 的一些 效果来增强
Acesidonu 2012-03-26
  • 打赏
  • 举报
回复

#fixed {
width:100px;
height:100px;
top:50px;
right:20px;
position:absolute;
}
#fixed .shadow{
position:absolute;
top:2px;
left:2px;
width:101%;
height:101%;
background-color:#555;
z-index:-1;
}
#fixed ul {
list-style: none;
margin: 0px;
padding: 0px;
top:50px;
right:20px;
width: 100%;
height: 100%;
background-color: red;
}

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧