如何在复选框中使用 css

用户10871279

正如你在这张图片上看到的: 我的期望

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

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>

但正如你所看到的,我没有以正确的方式做这件事。有人可以帮助我或解释我如何将我的元素放在图片上吗?(标题部分已完成)

丹尼尔·本特

使用 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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章