Html li背景色给孩子们同样的颜色
我有一些css使列表看起来像树视图。我正在尝试更改当前选定li的背景,但它也会将所有子项更改为该背景颜色。有没有办法避免这种情况发生 下面是基本树结构,我通过读取文件夹结构的代码ULScript和ULShader来填充它。为了进行测试,我刚刚将脚本li的背景设置为灰色,当加载其他li的脚本时,它们也都是灰色的Html li背景色给孩子们同样的颜色,html,css,Html,Css,我有一些css使列表看起来像树视图。我正在尝试更改当前选定li的背景,但它也会将所有子项更改为该背景颜色。有没有办法避免这种情况发生 下面是基本树结构,我通过读取文件夹结构的代码ULScript和ULShader来填充它。为了进行测试,我刚刚将脚本li的背景设置为灰色,当加载其他li的脚本时,它们也都是灰色的 <div class="css-treeview" id="projectTree" style="display: none;"> <ul>
<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>
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;
}
}
}
你能分享你的css吗?如果你正在使用javascript,我们可以进行故障排除。但是,快速浏览一下,LI中的任何内容都会有灰色背景,因为它包含在元素中。你总是可以让孩子改变颜色。“但它也会把所有的孩子都变成背景色”——不,不应该;背景色不是继承的。当然,您会看到父元素“shine through”的背景,所有未设置其自身背景的子元素。因此,每次单击时,我必须将所有背景设置为白色,然后仅将单击的1设置为灰色?这是一种有效的处理方法还是有更好的方法?
/*
* 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;
}
}
}