我有一个黑暗的主题/灯光主题按钮,它运作良好,但我只是想知道如何更改导航栏的背景颜色。这是我的代码:
BEGIN;
CREATE TABLE `base_testmodel` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(32) NOT NULL,
`x` integer NOT NULL,
`y` integer NULL,
`z` integer NULL
);
COMMIT;

body {
margin: 0px;
padding: 0px;
overflow-y: scroll;
font-family: Helvetica;
font-size: 18px;
background-color: #bdbdbd;
}
.nav {
background-color: #222;
position: relative;
width: 100%;
}
.nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: left;
}
.nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
.nav ul li {
display: inline-block;
background-color: #222;
transition: background-color 0.3s ease-in;
position: relative;
padding-top: 3px;
padding-bottom: 3px;
}
.nav ul li img {
width: 12px;
height: 10px;
vertical-align: middle;
padding-left: 10px;
}
.nav ul li a,visited {
display: block;
padding: 15px;
text-decoration: none;
transition: color 0.2s ease-in;
}
.nav ul li a:hover {
text-decoration: none;
color: #099;
}
.navhome {
color: #099;
border-bottom: 3px solid #099;
}
.navother {
color: #ccc;
}
.content {
text-align: center;
line-height: 130%;
font-size: 20px;
display: inline-block;
}
.bdaimg {
width: 50%;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
margin-top: 30px;
transform: scale(1);
transition-duration: 0.3s;
border-radius: 15px;
}
.bdaimg:hover {
transform: scale(1.1);
transition-duration: 0.3s;
}
.nu {
font-weight: bold;
font-size: 25px;
}
h3 {
font-weight: bold;
text-decoration: underline;
}
h2 {
font-weight: bold;
text-decoration: underline;
}
.bdaimg2 {
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
margin-top: 30px;
transform: scale(1);
transition-duration: 0.3s;
border-radius: 15px;
}
.bdaimg2:hover {
transform: scale(1.1);
transition-duration: 0.3s;
}
/*Light Switch*/
label {
display: block;
height: 25px;
width: 100px;
background: white;
text-align: center;
font: 14px/25px Helvetica, Arial, sans-serif;
margin: 20px 0;
position: absolute;
}
label:hover {
background: #ddca7e;
color: white;
cursor: pointer;
}
input#lightswitch {
position: fixed ;
top: -9999px;
left: -9999px;
}
input#lightswitch + .content {
background-color: #bdbdbd;
transition: background-color 0.5s ease-in;
}
/*Switched Off*/
input#lightswitch:checked + .content {
background-color: #222;
transition: background-color 0.5s ease-in;
}
input#lightswitch:checked + .content {
color: white;
transition: color 0.5s ease-in;
}
input#lightswitch:checked + .content {
color: white;
transition: color 0.5s ease-in;
}

答案 0 :(得分:1)
您无法定位导航的样式,因为它在输入之前。如果您能够更改元素的顺序,那么输入在导航之前,然后定位在您想要的位置。
<label for="lightswitch">Light Switch</label>
<input type="checkbox" id="lightswitch" />
<div class="nav">...</div>
<div class="content">...</div>
然后将其添加到css:
label { top: 50px; } //whatever position you need
input#lightswitch ~ .content {
background-color: #bdbdbd;
transition: background-color 0.5s ease-in;
}
/*Switched Off*/
input#lightswitch:checked ~ .content {
background-color: #222;
transition: background-color 0.5s ease-in;
}
input#lightswitch:checked ~ .content {
color: white;
transition: color 0.5s ease-in;
}
input#lightswitch:checked ~ .nav {
background-color: #bdbdbd; //whatever color you need
transition: background-color 0.5s ease-in;
}
input#lightswitch:checked ~ .nav .nav_wrapper ul li {
background-color: #bdbdbd;
transition: background-color 0.5s ease-in;
}