整个页面上的标签切换标记

时间:2022-12-30 22:55:17

I am trying to use a label to toggle a checkmark. When you press the label the checkmark is checked but when you press another part of the page the checkmark is also checked which isn't my intention.

我正在尝试使用标签切换复选标记。当您按下标签时,选中复选标记,但是当您按下页面的另一部分时,也会检查复选标记,这不是我的意图。

I don't really get why this is the case. Can you explain it and explain how to fix it?

我真的不明白为什么会这样。你能解释一下并解释如何解决它吗?

header {
  height: 100vh;
  background-size: cover;
  background-position: center;
  margin-bottom: 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  text-transform: uppercase;
  color: black;
}
h1 {
  font-size: 50px;
  letter-spacing: 8px;
}
ul {
  list-style-type: none;
  margin-left: 0px;
  padding-left: 0px;
}
p {
  width: 600px;
  margin: 0 auto 20px;
}
body {
  margin-top: 0px;
  margin-right: 0px;
  margin-bottom: 0px;
  margin-left: 0px
}
.container {
  margin: auto;
  width: 80%;
}
.page-content {
  position: relative;
  z-index: 0;
  transition-duration: 0.4s;
}
.sidebar {
  position: fixed;
  top: 0px;
  left: -180px;
  right: 0;
  bottom: 0px;
  width: 120px;
  padding: 30px;
  background-color: black;
  z-index: 0;
  width: 120px;
  transition-duration: 0.4s;
}
.sidebar a {
  text-decoration: none;
  opacity: 0.8;
  font-family: monospace;
  font-size: 25px;
}
.sidebar li {
  margin-bottom: 15px;
}
.sidebar a:hover {
  opacity: 1;
}
.toggle {
  position: fixed;
  top: 20px;
  right: 0;
  bottom: 0;
  left: 20px;
  z-index: 1;
  color: black;
  transition-duration: 0.4s;
}
#sidebartoggler:checked + .page-wrap .sidebar {
  left: 0px;
}
#sidebartoggler:checked + .page-wrap .toggle {
  left: 200px;
}
#sidebartoggler:checked + .page-wrap .page-content {
  padding-left: 180px;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="description" content="A page about me">
  <meta name="keywords" content="web developer, projects">
  <meta name="author" content="Tristan Trouwen">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">


  <title>hello - Tristan Trouwen</title>


  <!-- own style sheet -->
  <link rel="stylesheet" href="/static/css/style.css">
  <!-- favicon -->
  <link rel='icon' href="/static/assets/favicon.ico">
  <!-- google icons -->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <!-- the icon font -->
  <link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">

</head>

<body>



  <input type="checkbox" id="sidebartoggler" name="" value="">

  <div class="page-wrap">

    <label for="sidebartoggler"><i class="material-icons md-36 toggle">menu</i>
    </label>


    <div class="page-content">


      <header>
        <h1>title</h1>

      </header>

    </div>

    <div class="sidebar">

      <ul>
        <li><a href="/index">home</a>
        </li>
        <li><a href="/shoutbox">shoutbox</a>
        </li>
        <li><a href="/resume">resume</a>
        </li>
        <li><a href="/projects">projects</a>
        </li>
      </ul>

    </div>
  </div>



</body>

</html>

1 个解决方案

#1


1  

Remove .toggle { right: 0; bottom: 0; }

删除.toggle {right:0;底部:0; }

#1


1  

Remove .toggle { right: 0; bottom: 0; }

删除.toggle {right:0;底部:0; }