CSS - 孙子只在IE中继承来自不同父级的类

0 html css inheritance internet-explorer

我遇到了Internet Explorer的问题.我喜欢举起手来说我不想支持它,但这不是一个选择.基本上,我写了一个无序列表用于导航.然后在另一个部分,使用另一个父,我使用另一个无序列表,但它继承了另一个ID的属性.它在其他浏览器中完全正常.我删除了页面的基本部分,并在下面发布.另外,我检查了w3c css验证器,我收到的警告说"在两种情况下#container和#stripes ul a:link"中的颜色和背景颜色相同.

你会看到如果点击项目符号列表,它们的样式就像导航一样.但是,当我尝试更改项目符号列表时,它会影响导航!我尝试在maincontent中设置所有属性,但随后关闭所有内容.

有人可以检查出来并提供帮助吗?它的种类让我感到沮丧!

<!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>2012 Summer Blood Challenge</title>
<style  type="text/css">

#stripes ul
{ font-size:13px;
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;

}
#stripes li
{
float:left; 
}
#stripes ul a:link,a:visited
{
display:block;
width:128px;
font-weight:bold;
color:#FFFFFF; background-image:url(https://trigger.lwcdirect.com/LWC_00486/uploadImages/2012sbc/redbar.jpg);
 background-position: bottom;
text-align:center;
padding:4px;
text-decoration:none;
height:32px;
}
#stripes ul a:hover,a:active
{
background-image:url(https://trigger.lwcdirect.com/LWC_00486/uploadImages/2012sbc/darkredbar.jpg);
}

.roundside {
    background-image: url(https://trigger.lwcdirect.com/LWC_00486/uploadImages/2012sbc/goldboxes_02.jpg);
    background-repeat: repeat-y;
    width: 560px;
    text-align: left;
    padding: 0 30px 0 30px;
}

.roundside ul {list-style-type: none;
    margin: 0;
    padding: 0;}

.roundside li {background-image:url(https://trigger.lwcdirect.com/LWC_00486/uploadImages/2012sbc/drop.gif);

    background-repeat:no-repeat;
    padding:0 0 5px 16px; font-size:16px;}

.roundside ul a:link,a:visited,a:hover,a:active {color:#990000; font-weight:bold}


</style>
</head>
<body class="oneColFixCtrHdr">
<div id="largecontainer"><!--set centering-->
        <div id="container"><!--creates box-->
            <div id="stripes">

            <center>
            <ul>
                <li><a href="#">Promotional Materials</a></li>
                <li><a href="#" style="font-size:11px">Participating Employers and Results</a></li> 
                <li><a href="#">Newsletters</a></li>
                <li><a href="#">Give Blood</a></li>
                <li><a href="#">Become a Member</a></li>
            </ul>
            </center>

            </div><!--end stripes-->
            <div id="mainContent">
                    <div class="roundside">
                    <ul>
                        <li><a href="#">Official Rules and Point Structure</a></li>
                        <li><a href="#">Gage Flyer 8.5x11</a></li>
                        <li><a href="#">2012 SBC Hero Card</a></li>
                    </ul>
                 </div>
            </div> <!-- end #mainContent -->
            <div id="footer">&nbsp;
            </div><!-- end #footer -->
        </div><!--end container-->
    </div><!-- end #largecontainer -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

fro*_*guy 7

你的第二个ul内部是因为以下css而.roundside从中获取#stripes ulcss的原因

#stripes ul a:link,a:visited
Run Code Online (Sandbox Code Playgroud)

你需要改变它

#stripes ul a:link, #stripes ul a:visited
Run Code Online (Sandbox Code Playgroud)

否则它会将之后声明的样式应用于a:visited网站上的每一个,而不仅仅是在#stripes ul

这也是#stripes ul a:hover,a:active需要改变的情况,#stripes ul a:hover, #stripes ul a:hover a:active否则你会遇到同样的问题.

希望这能解决您的问题.

编辑:MrSlayer在下面的评论中提出了一个很好的观点,我错过了.

改变你也会更好

.roundside ul a:link,a:visited,a:hover,a:active {color:#990000; font-weight:bold}
Run Code Online (Sandbox Code Playgroud)

.roundside ul a:link, .roundside ul a:visited, .roundside ul a:hover, .roundside ul a:active {color:#990000; font-weight:bold}
Run Code Online (Sandbox Code Playgroud)

避免a将来出现任何令人讨厌的相关意外.在CSS中,您需要在设置样式时尽可能具体