HTML、CSS 和复选框

HTML, CSS and CheckBoxes

我正在尝试使用 css 呈现一些 html 复选框。

我希望它看起来像这样(所有复选框都在一条水平线上并标记):

<html>

<body>

  <center>

    <form id="pluginsForm">
      <input type="checkbox" value="Button_1" name="plugin">Button_1
      <input checked type="checkbox" value="Button_2" name="plugin">Button_2
      <input type="checkbox" value="Button_3" name="plugin">Button_3
      <input checked type="checkbox" value="Button_4" name="plugin">Button_4
      <br>
      <br>
      <input type="BUTTON" value="Go" onclick="alert('GO')">
    </form>

  </center>

</body>

</html>

但是使用一些花哨的 css 东西,我似乎无法让它工作。文本显示不正确,它是多行的,并且在选择一个按钮时右侧按钮未显示为已单击。 (基于 here 中的示例)

<html>

<body>

<head>

<style>

body {
 background: #555;
}

h1 {
 color: #eee;
 font: 30px Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 text-shadow: 0px 1px black;
 text-align: center;
 margin-bottom: 50px;
}

input[type=checkbox] {
 visibility: hidden;
}
/* SQUARED ONE */
.squaredOne {
 width: 28px;
 height: 28px;
 background: #fcfff4;

 background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
 background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
 background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
 background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
 background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
 margin: 20px auto;
 -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
 -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
 box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
 position: relative;
}

.squaredOne label {
 cursor: pointer;
 position: absolute;
 width: 20px;
 height: 20px;
 left: 4px;
 top: 4px;

 -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);
 -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);
 box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);

 background: -webkit-linear-gradient(top, #222 0%, #45484d 100%);
 background: -moz-linear-gradient(top, #222 0%, #45484d 100%);
 background: -o-linear-gradient(top, #222 0%, #45484d 100%);
 background: -ms-linear-gradient(top, #222 0%, #45484d 100%);
 background: linear-gradient(top, #222 0%, #45484d 100%);
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#222', endColorstr='#45484d',GradientType=0 );
}

.squaredOne label:after {
 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
 filter: alpha(opacity=0);
 opacity: 0;
 content: '';
 position: absolute;
 width: 16px;
 height: 16px;
 background: #00bf00;

 background: -webkit-linear-gradient(top, #00bf00 0%, #009400 100%);
 background: -moz-linear-gradient(top, #00bf00 0%, #009400 100%);
 background: -o-linear-gradient(top, #00bf00 0%, #009400 100%);
 background: -ms-linear-gradient(top, #00bf00 0%, #009400 100%);
 background: linear-gradient(top, #00bf00 0%, #009400 100%);

 top: 2px;
 left: 2px;

 -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
 -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
 box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
}

.squaredOne label:hover::after {
 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
 filter: alpha(opacity=30);
 opacity: 0.3;
}

.squaredOne input[type=checkbox]:checked + label:after {
 -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
 filter: alpha(opacity=100);
 opacity: 1;
}

</style>

</head>

 <center>

      <form id="pluginsForm" >

  <div class="squaredOne">
   <input type="checkbox" value="Button_1" id="squaredOne" name="check" />
   <label for="squaredOne">Button_1</label>
  </div>
  <div class="squaredOne">
   <input checked type="checkbox" value="Button_2" id="squaredOne" name="check" />
   <label for="squaredOne">Button_2</label>
  </div>
  <div class="squaredOne">
   <input type="checkbox" value="Button_3" id="squaredOne" name="check" />
   <label for="squaredOne">Button_3</label>
  </div>
  <div class="squaredOne">
   <input checked type="checkbox" value="Button_4" id="squaredOne" name="check" />
   <label for="squaredOne">Button_4</label>
  </div>
  <br>
  <br>
        <input type="BUTTON" value="Go" onclick="alert('GO')">
      </form>

   </center>

 </body>

</html>

HTML:

<center>
    <form id="pluginsForm">
        <div class="squaredOne">
            <input type="checkbox" value="Button_1" id="squaredOne" name="check" />
            <label for="squaredOne">Button_1</label>
        </div>
        <div class="squaredOne">
            <input checked="checked" type="checkbox" value="Button_2" id="squaredTwo" name="check" />
            <label for="squaredTwo">Button_2</label>
        </div>
        <div class="squaredOne">
            <input type="checkbox" value="Button_3" id="squaredThree" name="check" />
            <label for="squaredThree">Button_3</label>
        </div>
        <div class="squaredOne">
            <input checked="checked" type="checkbox" value="Button_4" id="squaredFour" name="check" />
            <label for="squaredFour">Button_4</label>
        </div>
        <br/>
        <br/>
            <input type="BUTTON" value="Go" onclick="alert('GO')" />
    </form>
</center>   

CSS:

body {
    background: #555;
}
h1 {
    color: #eee;
    font: 30px Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-shadow: 0px 1px black;
    text-align: center;
    margin-bottom: 50px;
}
input[type=checkbox] {
    visibility: hidden;
}
/* SQUARED ONE */
 .squaredOne {
      width: 28px;
  height: 28px;
  display: inline-block;
  background: #fcfff4;
  background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfff4', endColorstr='#b3bead', GradientType=0);
  margin: 20px auto;
    margin-right:70px;
  -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  position: relative;
}
.squaredOne label {
    cursor: pointer;
  position: absolute;
  width: 20px;
  height: 20px;
  left: 4px;
  top: 4px;
    padding-left:30px;
}
.squaredOne label:after {
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
  opacity: 0;
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #00bf00;
  background: -webkit-linear-gradient(top, #00bf00 0%, #009400 100%);
  background: -moz-linear-gradient(top, #00bf00 0%, #009400 100%);
  background: -o-linear-gradient(top, #00bf00 0%, #009400 100%);
  background: -ms-linear-gradient(top, #00bf00 0%, #009400 100%);
  background: linear-gradient(top, #00bf00 0%, #009400 100%);
  top: 0px;
  left: 0px;
  -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
  box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
    border:2px solid #333;
}
.squaredOne input[type=checkbox]:checked + label:after {
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    filter: alpha(opacity=100);
    opacity: 1;
}   

JSFiddle