HTML,CSS和CheckBoxes

时间:2015-06-09 21:50:13

标签: html css checkbox

我正在尝试使用css渲染一些html复选框。

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

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

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

{{1}}

1 个答案:

答案 0 :(得分:1)

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