Checboxex右对齐,但在下面显示另一个复选框

时间:2019-03-16 11:06:43

标签: html css

大家好。我有一个小问题,我希望课程偏好设置的复选框位于中间,而不是与底部的其他文本框在同一位置。我希望它成为页面的中心。就像在学术中字母D之后的某个地方。无论我尝试什么,checboxs都将限制在右侧。我试图将其浮动,但它不起作用。

body {
background: url(ewp.jpg);
background-size: cover;
}

.firstform {
order-radius: 5px;
background: green;
padding: 20px;
width: 550px;
margin: auto;
color: #fff;
font-size: 16px;
font-family: verdana;
margin-top: 100px;
opacity: 0.8;
}

.firstform h1 {
text-align: center;
margin: 0;
padding: 0;
}

.firstform input,
select {
width: 50%;
padding: 12px 20px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
background: black;
color: white;
opacity: 0.9;
/* removed margin-left */
}

.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 24em;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
 user-select: none;
}

.containertwo {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

/* Hide browser default radio button */

.container input {
 position: absolute;
 opacity: 0;
 cursor: pointer;  
}

/* Create custom radio button */

.checkmark {
 position: absolute;
 top: 0;
 left: 0;
 height: 15px;
 width: 15px;
 background-color: #eee;
 border-radius: 50%;
 }

 /* On mouse-over, add a grey background color */

 .container:hover input~.checkmark {
 background-color: #ccc;
 }

/* When the radio button is checked, add a blue background */

 .container input:checked~.checkmark {
 background-color: #2196f3;
 }

/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
content: "";
position: absolute;
display: none;
}

/* Show the indicator (dot/circle) when checked */

.container input:checked~.checkmark:after {
display: block;
}

/* Style the indicator (dot/circle) */

.container .checkmark:after {
 top: 6px;
 left: 6px;
 width: 4px;
 height: 4px;
border-radius: 50%;
background: white;
}

.buttonHolder {
display: block;
margin: 0 auto;
}

.firstform input[type="submit"]:hover {
background: #45a049;
transparent: 0.6s;
}

.firstform input[type="reset"]:hover {
 background: #45a059;
 transparent: 0.6s;
 }

label > span, p > span {
width: 50%;
display: inline-block;
} 

这是html代码。

<!DOCTYPE HTML>
<html>
<head>
<title>Register Form</title>
<link rel="stylesheet" type="text/css" href="report.css">

</head>
<body>
<form action="Form2.php" method="POST">

 <div class="firstform">

        <h1>COURSE PREFERENCE</h1>
            <div class="outer-container">
         <p><label class="container">Information Technology
         <input type="checkbox" name="course" value = "Information Technology">
         <span class="checkmark"></span></label></p>

         <p><label class="container">Management
         <input type="checkbox" name="course" value =  "Management">
         <span class="checkmark"></span></label></p>

         <p><label class="container">Business Administration
         <input type="checkbox" name="course" value = "Business Administration">
         <span class="checkmark"></span></label></p>

         <p><label class="container">Culinary Arts
         <input type="checkbox" name="course" value = "Culinary Arts">
         <span class="checkmark"></span></label></p>

        <p><label class="container">Early Childhood Education
        <input type="checkbox" name="course" value = "Early Childhood Education">
        <span class="checkmark"></span></label></p>

        <p>
        <label class="container">
        Hotel Management<input type="checkbox" name="course"value = "Hotel Management">
        <span class="checkmark"></span></label></p>

    <h1>ACADEMIC QUALIFICATION</h1>

    <p><label><span>Higher Qualification</span><select name="qualification">
            <option selected>SPM</option>
            <option>STPM</option>
            <option>O-Level</option>
            <option>Foundation</option>
            <option>A-Level</option>
            <option>others</option>
        </select>
    </label>
   </p>

   <p><label><span>Instituiton:</span><input type="text" name="address" size="30" /></label></p>

   <p><label><span>Country:</span><select name="country">
            <option selected>Malaysia</option>
            <option>International</option>
        </select>
    </label>
   </p>

    <p>
       <label><span>Date commenced </span></label><input type="date" name="date_commenced">&emsp;&emsp;
    </p>

    <p>
       <label><span>Date completed</span></label><input type="date" name="date_complete">&emsp;&emsp;
    </p>


<div class="buttonHolder">
  <input type="submit" name="Insert"><input type="reset" name="Clear">
</div>

 </form>
</div>

</body>
</html>

body {
  background: url(ewp.jpg);
  background-size: cover;
}

.firstform {
  order-radius: 5px;
  background: green;
  padding: 20px;
  width: 550px;
  margin: auto;
  color: #fff;
  font-size: 16px;
  font-family: verdana;
  margin-top: 100px;
  opacity: 0.8;
}

.firstform h1 {
  text-align: center;
  margin: 0;
  padding: 0;
}

.firstform input,
select {
  width: 50%;
  padding: 12px 20px;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 18px;
  background: black;
  color: white;
  opacity: 0.9;
  /* removed margin-left */
}

.container {
  display: block;
  position: relative;
  padding-left: 25px;
  margin-bottom: 12px;
  margin-left: 24em;
  cursor: pointer;
  font-size: 12px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}


/* Hide browser default radio button */

.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}


/* Create custom radio button */

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 15px;
  width: 15px;
  background-color: #eee;
  border-radius: 50%;
}


/* On mouse-over, add a grey background color */

.container:hover input~.checkmark {
  background-color: #ccc;
}


/* When the radio button is checked, add a blue background */

.container input:checked~.checkmark {
  background-color: #2196f3;
}


/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}


/* Show the indicator (dot/circle) when checked */

.container input:checked~.checkmark:after {
  display: block;
}


/* Style the indicator (dot/circle) */

.container .checkmark:after {
  top: 6px;
  left: 6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: white;
}

.buttonHolder {
  display: block;
  margin: 0 auto;
}

.firstform input[type="submit"]:hover {
  background: #45a049;
  transparent: 0.6s;
}

.firstform input[type="reset"]:hover {
  background: #45a059;
  transparent: 0.6s;
}

label>span,
p>span {
  width: 50%;
  display: inline-block;
}
<form action="Form2.php" method="POST">

  <div class="firstform">
    <h1>COURSE PREFERENCE</h1>

    <p><label class="containertwo">Information Technology
         <input type="checkbox" name="course" value = "Information Technology">
         <span class="checkmark"></span></label></p>

    <p><label class="containertwo">Management
         <input type="checkbox" name="course" value =  "Management">
         <span class="checkmark"></span></label></p>

    <p><label class="containertwo">Business Administration
         <input type="checkbox" name="course" value = "Business Administration">
         <span class="checkmark"></span></label></p>

    <p><label class="containertwo">Culinary Arts
         <input type="checkbox" name="course" value = "Culinary Arts">
         <span class="checkmark"></span></label></p>

    <p><label class="containertwo">Early Childhood Education
        <input type="checkbox" name="course" value = "Early Childhood Education">
        <span class="checkmark"></span></label></p>

    <p>
      <label class="containertwo">
        Hotel Management<input type="checkbox" name="course"value = "Hotel Management">
        <span class="checkmark"></span></label></p>
</div>
    <h1>ACADEMIC QUALIFICATION</h1>

    <p><label><span>Higher Qualification</span><select name="qualification">
            <option selected>SPM</option>
            <option>STPM</option>
            <option>O-Level</option>
            <option>Foundation</option>
            <option>A-Level</option>
            <option>others</option>
        </select>
    </label>
    </p>

    <p><label><span>Instituiton:</span><input type="text" name="address" size="30" /></label></p>

    <p><label><span>Country:</span><select name="country">
            <option selected>Malaysia</option>
            <option>International</option>
        </select>
    </label>
    </p>

    <p>
      <label><span>Date commenced </span></label><input type="date" name="date_commenced">&emsp;&emsp;
    </p>

    <p>
      <label><span>Date completed</span></label><input type="date" name="date_complete">&emsp;&emsp;
    </p>


    <div class="buttonHolder">
      <input type="submit" name="Insert"><input type="reset" name="Clear">
    </div>

</form>
</div>

2 个答案:

答案 0 :(得分:1)

有几种方法可以使用CSS将元素居中,一种用于将一组元素居中的方法是将所有这些元素封装在div等容器标签中并放置该容器标签。

因此,将所有复选框标签括在 div 标签内,并带有一个类(例如),说“ 外部容器”,并为其提供以下CSS:

.outer-container {
  display: inline-block;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

并从您的.container css中删除margin-left

我在下面的代码段中做了这些更改,请尝试使用此方法。

body {
  background: url(ewp.jpg);
  background-size: cover;
}

.firstform {
  border-radius: 5px;
  background: green;
  padding: 20px;
  width: 550px;
  margin: auto;
  color: #fff;
  font-size: 16px;
  font-family: verdana;
  margin-top: 100px;
  opacity: 0.8;
}

.firstform h1 {
  text-align: center;
  margin: 0;
  padding: 0;
}

.firstform input,
select {
  width: 50%;
  padding: 12px 20px;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 18px;
  background: black;
  color: white;
  opacity: 0.9;
  /* removed margin-left */
}

.outer-container {
  display: inline-block;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

.container {
  display: block;
  position: relative;
  padding-left: 25px;
  margin-bottom: 12px;
  /* margin-left: 24em; */
  cursor: pointer;
  font-size: 12px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}


/* Hide browser default radio button */

.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}


/* Create custom radio button */

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 15px;
  width: 15px;
  background-color: #eee;
  border-radius: 50%;
}


/* On mouse-over, add a grey background color */

.container:hover input~.checkmark {
  background-color: #ccc;
}


/* When the radio button is checked, add a blue background */

.container input:checked~.checkmark {
  background-color: #2196f3;
}


/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}


/* Show the indicator (dot/circle) when checked */

.container input:checked~.checkmark:after {
  display: block;
}


/* Style the indicator (dot/circle) */

.container .checkmark:after {
  top: 6px;
  left: 6px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: white;
}

.buttonHolder {
  display: block;
  margin: 0 auto;
}

.firstform input[type="submit"]:hover {
  background: #45a049;
  transparent: 0.6s;
}

.firstform input[type="reset"]:hover {
  background: #45a059;
  transparent: 0.6s;
}

label>span,
p>span {
  width: 50%;
  display: inline-block;
}
<form action="Form2.php" method="POST">

  <div class="firstform">
    <h1>COURSE PREFERENCE</h1>
    <div class="outer-container">

      <p><label class="container">Information Technology
         <input type="checkbox" name="course" value = "Information Technology">
         <span class="checkmark"></span></label></p>

      <p><label class="container">Management
         <input type="checkbox" name="course" value =  "Management">
         <span class="checkmark"></span></label></p>

      <p><label class="container">Business Administration
         <input type="checkbox" name="course" value = "Business Administration">
         <span class="checkmark"></span></label></p>

      <p><label class="container">Culinary Arts
         <input type="checkbox" name="course" value = "Culinary Arts">
         <span class="checkmark"></span></label></p>

      <p><label class="container">Early Childhood Education
        <input type="checkbox" name="course" value = "Early Childhood Education">
        <span class="checkmark"></span></label></p>

      <p>
        <label class="container">
        Hotel Management<input type="checkbox" name="course"value = "Hotel Management">
        <span class="checkmark"></span></label></p>

    </div>

    <h1>ACADEMIC QUALIFICATION</h1>

    <p><label><span>Higher Qualification</span><select name="qualification">
            <option selected>SPM</option>
            <option>STPM</option>
            <option>O-Level</option>
            <option>Foundation</option>
            <option>A-Level</option>
            <option>others</option>
        </select>
    </label>
    </p>

    <p><label><span>Instituiton:</span><input type="text" name="address" size="30" /></label></p>

    <p><label><span>Country:</span><select name="country">
            <option selected>Malaysia</option>
            <option>International</option>
        </select>
    </label>
    </p>

    <p>
      <label><span>Date commenced </span></label><input type="date" name="date_commenced">&emsp;&emsp;
    </p>

    <p>
      <label><span>Date completed</span></label><input type="date" name="date_complete">&emsp;&emsp;
    </p>


    <div class="buttonHolder">
      <input type="submit" name="Insert"><input type="reset" name="Clear">
    </div>
  </div>
</form>

答案 1 :(得分:0)

对css容器类进行一些更改,即保证金剩余值。

.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 15em;    <-----Change Value Here
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
 user-select: none;
}