li背景颜色给孩子们相同的颜色

时间:2015-03-05 17:05:17

标签: html css

我有一些css使列表看起来像树视图。我正在尝试更改当前所选li的背景,但它也将所有它的子项更改为该背景颜色。有没有办法不发生这种情况?

这是基本树结构,然后我通过代码ulScripts和ulShaders来读取文件夹结构。为了测试,我只是将Scripts li背景设置为灰色,当其他li加载时,它们也都是灰色的。

<div class="css-treeview" id="projectTree" style="display: none;">
            <ul>
                <li><input type="checkbox" id="projectRoot" /><label for="ProjectRoot" id="projectRootLabel">ProjectName</label>
                    <ul>
                        <li><input type="checkbox" id="Scripts" /><label for="Scripts">Scripts</label>
                            <ul id="ulScripts">
                            </ul>
                        </li>
                        <li><input type="checkbox" id="Shaders" /><label for="Shaders">Shaders</label>
                            <ul id="ulShaders">
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>

Jquery选择li

$(".css-treeview li").each(function(){
                $(this).click(function(){
                    $(this).css("background-color", "gray");
                });
            });

Treeview css,我也很乐意改变它,所以如果你点击标签需要点击dbl点击它,就像现在一样扩展它。复选框部分仍然是单击

/*
 * CSS3 Treeview. No JavaScript
 * @version 1.0
 * @author Martin Ivanov
 * @url developer's website: http://wemakesites.net/
 * @url developer's twitter: https://twitter.com/#!/wemakesitesnet
 * @url developer's blog http://acidmartin.wordpress.com/
 **/

/*
 * This solution works with all modern browsers and Internet Explorer 9+. 
 * If you are interested in purchasing a JavaScript enabler for IE8 
 * for the CSS3 Treeview, please, check this link:
 * http://experiments.wemakesites.net/miscellaneous/acidjs-css3-treeview/
 **/

.css-treeview ul,
.css-treeview li
{
    padding: 0;
    margin: 0;
    list-style: none;
}

.css-treeview input
{
    position: absolute;
    opacity: 0;
}

.css-treeview
{
    font: normal 11px "Segoe UI", Arial, Sans-serif;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
}

.css-treeview a
{
    color: #00f;
    text-decoration: none;
}

.css-treeview a:hover
{
    text-decoration: underline;
}

.css-treeview input + label + ul
{
    margin: 0 0 0 22px;
}

.css-treeview input ~ ul
{
    display: none;
}

.css-treeview label,
.css-treeview label::before
{
    cursor: default;
}

.css-treeview input:disabled + label
{
    cursor: default;
    opacity: .6;
}

.css-treeview input:checked:not(:disabled) ~ ul
{
    display: block;
}

.css-treeview label,
.css-treeview label::before
{
    background: url("../img/icons.png") no-repeat;
}

.css-treeview label,
.css-treeview a,
.css-treeview label::before
{
    display: inline-block;
    height: 16px;
    line-height: 16px;
    vertical-align: middle;
}

.css-treeview label
{
    background-position: 18px 0;
}

.css-treeview label::before
{
    content: "";
    width: 16px;
    margin: 0 22px 0 0;
    vertical-align: middle;
    background-position: 0 -32px;
}

.css-treeview input:checked + label::before
{
    background-position: 0 -16px;
}

/* webkit adjacent element selector bugfix */
@media screen and (-webkit-min-device-pixel-ratio:0)
{
    .css-treeview 
    {
        -webkit-animation: webkit-adjacent-element-selector-bugfix infinite 1s;
    }

    @-webkit-keyframes webkit-adjacent-element-selector-bugfix 
    {
        from 
        { 
            padding: 0;
        } 
        to 
        { 
            padding: 0;
        }
    }
}

0 个答案:

没有答案