26.12.2008
category: CSS
tags:
tags:
这是一个自适应的圆角DIV。底部的两个圆角是由两个绝对定位的DIV分别设置{left:0;bottom:0;}和{right:0;bottom:0}做成的。所以不管DIV内的文字如何增减,它们始终定位在底部。
但是当内容通过程序动态增加时,但IE6无法响应到外层尺寸出现的变化,原先的绝对定位还是停留在原处。导致DIV被撑破。
解决方法:在底部绝对定位的DIV外面套一个position:relative。
代码如下
- <!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>
- <title> new document </title>
- <meta http-equiv="content-type" content="text/html;charset=UTF-8">
- <style>
- *{margin:0;padding:0;font-family:"MS PGothic"}
- /*roundCorner start*/
- .roundCornerOuter {width:482px;position:relative; background:#fffdf8;overflow:hidden;float:left; }
- .roundCornerContent {position:relative; z-index:1; width:100%}
- .rc_t_l {position:absolute; top:0; background:url(images/roundCorner.gif) -20px -20px;width:20px;height:20px; font-size:1px }
- .rc_t_m {position:absolute;top:0; background:url(images/roundCorner.gif) 0 0 repeat-x;width:100%;height:20px; font-size:1px }
- .rc_t_m span {position:absolute; background:url(images/roundCorner.gif) -40px 0 repeat-x;width:100%;height:20px;font-size:1px }
- .rc_t_r {position:absolute; right:0;top:0;background:url(images/roundCorner.gif) -40px -20px;width:20px; height:20px; font-size:1px }
- .rc_m_l {position:absolute;top:20px; background:url(images/roundCorner.gif) 0 -20px; width:20px;}
- .rc_m_r {position:absolute;top:20px;right:0; background:url(images/roundCorner.gif) -60px -20px; width:20px; }
- .rc_m_l span {display:block; background:url(images/roundCorner.gif) 0 20px; width:20px;height:2000px; }
- .rc_m_r span {display:block; background:url(images/roundCorner.gif) -60px 20px; width:20px;height:2000px; }
- .rc_b_l {position:absolute; bottom:0;background:url(images/roundCorner.gif) -20px -40px; width:20px;height:20px;font-size:1px }
- .rc_b_r {position:absolute; bottom:0;right:0;background:url(images/roundCorner.gif) -40px -40px; width:20px;height:20px; font-size:1px }
- .rc_b_m {position:absolute;bottom:0; background:url(images/roundCorner.gif) 0 -60px repeat-x;width:100%;height:20px; font-size:1px }
- .rc_b_m span {position:absolute; background:url(images/roundCorner.gif) -40px -60px repeat-x;width:100%;height:20px;font-size:1px }
- /*roundCorner end*/
- .rc_b_fixIE6 {position:relative; height:20px; } /*解决问题的层*/
- #newDiv {height:200px ;background:#ccc; } /*动态追加的层*/
- </style>
- </head>
- <body style="margin:10%">
- <div class="roundCornerOuter">
- <div class="roundCornerContent">
- <a class="btn businessMasterAdd"
- id="btn">点击</a><br /><br />
- <div id="father" style="margin:0 auto;width:50px">
- </div>
- </div>
- <div class="rc_t_m">
- <span></span>
- </div>
- <div class="rc_t_l">
- </div>
- <div class="rc_t_r">
- </div>
- <div class="rc_m_l">
- <span></span>
- </div>
- <div class="rc_m_r">
- <span></span>
- </div>
- <div class="rc_b_fixIE6">
- <div class="rc_b_m">
- <span></span>
- </div>
- <div class="rc_b_l">
- </div>
- <div class="rc_b_r">
- </div>
- </div>
- </div>
- <!-- 模拟动态追加效果 -->
- <script language="javascript">
- document.getElementById("btn").onclick = function(){
- var newelem = document.createElement("div");
- newelem.setAttribute("id","newDiv")
- document.getElementById("father").appendChild(newelem);
- }
- </script>
- </body>
- </html>
BTW:这个自适应圆角DIV的制作方法初见觉得很麻烦(BI会员提供),但整理一下之后以后使用就直接复制粘贴还是很方便的。
XHTML: You can use these tags: