<!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>Untitled Document</title>
<style type="text/css">
body { margin:0; padding:0; }
ul.tab { margin:0 auto; width:150px; }
ul,li { margin:0; padding:0; }
ul { list-style:none; }
ul li { float:left; position:relative; line-height:30px; }
ul li a { display:block; padding:0 10px; text-decoration:none; width:50px; }
ul li ul { position:absolute; right:-1px; top:30px; display:none; }
ul li a:link,ul li a:visited { color:#FFF; background:#F00; }
ul li a:hover,ul li a:active { color:#000; background:#CCC; }
ul li ul li a { width:100px; }
</style>
<script type="text/javascript">
function showMune(obj) {
obj.getElementsByTagName("ul")[0].style.display = "block";
obj.getElementsByTagName("ul")[0].style.border = "1px solid #000";
obj.style.border = "1px solid #000";
obj.style.borderBottom = "1px solid #ccc";

}
function hideMune(obj) {
obj.getElementsByTagName("ul")[0].style.display = "none";
obj.getElementsByTagName("ul")[0].style.border = "none";
obj.style.border = "none";
obj.style.borderBottom = "none";
}
</script>
</head><body>
<ul class="tab">
<li onmouseover="showMune(this)" onmouseout="hideMune(this)">
     <a href="#">中国</a>
        <ul>
         <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
        </ul>
    </li>
    <li onmouseover="showMune(this)" onmouseout="hideMune(this)">
     <a href="#">中国</a>
        <ul>
         <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
            <li><a href="#">中国</a></li>
        </ul>
    </li>
</ul>
</body>
</html>
代码如上,如何去掉上面块和下面块之间的border呢

解决方案 »

  1.   

    <script type="text/javascript">
     function showMune(obj) {
     obj.getElementsByTagName("ul")[0].style.display = "block";
     obj.getElementsByTagName("ul")[0].style.border = "1px solid #000";
     obj.getElementsByTagName("ul")[0].style.borderTop="0"
     obj.style.borderBottom = "1px solid #ccc"; }
    //所有的代码都没改只是加了在显示上面加了一句话obj.getElementsByTagName("ul")[0].style.borderTop="0"
      

  2.   

    因为子菜单ul是absolute定位,覆盖在链接上了。。可以多增加一条红线覆盖ul子菜单的上边缘。。<!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>Untitled Document</title>
    <style type="text/css">
    body { margin:0; padding:0; }
    ul.tab { margin:0 auto; width:150px; }
    ul,li { margin:0; padding:0; }
    ul { list-style:none; }
    ul li { float:left; position:relative; line-height:30px; }
    ul li a { display:block; padding:0 10px; text-decoration:none; width:50px; }
    ul li div.line{width:100%;height:1px;background:#f00;overflow:hidden;z-index:2;position:absolute;display:none}/*---红线样式----*/
    ul li ul { position:absolute; right:-1px; top:30px; display:none; z-index:1;}
    ul li a:link,ul li a:visited { color:#FFF; background:#F00; }
    ul li a:hover,ul li a:active { color:#000; background:#CCC; }
    ul li ul li a { width:100px; }
    </style>
    <script type="text/javascript">
        function showMune(obj) {
            obj.getElementsByTagName("ul")[0].style.display = "block";
            obj.getElementsByTagName("div")[0].style.display = "block";//显示红线
            obj.getElementsByTagName("ul")[0].style.border = "1px solid #000";
            obj.style.border = "1px solid #000";
            obj.style.borderBottom = "1px solid #ccc";    }
        function hideMune(obj) {
            obj.getElementsByTagName("ul")[0].style.display = "none";
            obj.getElementsByTagName("ul")[0].style.border = "none"; //隐藏红线
            obj.getElementsByTagName("div")[0].style.display = "none";
            obj.style.border = "none";
            obj.style.borderBottom = "none";
        }
    </script>
    </head><body>
    <ul class="tab">
    <li onmouseover="showMune(this)" onmouseout="hideMune(this)">
         <a href="#">中国</a><div class="line"></div><!--红线-->
            <ul>
             <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
            </ul>
        </li>
        <li onmouseover="showMune(this)" onmouseout="hideMune(this)">
         <a href="#">中国</a><div class="line"></div><!--红线-->
            <ul>
             <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
            </ul>
        </li>
    </ul>
    </body>
    </html>
      

  3.   


    <!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>Untitled Document</title>
    <style type="text/css">
    body { margin:0; padding:0; }
    ul.tab { margin:0 auto; width:150px; }
    ul,li { margin:0; padding:0; }
    ul { list-style:none; }
    ul li { float:left; position:relative; line-height:30px; }
    ul li a {display:block; padding:0 10px; text-decoration:none; width:50px;text-align:center;}
    ul li a.s:hover{line-height:29px;padding:0 9px;}
    ul li div.line{width:100%;height:1px;background:#f00;overflow:hidden;z-index:2;position:absolute;display:none}/*---红线样式----*/
    ul li ul { position:absolute; right:0px; top:30px; display:none; z-index:1;}
    ul li a:link,ul li a:visited { color:#FFF; background:#F00; }
    ul li a:hover,ul li a:active { color:#000; background:#CCC; }
    ul li ul li a { width:100px; }
    </style>
    <script type="text/javascript">
        function showMune(obj) {
            obj.getElementsByTagName("ul")[0].style.display = "block";
            obj.getElementsByTagName("ul")[0].style.border = "1px solid #000";
            obj.getElementsByTagName("a")[0].style.border = "1px solid #000";
            obj.getElementsByTagName("a")[0].style.borderBottom = "1px solid #ccc";
     
        }
        function hideMune(obj) {
            obj.getElementsByTagName("ul")[0].style.display = "none";
            obj.getElementsByTagName("ul")[0].style.border = "none"; //隐藏红线
            obj.getElementsByTagName("a")[0].style.border = "none";
            obj.getElementsByTagName("a")[0].style.borderBottom = "none";
        }
    </script>
    </head>
     
    <body>
    <ul class="tab">
    <li onmouseover="showMune(this)" onmouseout="hideMune(this)">
         <a href="#" class="s">中国</a>
            <ul>
             <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
            </ul>
        </li>
        <li onmouseover="showMune(this)" onmouseout="hideMune(this)">
         <a href="#" class="s">中国</a>
            <ul>
             <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
                <li><a href="#">中国</a></li>
            </ul>
        </li>
    </ul>
    </body>
    </html>