如何将CSS用于复选框

时间:2019-01-13 14:36:38

标签: html css

因此您可以在这张图片上看到:my expectation

我想像上面那样进行页面设计,但是我不能将复选框放置在图片上(居中,在正确的时间下方,在空格上方) 目前我在这里:

body {
    background-color: gray;
}
#head {
  padding-top: 20px;
  text-align:center;
  display:block;
}
#container {
  background-color: #1b345e;;
}
h2 {
    text-align: center;
    font-family: Arial, Helvetica, sans-serif;
    background-color: #1b345e;
    color: white;
}
.topnav {
    position: relative;
    background-color: #333;
    overflow: hidden;
  }

  /* Style the links inside the navigation bar */
  .topnav a {
    float: left;
    color: #f2f2f2;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
  }

  /* Change the color of links on hover */
  .topnav a:hover {
    background-color: #ddd;
    color: black;
  }

  /* Add a color to the active/current link */
  .topnav a.active {
    background-color: #4CAF50;
    color: white;
  }

  /* Centered section inside the top navigation */
  .topnav-centered a {
    float: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Right-aligned section inside the top navigation */
  .topnav-right {
    float: right;
  }
  input {
    margin-left: 49%;
    width: 30px;
    height: 30px;
  }
  .checkboxes{
    display: inline;
  }

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Piarista Kollégium - Stúdiumi jelentkezés</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <script src="main.js"></script>
</head>
<body>
<div id="container">
<div class="topnav">

<div class="topnav-centered">
  <a href="#home" class="active">Jelentkezés</a>
</div>

<a href="#news">Frissítések</a>

<div class="topnav-right">
  <a href="#search">Bejelentkezés</a>
</div>
</div>
<div id="head">
    <img src="logo.png">
</div>
<h2>Üdvözöllek, XY!</h2>
</div>

<div class="checkboxes">
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
      <div>
        <h4>14:30-15:15</h4>
        <input type="checkbox">
      </div>
</div>
</body>
</html>

但是正如您所看到的,我做的方式不正确。有人可以帮助我或向我解释如何将我的元素放置在图片上吗? (标题部分完成了)

1 个答案:

答案 0 :(得分:1)

使用flexbox将元素居中,并使用justify-content: center对齐它们。

.checkboxes {
   display: flex;
   flex-wrap: wrap;
   width: 100%;
   justify-content: center;
 }

.checkboxes div {
  text-align: center;
  margin: 0 10px;
}

这是一个有效的示例:https://codepen.io/dobladov/pen/pqqypY