how to reposition label which sits on top of the checkbox - css

WHen I styled my checkbox, the label sits on top of the checkbox. But I want it to be separated. However due to the css I used, I find it very tricky because both checkbox and label shares the same with and height. Can someone suggest how to manipulate this label alone?
css
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
background: #D9D9D9;
height: 40px;
width: 40px;
border-radius:20px;
display:inline-block;
padding: 0 0 0 0px;
cursor:pointer;
border:1px solid #00AAFF;
}
input[type=checkbox]:checked + label
{
background: #00B0F0;
height: 40px;
width: 40px;
border-radius:20px;
display:inline-block;
padding: 0 0 0 0px;
cursor:pointer;
}
here's the fiddle: http://jsfiddle.net/vxbbfyr0/

#container > div{
-webkit-user-select:none;
}
input[type=checkbox] {
display:none;
}
label span{
background: #D9D9D9;
height: 40px;
width: 40px;
border-radius: 20px;
display:inline-block;
vertical-align: middle;
padding: 0 0 0 0px;
cursor:pointer;
border:1px solid #00AAFF;
}
label input[type=checkbox]:checked + span{
background: #00B0F0;
}
<div id="container">
<div>
<label for="checkbox1">
<input type="checkbox" id="checkbox1" class="item"/>
<span></span>
Label 1
</label>
</div>
<div>
<label for="checkbox2"><input type="checkbox" id="checkbox2" class="item"/>
<span></span>
label 2</label>
</div>
<div>
<label for="checkbox3">
<input type="checkbox" id="checkbox3" class="item"/>
<span></span>
label 3</label>
</div>
</div>

Related

Change color on radio button (default and checked)

I have a question:
I want my radio button at default-mode to have the css:
border-color: #00AD51;
color: #fff;
background-color: #00AD51;
and when the user selects/clicks on another radio button it changes to this css:
border-color: #00AD51;
color: #00AD51;
background-color: #fff;
Is this possible? How can I make specific css on default-mode and checked-mode on radio buttons?
HTML:
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals"><div class="input">
<input id="dog" type="radio" name="Animal" checked>
<label for="dog"><span>Dog</span></label>
</div>
<div class="Animals"><div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>
Link to codepen: https://codepen.io/vicm/pen/QBPQWZ
Here is a snippet where I:
Added the closing </div> in your HTML,
Reorganized your CSS code and tried to remove duplicate styled properties,
Corrected some typo errors (display: inline-blok to display: inline-block, position:relavitve; to position: relative; …),
I added some styling plus comments to make things clear about the different possible states,
Instead of using checked on the "recommended" answer, you can use another custom property, like "recommend", and use it in your CSS to stylize it correctly.
input[type=radio] {
margin-right: 3px;
position: relative;
top: 3px;
}
.Animals {
display: inline-block;
height: 100px;
margin: 10px;
border: 2px solid #003D6A;
border-radius: 3px;
background-color: #fff;
padding: 10px;
text-align: center;
line-height: 20px;
font-family: Helvetica;
font-size: 20px;
}
.Animals .input {
padding-bottom: 0;
}
.Animals input[type=radio] {
opacity: 0;
}
.Animals input[type=radio]+label {
cursor: pointer;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0);
border: 2px solid;
margin: 10px;
height: 100px;
border-radius: 3px;
text-align: center;
font-size: 20px;
font-family: Helvetica;
width: 292px;
/* Default */
border-color: darkblue;
background-color: #fff;
color: darkblue;
}
/* Recommanded */
.Animals input[type=radio][recommand]+label {
border-color: turquoise;
color: turquoise;
}
/* Hover */
.Animals input[type=radio]+label:hover {
border-color: #00AD51;
color: #00AD51;
}
/* Checked */
.Animals input[type=radio]:checked+label {
border-color: #00AD51;
background-color: #00AD51;
color: #fff;
}
.Animals label span {
position: relative;
top: 33%;
}
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals">
<div class="input">
<input id="dog" type="radio" name="Animal" recommand>
<label for="dog"><span>Dog</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
</div>
<div class="Animals">
<div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>
</div>
If you wish to modify something, it should be easier now.
You can use this simple trick.
When user can click or check the radio button
.Animals input[type=radio]:checked + label{border-color: #00AD51;color: #00AD51;background-color: #fff;}
Hope this help.
Let me know further clarification.
input[type=radio]
{
margin-right: 3px;
position: relative;
top: 3px;
}
.Animals
{
border:2px solid #003D6A;
margin:10px;
height:100px;
padding:10px;
border-radius:3px;
text-align:center;
font-size: 20px;
line-height: 20px;
background-color:#fff;
font-family: Helvetica;
display: inline-blok;
}
.Animals{
margin: 0 auto;
}
.Animals input[type=radio] {
opacity: 0;
position:relavitve;
}
.Animals input[type=radio] + label {
cursor: pointer;
text-shadow: 1px 1px 0 rgba(0,0,0,0);
border: 2px solid #003D6A;
margin: 10px;
height: 100px;
border-radius: 3px;
text-align: center;
font-size: 20px;
font-family: Helvetica;
width: 292px;
background-color: #ffffff;
}
.Animals input[type=radio] + label:hover{
border-color: #00AD51;
background-color: #fff;
color: #00AD51;
}
.Animals .input
{
padding-bottom:0;
}
.Animals label span
{
position:relative;
top:33%;
}
.Animals input[type=radio]:checked + label{
border-color: #00AD51;
color: #00AD51;
background-color: #fff;
}
<p><b>What is your favorite animal?</b></p><br />
<div class="Animals"><div class="input">
<input id="dog" type="radio" name="Animal" checked>
<label for="dog"><span>Dog</span></label>
</div>
<div class="Animals"><div class="input">
<input id="cat" type="radio" name="Animal">
<label for="cat"><span>Cat</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Horse" type="radio" name="Animal">
<label for="Horse"><span>Horse</span></label>
</div>
<div class="Animals"><div class="input">
<input id="Cow" type="radio" name="Animal">
<label for="Cow"><span>Cow</span></label>
</div>

input drops down after zooming in and out

Here I made two simple input fields, but when I zoom in and zoom out on the page (Ctrl + Mouse wheel) somehow the input fields change places, input goes down and up, why it is doing this? How to have them at the same place whether I zoom in or out?
body {
width: 870px;
}
#col3 {
width: 400px;
float: left;
/*background-color:#383838;*/
margin: 20px 10px 10px 30px;
}
form {
width: 380px;
margin: auto;
padding: 5px;
border: solid 1px white;
}
fieldset {
margin: auto;
border: solid 1px #E37222;
padding-left: 19px;
padding-top: 15px;
background-color: #EEEEDD;
}
label {
display: block;
width: 70px;
float: left;
margin-left: 10px;
}
span {
margin-left: -16px;
}
legend {
background-color: #E37222;
color: white;
}
input.tt {
outline: 1px solid #909090;
}
.tt {
margin-top: 8px;
}
<div id="col3">
<form>
<fieldset>
<legend>eeeee</legend>
<label for="name">
<span>rrr:</span>
</label>
<input class="tt" type="text" size="34" />
<br />
<label class="tt" for="email">
<span>ttt:</span>
</label>
<input class="tt" type="text" size="34" />
</fieldset>
</form>
</div>
..........................
Remove float:left for <label>
label{
display:block;
width:70px;
margin-left:10px;
}
Try with This
.youclassname{
display:flex;
}
<div class="yourclassname">
<label for="name"><span>rrrrrr rrrrrr:</span></label>
<input class="tt type="text" size="34" />
</div>
Either change your markup a little like that, or use flexbox/grid.
<style>
body{
width:870px;
}
#col3{
width:400px;
float:left;
/*background-color:#383838;*/
margin:20px 10px 10px 30px;
}
form{
width:380px;
margin:auto;
padding:5px;
border:solid 1px white;
}
fieldset{
margin:auto;
border:solid 1px #E37222;
padding-left: 19px;
padding-top: 15px;
background-color: #EEEEDD;
}
label{
display:block;
width: 100%;
}
label div{
padding-right: 5px;
width: 68px;
display: inline-block;
}
legend{
background-color:#E37222;
color:white;
}
input.tt{
outline: 1px solid #909090;
}
.tt{
margin-top:8px;
}
</style>
</head>
<body>
<div id="col3">
<form ">
<fieldset >
<legend>eeeee</legend>
<label for="name"><div>rrr:</div><input class="tt type="text" size="34" /> </label>
<br/>
<label class="tt"for="email"><div>ttt:</div><input class="tt" type="text" size="34" /></label>
</fieldset>
</form>
</div>
</body>

How to put text inside radio button?

I am trying to put a letter inside a radio button (with Materialize framework) like the A and B in this image.
How do I do this?
Here is the customize radio button.
see the comments given in css.
input[type="radio"] {
width: 30px;
height: 30px;
border-radius: 15px;
border: 2px solid #1FBED6;
background-color: white;
-webkit-appearance: none; /*to disable the default appearance of radio button*/
-moz-appearance: none;
}
input[type="radio"]:focus { /*no need, if you don't disable default appearance*/
outline: none; /*to remove the square border on focus*/
}
input[type="radio"]:checked { /*no need, if you don't disable default appearance*/
background-color: #1FBED6;
}
input[type="radio"]:checked ~ span:first-of-type {
color: white;
}
label span:first-of-type {
position: relative;
left: -27px;
font-size: 15px;
color: #1FBED6;
}
label span {
position: relative;
top: -12px;
}
<label>
<input type="radio" name="options"/>
<span>A</span><span>Option A</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>B</span><span>Option B</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>C</span><span>Option C</span>
</label>
<br/>
<label>
<input type="radio" name="options"/>
<span>D</span><span>Option D</span>
</label>
You cannot do that. But instead, you can make something similar using CSS:
label {display: block; padding: 5px; position: relative; padding-left: 20px;}
label input {display: none;}
label span {border: 1px solid #ccc; width: 15px; height: 15px; position: absolute; overflow: hidden; line-height: 1; text-align: center; border-radius: 100%; font-size: 10pt; left: 0; top: 50%; margin-top: -7.5px;}
input:checked + span {background: #ccf; border-color: #ccf;}
<h3>Select One</h3>
<label><input type="radio" name="select" /><span>a</span> Item 1</label>
<label><input type="radio" name="select" /><span>b</span> Item 2</label>
Preview

css for checkbox while hover

I wanna change color for each checkbox while hover.I have four checkbox.I wanna change the color, If I hover the 'all' checkbox it shows red,blue color for 'cold',orange for 'warm' and green for 'Active'.
#ck-button {
margin: 0px;
background-color: #EFEFEF;
border-radius: 4px;
border: 1px solid #D0D0D0;
overflow: auto;
float: left;
}
#ck-button label {
float: left;
width: 4.0em;
}
#ck-button label span {
text-align: center;
padding: 3px 0px;
display: block;
border-radius: 4px;
}
#ck-button label input {
position: absolute;
top: -20px;
}
input:checked +span {
background-color: #911;
color: #fff;
}
#ck-button input:hover #all + span {
background-color: #efE0E0;
}
#ck-button input:hover #o1 + span {
background-color: blue;
}
#ck-button input:hover #o2 + span {
background-color: orange;
}
#ck-button input:hover #o3 + span {
background-color: green;
}
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id=all value="All" checked><span>All</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o1" value="Cold" onclick=handleClick1(this.val);><span class="o1">Cold</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o2" value="Warm" onclick="handleClick1(this.val);"><span>Warm</span>
</label>
</div>
<div id="ck-button">
<label>
<input type="radio" name="sta_choice" id="o3" value="Active" onclick="handleClick1(this.val);"><span>Active</span>
</label>
</div>
In the last four lines use label:hover instead of input:hover. Input is positioned to top and isn't hovered (is outside the label).
#ck-button label:hover #all + span {
background-color:#efE0E0;
}
#ck-button label:hover #o1 + span {
background-color:blue;
}
#ck-button label:hover #o2 + span {
background-color:orange;
}
#ck-button label:hover #o3 + span {
background-color:green;
}
http://jsfiddle.net/3q4uuvum/3/
even as an option
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
ul{
text-align: center;
width: 300px;
margin: 25px auto;
}
ul > li{
display: inline-block;
*display: inline;
zoom: 1;
vertical-align: top;
width: 100px;
height: 100px;
border: 1px solid #ccc;
position: relative;
}
input{
display: none;
}
label{
display: block;
width: 100px;
height: 100px;
}
label:hover{
background: #f7f7f7;
}
input:checked ~ label{
position: absolute; top: 0; left: 0;
width: 100%;
height: 100%;
background: url(http://html5doctor.com/wp-content/themes/html5doctor2/images/HTML5_Badge_64.png) no-repeat center center;
border: 1px solid #000;
}
<ul>
<li>
<input type="checkbox" id="c1" name="checkbox" />
<label for="c1"></label>
<li>
<input type="checkbox" id="c2" name="checkbox" />
<label for="c2"></label>
<li>
<input type="checkbox" id="c3" name="checkbox" />
<label for="c3"></label>
<li>
<input type="checkbox" id="c4" name="checkbox" checked />
<label for="c4"></label>
<li>
<input type="checkbox" id="c5" name="checkbox" />
<label for="c5"></label>
<li>
<input type="checkbox" id="c6" name="checkbox" />
<label for="c6"></label>
<li>
<input type="checkbox" id="c7" name="checkbox" />
<label for="c7"></label>
<li>
<input type="checkbox" id="c8" name="checkbox" />
<label for="c8"></label>
<li>
<input type="checkbox" id="c9" name="checkbox" />
<label for="c9"></label>
</ul>
I couldn't find online how to display different colors for hover depending if the box is checked, but after tirelessly tweaking the code I figured it out.
.ck-button-class:hover input:checked + span {
background-color: green;
}
This is assuming you assigned the class to these buttons, <div id="ck-button" class="ck-button-class">.

Middle the label for text area input in css3

html
div class="main">
<div class="one">
<div class="register">
<h3>Create your account</h3>
<form id="reg-form">
<div>
<div>
<label for="username">Username</label>
<input type="text" id="username" spellcheck="false" placeholder="User Name" />
</div>
<div>
<label for="password">Password</label>
<input type="password" id="password" />
</div>
<div>
<label></label>
<input type="submit" value="Shop Login" id="create-account" class="button"/>
</div>
</form>
</div>
</div></div>
<div class="two">
<div class="register">
<h3>Create your account</h3>
<form id="reg-form1">
<div>
<label for="name1">Name</label>
<input type="text" id="name1" spellcheck="false" placeholder="Enter Your Name"/>
</div>
<div>
<label for="email1">Email</label>
<input type="text" id="email1" spellcheck="false" placeholder="mymail#mail.com"/>
</div>
<div>
<label for="username1">Username</label>
<input type="text" id="username1" spellcheck="false" placeholder="User Name" />
</div>
<div class="textarea">
<label for="address">Shipping Address</label>
<textarea name="address"cols="35" rows="4"></textarea>
</div>
<div>
<label for="password1">Password</label>
<input type="password" id="password1" />
</div>
<div>
<label for="password-again1">Password Again</label>
<input type="password" id="password-again1" />
</div>
<div>
<label></label>
<input type="submit" value="Create Account" id="create-account1" class="button"/>
</div>
</form>
</div>
</div>
</div>
CSS
.main > div {
display: inline-block;
width: 49%;
margin-top: 20px;
}
.two .register {
border: none;
}
.two .register h3 {
border-bottom-color: #909090;
}
.two .register .sep {
border-color: #909090;
}
.register {
width: 400px;
margin: 10px auto;
padding: 10px;
border: 7px solid #ADD8E6;
border-radius: 10px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #444;
background-color: #f0f0f0;
box-shadow: 0 0 20px 0 #000000;
}
.register h3 {
margin: 0 15px 20px;
border-bottom: 2px solid #72b372;
padding: 5px 10px 5px 0;
font-size: 1.1em;
}
.register div {
margin: 0 0 15px 0;
border: none;
}
.register label {
display: inline-block;
width: 25%;
text-align: right;
margin: 10px;
}
.register input[type=text], .register input[type=password] {
width: 65%;
font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Sans-Serif;
padding: 5px;
font-size: 0.9em;
border-radius: 5px;
background: rgba(0, 0, 0, 0.07);
}
.register input[type=text]:focus, .register input[type=password]:focus {
background: #FFFFFF;
}
.register textarea{
width: 65%;
font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Sans-Serif;
padding: 5px;
font-size: 0.9em;
border-radius: 5px;
background: rgba(0, 0, 0, 0.07);
}
.register .button {
font-size: 1em;
border-radius: 8px;
padding: 10px;
border: 1px solid #ADD8E6;
box-shadow: 0 1px 0 0 #05B8CC inset;
background: #05B8CC;
background: -webkit-linear-gradient(#ADD8E6, #05B8CC);
background: -moz-linear-gradient(#ADD8E6, #05B8CC);
background: -o-linear-gradient(#ADD8E6, #05B8CC);
background: linear-gradient(#ADD8E6, #05B8CC);
}
.register .button:hover {
background: #51db1c;
background: -webkit-linear-gradient(#51db1c, #6ba061);
background: -moz-linear-gradient(#51db1c, #6ba061);
background: -o-linear-gradient(#51db1c, #6ba061);
background: linear-gradient(#51db1c, #6ba061);
}
.register .sep {
border: 1px solid #72b372;
position: relative;
margin: 35px 20px;
}
.register .or {
position: absolute;
width: 50px;
left: 50%;
background: #f0f0f0;
text-align: center;
margin: -10px 0 0 -25px;
line-height: 20px;
}
.register .connect {
width: 400px;
margin: 0 auto;
text-align: center;
}
div.one {position: relative; top: -165px}
The css is working fine, except that the label for text area is displaying at bottom.
How can I display the text area label at center position of the text area ?? Thanks in advance.
Here is a link to Fiddle Demo
Add the following css rule:
div.textarea > * {
vertical-align:middle
}
Add following css in your code
.register label, .register textarea{
vertical-align:middle
}

Resources