应用于特定DIV时,CSS会遗漏一些细节

时间:2017-04-18 08:15:38

标签: html css

尝试将某些样式应用于特定div时,我有一种奇怪的情况。这是代码:

    <style>
        div#West_Pane {
            ul {
                animation-duration: 4s;
                padding-left: 20px;
            }
            ul li {
                display: block ;
                cursor:pointer;
                animation-duration: 4s;
                font-size: 12px;
                clear: both;
                -webkit-user-select: none;  /* Prevent selection on double click for Chrome/Safari  */        
                -moz-user-select: none;     /* Prevent selection on double click for Firefox        */
                -ms-user-select: none;      /* Prevent selection on double click for IE10+          */
            }

            li.groupCollapsed:before {
                content: "\e080";
                font-family: 'Glyphicons Halflings';
                font-size: 12px;
                float: left;
                margin-top: 4px;
                margin-left: -17px;
                color: blue;
            }

            li.groupExpanded:before {
                content: "\e114";
                font-family: 'Glyphicons Halflings';
                font-size: 12px;
                float: left;
                margin-top: 4px;
                margin-left: -17px;
                color: blue;
            }
        }
    </style>
<div id="West_Pane" ng-controller="Main_Commands_List_Controller" style="background:#f9ebea;">
    <compile-Directive id="cmpldirective" content="Commands_Tree_Contents_LTR"></compile-Directive>
</div>

West_Pane的内容是生成的多级菜单。它工作正常,所以我没有显示JavaScript。

如果我注释掉div#West_Pane{...}包装,则所有内容都会根据需要显示在菜单中,但同一页面中的其他内容会受到负面影响。

当我取消注释时,会发生两件事:

  1. cursor:pointer元素(请参阅ul il的设置)似乎被忽略了,

  2. 未显示为groupCollapsed:beforegroupExpanded:before类设置的Glyphicons(事实上,在浏览器中检查before内容时,没有任何定义,甚至没有之前元素的一部分。)

1 个答案:

答案 0 :(得分:1)

我通过尝试和错误找到了这个问题,但在得到明确的理解之后却没有。 获得所需结果需要进行两项更改:

  1. 删除分隔css规范中元素的空格,例如:

     .class > li + li {...}
    

    应该是:

     .class>li+li {...}
    
  2. 问题在于,多标签div的药丸在另一个之后显示为另一个。我通过为这些药片设置一个小类定义并设置float:none;

  3. 来解决这个问题

    希望这对那些面临同样问题的人有所帮助。