HTML
<div class="select">
<div>
<label for="kitty" class="kitty-label kitty-label-1 l-center">
</label>
<input type="checkbox" name="cats" value="1">
<label>Kitty One</label>
</div>
<div class="cly-pam" style="width:50%; float: left">
<label for="kitty" class="kitty-label kitty-label-2 l-center">
</label>
<input type="checkbox" name="cats" value="2">
<label>Kitty Two</label>
</div>
</div>
<div>
css
label{
cursor: pointer;
}
.kitty-label{
position: relative;
width: 100%;
&:hover,
&:focus,
&:active{
border-radius: 6px solid #fff;
}
}
.kitty-label-1{
display: inline-block;
background: url(../img/kitty1.png) no-repeat 0 0;
height: 142px;
width: 142px;
}
.kitty-label-2{
display: inline-block;
background: url(../img/kitty2.png) no-repeat 0 0;
height: 144px;
width: 144px;
}
.select input[type="checkbox"]{
display: none;
&:checked + label:before{
background: url(../img/tick.png) no-repeat;
}
}
The labels would have background image but the issue is that when focus, active or hover, the border-radius does not appear behind the images. Also the kitty images do not have border-radius edges. Wonder if should have image in circle shape or css3 can do that?
Also checkbox seems not to show the tick or anything. Tried to click on label (as in kitty image), tick doesn't appear?
Not sure where I might go wrong. Help will be very much appreciated.
Updated
<div>
<input type="radio" name="type" value="designer" id="designer">
<label for="designer" id="designer" class="inline-block testsign" style="background: url(../img/face.png) no-repeat center;">
</label></div>
CSS
.testsign{
width: 170px;
height: 170px;
border-radius: 100%;
&:hover,
&:focus,
&:active{
border: 15px solid #f3f3f3;
}
}
// [type="radio"]:not(:checked),
// [type="radio"]:checked {
// visibility: hidden;
input[type="radio"]:checked + label:after {
content:"";
display: block;
position: absolute;
height: 60px;
width: 60px;
background: #f0f1f1 url(../img/tick.png) no-repeat center center;
border-radius: 100%;
border: 10px solid #fff;
}
Attempted the example from #misterMan
Couldn't get the label:after to be positioned at the right bottom - tried top and left to position the tick circle, but the problem is that when checked, it will appear in the position which followed top and left. So if check extra element or image, tick circle will appear in the same place which is not right. Removed the top and left. There is no way to have tick circle positioned in right bottom appearing in each label whenever radio is checked?
Also another problem is that when border radius on the label is hovered on background image, and if checked radio, the tick circle (label:after) will appear, the tick circle will be "jumpy" whenever hovered on label. How to stop the jump? I tried to add absolute center and position relative but the labels will be out of the container.
Help or insight will be appreciated.
I love this type of stuff so I made this for you, if you are still looking for a solution. I have added the images with <img> as they are not decoration, they are primary content :)
It's nice and simple, and I think does what you want. Let me know!
Updated
Have an updated fiddle!
HTML
<form>
<input type="checkbox" id="pic1" />
<label for="pic1">
<img src="http://www.placehold.it/200" />
</label>
<input type="checkbox" id="pic2" />
<label for="pic2">
<img src="http://www.placehold.it/200" />
</label>
</form>
CSS
body {
margin: 0;
}
input[type=checkbox] {
display: none;
}
label {
position: relative;
display: block;
width: 200px;
cursor: pointer;
float: left;
margin: 10px 0 10px 10px;
}
input[type=checkbox] + label img:hover {
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
}
input[type=checkbox]:checked + label img {
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
}
input[type=checkbox]:checked + label img:hover {
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
}
input[type=checkbox]:checked + label:after {
content:"";
display: block;
position: absolute;
bottom: 10px;
right: 10px;
height: 50px;
width: 50px;
background: url(http://i.imgur.com/i7379jf.png) no-repeat right bottom;
background-size: 50px;
}
input[type=checkbox]:checked + label:hover:after {
}
Related
I used a radio button in my simple project. The radio button looks good with a blue color background when selected. But while running the same code using Edge and Firefox, the background color is black.
I heard that the radio button style is Browser specific. Is this true?
And is there any possibility to change the style without custom radio buttons?
If a custom radio button is the only option, then how do you render it the same as in Google Chrome?
Radio Button visible in Chrome
Radio Button visible in Firefox and Edge
I recreated the chrome radio button with custom css and added a blue background instead of gray. It shows up the same on chrome, firefox, and edge. You might want to do some tweaking of the css to fit your size needs though.
Here is the code
HTML
div class="radio-item">
<input type="radio" id="ritema" name="ritem" value="ropt1">
<label for="ritema">Option 1</label>
</div>
<div class="radio-item">
<input type="radio" id="ritemb" name="ritem" value="ropt2">
<label for="ritemb">Option 2</label>
</div>
CSS
.radio-item {
display: inline-block;
position: relative;
padding: 0 6px;
margin: 10px 0 0;
}
.radio-item input[type='radio'] {
display: none;
}
.radio-item label {
color: black;
font-weight: normal;
}
.radio-item label:before {
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin: 0 5px 0 0;
width: 20px;
height: 20px;
border-radius: 11px;
border: 2px solid gray;
background-color: transparent;
}
.radio-item input[type=radio]:checked + label:after {
border-radius: 11px;
width: 12px;
height: 12px;
position: absolute;
top: 11px;
left: 12px;
content: " ";
display: block;
background: blue;
background-color: blue;
}
Well, my HTML looks like this, when I hover over the image the two checkboxes with a black background should be visible.
<img class='itemImage'/>
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
My CSS
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none; }
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px; }
.itemImage:hover ~ .hoverDisplay {
display: block; }
It works fine when I hover on the image, the two checkboxes are visible, the problem starts when I hover on the checkboxes it starts to flicker
I am not able to figure out the false scenario here.
When I move my cursor to the black are which is hoverDisplay class it starts to flicker and I am not able to check any checkboxes. While moving my
Simply because you will loss the hover when you want to use the input as you are no more hovering the image but another element which is a sibling. To avoid this add another property to keep the display:block state:
.itemImage:hover ~ .hoverDisplay,
.hoverDisplay:hover {
display: block;
}
The problem is that you show the checkboxes when you hover over the image. And then when you hover the checkboxes ( because they are not inside the image ( they are impossible to be) ) you hover out the image and css tries to hide them. But checkboxes are on top of the image, so the flickering happens.
You basically hover in and out the image in the same time.
One solution would be to wrap the img and checkboxes in a div and show the checkboxes when you hover over the div not just the img.
.img-container {
position:relative;
width:350px;
}
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none;
}
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px;
}
.img-container:hover .hoverDisplay {
display: block;
}
<div class="img-container">
<img class="itemImage" src="http://via.placeholder.com/350x150">
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
</div>
I had a text field where on mouse hover I need to get some kind of tool tip which I created using some css and its fine.But the issue here is I need that only to some particular text fields but not for all.
How can I do this.
Can someone help me here
Please find the jsfiddle ,right now getting tool tip for both textfields..But need only for one.
http://fiddle.jshell.net/CvtLq/203/
Thanks
Thanks for the answers..Im adding some more where Iam getting the issue..
I had another text field where it had date picker.Now because of that css,even the date picker is getting that tooltip.
<div class="col-lg-4">
<input class="form-control" type="datetime" date-time auto-close="true" view="date" min-view="date" maxlength="10" format="dd/MM/yyyy" placeholder="renewal date" required="true">
</div>
Below is the screen shot of that
How can I prevent this coming because of that css for tooltip
Based on your jsfiddle the tooltip is created by the <span>...</span> element. You can remove this span to remove this tooltip:
span:before {
content: "";
border-style: solid;
border-width: 0 15px 15px 15px;
border-color: transparent transparent rgba(0,102,255,.5) transparent;
height: 0;
position: absolute;
top: -17px;
width: 0;
}
span {
background-color: rgba(0,102,255,.15);
border: 2px solid rgba(0,102,255,.5);
border-radius: 10px;
color: #000;
display: none;
padding: 10px;
position: relative;
}
input {
display: block
}
input:hover + span {
display: inline-block;
margin: 10px 0 0 10px
}
<input type="text">
<span>Some Text inside... </span>
<input type="text"><!--dont need on hover for this text field-->
<!--<span>please enter </span>-->
Now the tooltip is only for the first input.
Another option - add the tooltip class to the input and use this class to control which input tags show tooltip using input.show-tooltip:hover + span:
span:before {
content: "";
border-style: solid;
border-width: 0 15px 15px 15px;
border-color: transparent transparent rgba(0,102,255,.5) transparent;
height: 0;
position: absolute;
top: -17px;
width: 0;
}
span {
background-color: rgba(0,102,255,.15);
border: 2px solid rgba(0,102,255,.5);
border-radius: 10px;
color: #000;
display: none;
padding: 10px;
position: relative;
}
input {
display: block
}
input.show-tooltip:hover + span {
display: inline-block;
margin: 10px 0 0 10px
}
<input type="text" class="show-tooltip">
<span>Some Text inside... </span>
<input type="text"><!--dont need on hover for this text field-->
<span>please enter </span>
You can do this by just adding a data-attribute like data-show="tooltip" in my case, or you can use any class for the same.
Look at the snippet below:
.tooltip-container span:before {
content: "";
border-style: solid;
border-width: 0 15px 15px 15px;
border-color: transparent transparent rgba(0,102,255,.5) transparent;
height: 0;
position: absolute;
top: -17px;
width: 0;
}
.tooltip-container span {
background-color: rgba(0,102,255,.15);
border: 2px solid rgba(0,102,255,.5);
border-radius: 10px;
color: #000;
display: none;
padding: 10px;
position: relative;
}
.tooltip-container input {
display: block
}
/* Use a data-attribute or class and apply hover conditions */
.tooltip-container input[data-show="tooltip"]:hover + span {
display: inline-block;
margin: 10px 0 0 10px
}
<div class="tooltip-container">
<input type="text" data-show="tooltip">
<span>Some Text inside... </span>
<input type="text"><!--dont need on hover for this text field-->
<span>please enter </span>
</div>
Hope this helps!
I am styling a checkbox using CSS3. Everything works fine except that the label jumps whenever I check and uncheck the checkbox. Could you please tell me why?
input[type="checkbox"]{
display:none;
}
input[type="checkbox"] + label::before{
background-color: white;
border: 1px solid #ccc;
content: '';
display: inline-block;
height: 15px;
width: 15px;
text-align: center;
margin: 0 5px -2px 0;
}
input[type="checkbox"]:checked + label::before{
content: '\2713';
}
<div>
<input type="checkbox" id="checkbox1">
<label for="checkbox1">Check 1</label>
</div>
You could add an overflow hidden to your pseudo element to prevent the jumping effect. I also updated the css a little bit to compensate for the overflow and the fact that the arrow wasn't really centered properly in the box.
JSFIDDLE Example
Here is my take on it:
input[type="checkbox"]{
display:none;
}
input[type="checkbox"] + label::before{
background-color: white;
border: 1px solid #ccc;
content: '';
display: inline-block;
height: 22px; /*Change width and height to compensate*/
width: 22px;
text-align: center;
margin: 0 5px -2px 0;
/*Added styles*/
overflow: hidden;
top: 3px;
position: relative;
}
input[type="checkbox"]:checked + label::before{
content: '\2713';
}
You can make the position for pseudo element to absolute and place it accordingly.
Here is a solution.
div
{
padding-left:20px;
}
input[type="checkbox"]{
display:none;
}
input[type="checkbox"] + label::before{
background-color: white;
border: 1px solid #ccc;
content: '';
display: inline-block;
height: 15px;
width: 15px;
text-align: center;
margin: 0 5px -2px 0;
position:absolute;
left:10px;
}
input[type="checkbox"]:checked + label::before{
content: '\2713';
}
<div>
<input type="checkbox" id="checkbox1">
<label for="checkbox1">Check 1</label>
</div>
There might be other attractive solutions too, this is just one.
Update
As reported by OP, there was(is?) a jumping behavior still present on demo. I added 2 more properties that might resolve the problem. I am getting the same desired results so I can't test it myself (hard to fix what you can't see).
Additional CSS
margin: 0 5px -5px 0;
line-height: 100%;
position: relative; // This should keep the input positioned in one spot.
float: left; // This should keep any extra movements of label and/or input from jumping as well.
The point of adding these 2 properties is that both of them take the element(s) out of the normal flow of the document, therefore having little to no interaction with other elements that might normally nudge or displace inputs and/or labels.
looked for that funky margin offset that'll always get added on in order to counteract that jumping behavior.
balanced out the neg and pos values
and added line-height: 100%
margin: 0 5px -5px 0;
line-height: 100%;
Also replaced the div with a fieldset it's not necessary, it just looks better. :)
input[type="checkbox"] {
display: none;
}
input[type="checkbox"] + label::before {
background-color: white;
border: 1px solid #ccc;
content: '';
display: inline-block;
height: 15px;
width: 15px;
text-align: center;
margin: 0 5px -5px 0;
line-height: 100%;
position: relative;
float: left;
}
input[type="checkbox"]:checked + label::before {
content: '\2713';
}
<fieldset>
<input type="checkbox" id="checkbox1">
<label for="checkbox1">Check 1</label>
</fieldset>
I currently have two radio buttons in a form that I have used the CSS property content to insert an image for each button and that changes in opacity when selected or not. The original radio button still shows to the left of the image. Is there any way move the image so that it is centered over the original radio button?
#button1,
#button2 {
height: 150px;
width: 150px;
margin-left: 10%;
margin-right: 10%;
}
#button1 {
content: url(../assets/logo.gif);
opacity: .4;
-webkit-transition-duration: 1.5s;
}
I wonder if this FIDDLE is what you're looking for.
HTML
<label class="mickey" for="button1">
<input id="button1" type="radio" name="testme" />
<img src='http://i.imgur.com/Q7IJUNJ.png?1' alt='' />
</label>
<label class="mickey" for="button2">
<input id="button2" type="radio" name="testme" />
<img src='http://i.imgur.com/73kXZTR.jpg' alt='' />
</label>
CSS
#button1, #button2 {
display: none;
}
input[type=radio] + img{
cursor:pointer;
border: 2px solid blue;
opacity: 0.5;
}
input[type=radio]:checked + img {
border: 2px solid red;
opacity: 1.0;
}
img {
height: 100px;
width: 100px;
}