我如何使用css和html来制作复选框?

kr98yfug  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(111)

我想在每个主题矩形的右边做一个复选标记框。我想让这个框的宽度大约为一英寸,颜色为白色,当它被单击时显示为蓝色。
我怎样才能在html和css中做出正确的改变来解决这个问题呢?我做了一个复选框,但是我很难用css来操作复选框。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Select a Topic</title>
    <link rel="stylesheet" href="style_landingpage.css">
  </head>
  <body>
    <h1>Select a Topic</h1>
    <label>
      <input class="checkboxid" type="checkbox" name="topic">
      <a href="game.html?topic=movies">
        <button>Movies</button>
      </a>
    </label>
    <label>
      <input for="checkboxid1" class="checkboxid"  type="checkbox" name="topic">
      <a href="game.html?topic=music">
        <button>Music</button>
      </a>
    </label>
    <label>
      <input class="checkboxid"  type="checkbox" name="topic">
      <a href="game.html?topic=countries">
        <button>Countries</button>
      </a>
    </label>
    <a href="game.html?topic=countries">
      <button class="play-btn">Play</button>
    </a>
  </body>
</html>
body {
    background-color: black;
      color: white;
    text-align: center;
    font-family: 'Times New Roman', Times, serif;
  }

button {
  display: block;
  width: 2in;
  height: 1in;
  margin: 20px auto;
  background-color: lightblue;
  border: none;
  border-radius: 5px;
  color: black;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.play-btn {
  width: 2in;
  height: 50px;
  background-color: #006400;
  color: #fff;
  border: none;
  padding: 5px;
  font-size: 18px;
  border-radius: 5px;
  cursor: pointer;
}

input {
  padding: 3px;
  box-shadow: 3px 3px 5px white;
  background-color: #006400 !important;
  color: white;
  font-size: 14px;
  font-weight: 600;
  width: 100px;
}

#checkboxid1 {
  display: block;
}
2guxujil

2guxujil1#

第一:标签中的put按钮标签错误。
同样,你可以使用display:flex把复选框位置水平放置在主题矩形旁边。

label{
  display:flex;
  align-items:center;
  margin-top:5px;
}
a {
  display:flex;
      align-items: center;
    justify-content: center;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
  width: 2in;
  height: 1in;
  background-color: lightblue;
  border: none;
  border-radius: 5px;
  color: black;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
input {
   accent-color: blue;
  padding: 10px;
  display: block;
  width: 1in;
  height: 1in;
 cursor:pointer;
  
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Select a Topic</title>
    <link rel="stylesheet" href="style_landingpage.css">
  </head>
  <body>
    <h1>Select a Topic</h1>
    <label>
     
      <a href="game.html?topic=movies">
        Movies
      </a>
       <input class="checkboxid" type="checkbox" name="topic">
    </label>
    <label>
      <a href="game.html?topic=music">
        Music
      </a>
      <input for="checkboxid1" class="checkboxid"  type="checkbox" name="topic">
      
    </label>
    <label>
      
      <a href="game.html?topic=countries">
        Countries
      </a>
      <input class="checkboxid"  type="checkbox" name="topic">
    </label>
    <label>
    <a href="game.html?topic=countries">
      Play
    </a>
    </label>
  </body>
</html>

相关问题