<div class='list'><div class='item'><a>Link</a></div><div class='parent-background'></div><!-- submenu takes this place --></div>
CSS的一部分
/* Hide parent backgrounds... */.parent-background {display: none; }
/* ... and show it when hover on children */.item:hover + .parent-background {display: block;position: absolute;z-index: 10;top: 0;width: 100%; }
/* Hide things that may be latter shown */.menu__checkbox__selection,.menu__checkbox__style,.menu__hidden {display: none;visibility: hidden;opacity: 0;filter: alpha(opacity=0); /* Old Microsoft opacity */}
/* Base style for content and style menu */.main__content {background-color: lightgray;color: black;}
.menu__hidden {background-color: black;color: lightgray;/* Make list look not so _listy_ */list-style: none;padding-left: 5px;}
.menu__option {box-sizing: content-box;display: block;position: static;z-index: auto;}
/* ▼ - \u2630 - Three Bars *//*.menu__trigger__selection::before {content: '\2630';display: inline-block;}*/
/* ▼ - Down Arrow */.menu__trigger__selection::after {content: "\25BC";display: inline-block;transform: rotate(90deg);}
/* Customize to look more `select` like if you like */.menu__trigger__style:hover,.menu__trigger__style:active {cursor: pointer;background-color: darkgray;color: white;}
/*** Things to do when checkboxes/radios are checked*/
.menu__checkbox__selection:checked + .menu__trigger__selection::after,.menu__checkbox__selection[checked] + .menu__trigger__selection::after {transform: rotate(0deg);}
/* This bit is something that you may see elsewhere */.menu__checkbox__selection:checked ~ .menu__hidden,.menu__checkbox__selection[checked] ~ .menu__hidden {display: block;visibility: visible;opacity: 1;filter: alpha(opacity=100); /* Microsoft!? */}
/*** Hacky CSS only changes based off non-inline checkboxes* ... AKA the stuff you cannot unsee after this...*/.menu__checkbox__style[id="style-default"]:checked ~ .main__content {background-color: lightgray;color: black;}
.menu__checkbox__style[id="style-default"]:checked ~ .main__content .menu__trigger__style[for="style-default"] {color: darkorange;}
.menu__checkbox__style[id="style-one"]:checked ~ .main__content {background-color: black;color: lightgray;}
.menu__checkbox__style[id="style-one"]:checked ~ .main__content .menu__trigger__style[for="style-one"] {color: darkorange;}
.menu__checkbox__style[id="style-two"]:checked ~ .main__content {background-color: darkgreen;color: red;}
.menu__checkbox__style[id="style-two"]:checked ~ .main__content .menu__trigger__style[for="style-two"] {color: darkorange;}
<!--This bit works, but will one day cause troubles,but truth is you can stick checkbox/radio inputsjust about anywhere and then call them by id witha `for` label. Keep scrolling to see what I mean--><input type="radio"name="colorize"class="menu__checkbox__style"id="style-default"><input type="radio"name="colorize"class="menu__checkbox__style"id="style-one"><input type="radio"name="colorize"class="menu__checkbox__style"id="style-two">
<div class="main__content">
<p class="paragraph__split">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo</p>
<input type="checkbox"class="menu__checkbox__selection"id="trigger-style-menu"><label for="trigger-style-menu"class="menu__trigger__selection"> Theme</label>
<ul class="menu__hidden"><li class="menu__option"><label for="style-default"class="menu__trigger__style">Default Style</label></li>
<li class="menu__option"><label for="style-one"class="menu__trigger__style">First Alternative Style</label></li>
<li class="menu__option"><label for="style-two"class="menu__trigger__style">Second Alternative Style</label></li></ul>
<p class="paragraph__split">consequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="outer-div"><div class="inner-div">I want to change outer-div(Background color) class based on inner-div. Is it possible?<input type="text" placeholder="Name" /></div></div>
<ul><li class="listitem"><a class="link" href="#">This is a Link</a></li></ul>
现在使用a上的active伪类应用这些样式以在单击链接时重新设置父li标记的样式:
a.link {display: inline-block;color: white;background-color: green;text-decoration: none;padding: 5px;}
li.listitem {display: inline-block;margin: 0;padding: 0;background-color: transparent;}
/* When this 'active' pseudo-class event below fires on click, it hides itself,triggering the active event again on its parent which applies new styles to itself and its child. */
a.link:active {display: none;}
.listitem:active {background-color: blue;}
.listitem:active a.link {display: inline-block;background-color: transparent;}