I've made custom checkbox, here is what i've made so far, but what I need is something like this, where there is also text and one image (not icon/fa-fa icon) in the center of the checkbox. Did u know how to achieve it? Here is the code from snippet:
div {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
outline: 1px solid white;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
top: 1px;
left: 1px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-ms-transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
outline: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
height: 95%;
width: 95%;
outline: 3px solid red;
}
<div>
<div>
<input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</div>
<div>
<input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</div>
</div>
Thanks in advance for your help.
You're doing just fine at your own. Your code looks a bit complex because you can use the label as a block-element (like a div or a wrapper). Take a step back, look at your layout 'inside' the checkbox and see it as a normal layout/styling element. Nothing fancy.
.styled {
/* could also be a background */
background-color: red;
padding: 1rem 4rem;
text-align: center;
cursor: pointer;
}
span {
display: block;
font-size: 16px;
font-family: Arial;
margin-top: 10px;
}
label {
display: block;
max-width: 100px;
margin: 0 auto;
}
#checkbox {
display: none;
}
input:checked+label {
background-color: green;
}
<input id="checkbox" type="checkbox">
<label class="styled" for="checkbox">
<img src="https://placehold.it/20x20" alt="image 1">
<img src="https://placehold.it/40x40" alt="image 2">
<img src="https://placehold.it/60x60" alt="image 3">
<span>Text</span>
</label>
<div>
<div><input type="checkbox" id="cb1" />
<label for="cb1">
<img src="http://lorempixel.com/103/103" />
<img src="https://dummyimage.com/120/000000/ffffff" />
<span>Text</span>
</label>
</div>
<div><input type="checkbox" id="cb2" />
<label for="cb2">
<img src="http://lorempixel.com/102/102" />
<img src="https://dummyimage.com/120/000000/ffffff" />
<span>Text</span>
</label>
</div>
</div>
div {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
outline: 1px solid white;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
top: 1px;
left: 1px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
z-index: 1;
}
label img + img {
height: 60%;
width: 60%;
z-index: 2;
position: absolute;
top: 10%;
left: 20%;
}
span {
z-index: 2;
color: red;
position: absolute;
top: 75%;
left: 40%;
text-align: center;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
outline: 1px solid red;
z-index: 3;
}
:checked + label img + img {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
height: 60%;
width: 60%;
outline: 0px solid transparent;
}
:checked + label img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 98%;
width: 98%;
outline: 3px solid red;
}
Related
I'm looking to place the toggle button aligned to the center of my element "Client_name" I created another div but I can't get the button to drop down and put it more to the right. Do you have any ideas?
The jsfiddle link is just below
https://jsfiddle.net/6cyuwxvf/
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #CD3B1B;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #89C445;
}
input:focus + .slider {
box-shadow: 0 0 1px #89C445;
}
input:checked + .slider:before {
-webkit-transform: translateX(86px);
-ms-transform: translateX(36px);
transform: translateX(38px);
}
.button10 {
background-color: white;
color: black;
border: 2px solid;
width: 500px;
height: 50px;
}
.div-permission {
display: table-cell;
vertical-align: middle;
height: 45px;
width: 900px;
border: 1px solid red;
}
You can use display: flex; with align-items: center; for vertical alignment and just add some margin to the switch.
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
margin-left: 0.25rem;
}
.switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #CD3B1B;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked+.slider {
background-color: #89C445;
}
input:focus+.slider {
box-shadow: 0 0 1px #89C445;
}
input:checked+.slider:before {
-webkit-transform: translateX(86px);
-ms-transform: translateX(36px);
transform: translateX(38px);
}
.button10 {
background-color: white;
color: black;
border: 2px solid;
width: 500px;
height: 50px;
}
.div-permission {
display: flex;
align-items: center;
height: 45px;
width: 900px;
border: 1px solid red;
}
<div class="div-permission">
<input type="text" class="button10" placeholder="Client_name" />
<label class="switch">
<input type="checkbox" id="togBtn" onclick="myFunction()" />
<div class="slider round"></div>
</label>
<input type="submit" id="myDIV" style="display: none;" name="valider" onclick="style.display = 'none'" />
</div>
In order to change the position, I use the CSS transform function.
Change your .switch class to this:
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
top:50%;
left:10%;
transform: translate(-50%,-50%);
}
That should center it for you! All I added was the top, left, and transform functions in the class.
I am trying to add arrows on the left and right side of the slider but even though the arrows Z-index is lower than the navigations Z-index, the surface above the arrows is not clickable.
Everything else works, but you can't have an image slider where the arrows are not clickable even though the surroundings of it is.
Please I have tried everything, my mind could come up with. Do you have any idea what could cause this problem? And how to fix it?
body {
margin: 0;
}
#container {
width: 960px;
height: 740px;
position: relative;
margin: 0px;
}
#container input {
display: none;
}
.images {
width: 100%;
height: 100%;
position: absolute;
}
.images img {
width: 100%;
height: 100%;
margin: 0px;
}
.prev,
.next {
height: 100%;
width: 12%;
position: absolute;
top: 0;
transition: .15s;
z-index: 100;
margin: 0px;
}
.prev:hover,
.next:hover {
cursor: pointer;
/* background: rgba(10, 10, 10, .5);*/
}
.prev {
left: 0
}
.next {
right: 0
}
#nav {
width: 100%;
height: 35px;
position: absolute;
bottom: 0px;
text-align: center;
cursor: arrow;
z-index: 100;
}
.dots {
width: 12px;
height: 12px;
margin: 0 4px;
border-radius: 50%;
background: rgba(10, 10, 10, .7);
position: relative;
display: inline-block;
cursor: pointer;
}
.dots:hover {
*background: rgba(245, 245, 245, .7);
}
#one,
#two,
#three {
z-index: -1;
}
#inp1:checked~#one,
#inp2:checked~#two,
#inp9:checked~#three {
z-index: 10;
}
#inp1:checked~#nav #dot1,
#inp2:checked~#nav #dot2,
#inp9:checked~#nav #dot3 {
background: white;
opacity: 70%;
}
.arrow:hover {
cursor: pointer;
}
.arrow {
border: solid white;
border-width: 0 6px 6px 0;
display: inline-block;
padding: 10px;
color: white;
opacity: 70%;
margin: 0px;
z-index: 11;
left: 0;
right: 0;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
position: relative;
left: 900px;
top: 400px;
}
.left {
transform: rotate(135deg);
position: relative;
top: 400px;
right: 0px;
}
<div id='container'>
<input type='radio' name="image" id='inp1' checked>
<input type='radio' name="image" id='inp2'>
<input type='radio' name="image" id='inp3'>
<i class="arrow right"></i>
<i class="arrow left"></i>
<div class='images' id='one'>
<img src='img/image1.jpeg'>
<label for='inp3' class='prev'></label>
<label for='inp2' class='next'></label>
</div>
<div class='images' id='two'>
<img src='img/image2.jpeg'>
<label for='inp1' class='prev'></label>
<label for='inp3' class='next'></label>
</div>
<div class='images' id='three'>
<img src='img/image3.jpeg'>
<label for='inp2' class='prev'></label>
<label for='inp1' class='next'></label>
</div>
<div id='nav'>
<label class='dots' id='dot1' for='inp1'></label>
<label class='dots' id='dot2' for='inp2'></label>
<label class='dots' id='dot3' for='inp3'></label>
</div>
</div>
I have been created custom radio button right to left
i used code from w3school
custom radio button w3school
but it's not working as right to left
that's mean first circle of radio and next text
.radioContainer{
display: inline-block;
position: relative;
cursor: pointer;
font-family: sans-serif;
font-size: 22px;
user-select: none;
padding-left: 30px;
direction: rtl;
}
.radioContainer input {
display:none;
}
.radioContainer .circle{
display: inline-block;
width: 25px;
height: 25px;
background-color: #eee;
position: absolute;
left: 0;
top: 0;
border-radius: 50%;
}
.radioContainer:hover .circle{
background-color: #ccc;
}
.radioContainer input:checked + .circle{
background-color: #2196fc;
}
.radioContainer input:checked + .circle:after{
content: "";
width: 10px;
height: 10px;
background-color: white;
position: absolute;
border-radius: 50%;
left:50%;
top:50%;
transform: translate(-50%,-50%);
}
<label class="radioContainer">my text1
<input type="radio" name="radio">
<span class="circle"></span>
</label>
<br/>
<label class="radioContainer">my text2
<input type="radio" name="radio">
<span class="circle"></span>
</label>
I want to change direction of label or put all the radio buttons on to div and set direction of div from right to left, but it's not working
Change padding-left to padding-right in radioContainer class.
And also change left to right in .radioContainer .circle
Your final CSS must be like this:
.radioContainer{
display: inline-block;
position: relative;
cursor: pointer;
font-family: sans-serif;
font-size: 22px;
user-select: none;
padding-right: 30px;
direction: rtl;
}
.radioContainer input {
display:none;
}
.radioContainer .circle{
display: inline-block;
width: 25px;
height: 25px;
background-color: #eee;
position: absolute;
right: 0;
top: 0;
border-radius: 50%;
}
.radioContainer:hover .circle{
background-color: #ccc;
}
.radioContainer input:checked + .circle{
background-color: #2196fc;
}
.radioContainer input:checked + .circle:after{
content: "";
width: 10px;
height: 10px;
background-color: white;
position: absolute;
border-radius: 50%;
left:50%;
top:50%;
transform: translate(-50%,-50%);
}
I can't do the task: center the text from the data-sentence attribute
After hovering over the picture (centered horizontally): https://jsfiddle.net/m59azhn8/1/
[data-sentence] {
position: relative;
}
[data-sentence]::after {
content: attr(data-sentence);
text-align: center;
padding: 5px;
font-size: 17px;
background: #333;
color: #fff;
z-index: 1000;
display: none;
position: absolute;
top: calc(100% - 55px);
border-bottom-right-radius: 20px;
border-bottom-left-radius: 20px;
left: 50%;
right: 0;
min-width: 245px;
min-height: 50px;
transform: translate(-50%, 0);
}
[data-sentence]:hover::after {
display: block;
}
[data-sentence='']::after {
display: none !important;
}
Here is a simple solution with flex-box. Hope this helps. New https://jsfiddle.net/m59azhn8/2/
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
<link rel="stylesheet" media="all" href="./css/all.css">
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="./js/all.js"></script>
<style>
body {
text-align: center;
margin: 0;
padding: 0;
}
.characters {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
}
ul li {
list-style-type: none;
display: inline;
}
input#checkbox_yoda + label {
background: url("https://image.ibb.co/fqqbDn/yoda.png") no-repeat;
background-size: 100%;
height: 250px;
width: 250px;
display:inline-block;
}
input#checkbox_trooper + label {
background: url("https://image.ibb.co/jBdk67/trooper.png") no-repeat;
background-size: 100%;
height: 250px;
width: 250px;
display:inline-block;
}
input#checkbox_vader + label {
background: url("https://image.ibb.co/chLbDn/vader.png") no-repeat;
background-size: 100%;
height: 250px;
width: 250px;
display:inline-block;
}
label[for=checkbox_yoda] {
border: 3px solid white;
border-radius: 20px;
color: transparent;
}
label[for=checkbox_trooper] {
border: 3px solid white;
border-radius: 20px;
color: transparent;
}
label[for=checkbox_vader] {
border: 3px solid white;
border-radius: 20px;
color: transparent;
}
input:hover + label {
border: 3px solid black;
border-radius: 20px;
cursor: pointer;
}
input:checked + label {
border: 3px solid black;
border-radius: 20px;
cursor: pointer;
}
input[type=checkbox] {
display: none;
}
[data-sentence] {
position: relative;
}
[data-sentence]::after {
content: attr(data-sentence);
text-align: center;
vertical-align: middle;
padding: 5px;
font-size: 17px;
background: #333;
color: #fff;
z-index: 1000;
display:none;
align-items:center;
justify-content:center;
position: absolute;
top: calc(100% - 55px);
border-bottom-right-radius: 20px;
border-bottom-left-radius: 20px;
left: 50%;
right: 0;
bottom: 0;
min-width: 245px;
min-height: 50px;
transform: translate(-50%, 0);
}
[data-sentence]:hover::after {
display: flex;
}
[data-sentence='']::after {
display: none !important;
}
</style>
</head>
<body>
<section class="characters">
<form action="#" method="get">
<input type="hidden" name="v" value="dQw4w9WgXcQ">
<ul>
<li>
<input id="checkbox_yoda" type="checkbox" name="character" value="light_side">
<label for="checkbox_yoda" data-sentence="Force is strong in you">Yoda</label>
</li>
<li>
<input id="checkbox_trooper" type="checkbox" name="character" value="dark_side">
<label for="checkbox_trooper" data-sentence="Just chillin'">Trooper</label>
</li>
<li>
<input id="checkbox_vader" type="checkbox" name="character" value="dark_side">
<label for="checkbox_vader" data-sentence="There is no escape from the Dark Side.">Vader</label>
</li>
</ul>
<button type="submit">Turn to the dark side</button>
</form>
</section>
</body>
</html>
I'm trying to "fill" a circle when a user clicks on it. The main issue is that when the animation ends, it's offset on the top by just a little bit. I've tried to add a margin-top: -1px to it but it's then offset on the bottom!
I'm open to any suggestion to make the animation smoother but my main question is: Why is the end result offset from the top a tiny bit and how can I fix it?
#searchOptions label {
display: inline-block;
cursor: pointer;
font-size: 14px;
text-transform: uppercase;
color: #000;
font-weight: 400;
margin-right: 40px;
}
#searchOptions label .circle {
display: inline-block;
position: relative;
border: 2px solid #000;
width: 15px;
height: 15px;
border-radius: 50%;
margin-right: 12px;
}
#searchOptions label .circle:before {
display: none;
position: absolute;
content: '';
background-color: #000;
border-radius: 50%;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
margin: 0 auto;
width: 2px;
height: 2px;
}
#searchOptions label .txt {
position: relative;
top: -3px;
}
#searchOptions input[type=radio] {
height: 0;
width: 0;
opacity: 0;
}
#searchOptions input[type=radio]:checked + label .circle:before {
display: block;
width: 100%;
height: 100%;
animation: fillRadio ease-in 1s;
}
#-webkit-keyframes fillRadio {
0% {
top: 50%;
transform: translateY(-50%);
width: 1%;
height: 1%;
}
100% {
top: 0%;
transform: translateY(0%);
width: 100%;
height: 100%;
}
}
<div id="searchOptions">
<input type="radio" name="searchType" value="option1" id="option1" />
<label for="option1"><span class="circle"></span> <span class="txt">Option 1</span>
</label>
<input type="radio" name="searchType" value="option2" id="option2" />
<label for="option2"><span class="circle"></span> <span class="txt">Option 2</span>
</label>
</div>
<!-- id="searchOptions" -->
Here's a JSFiddle if anyone would rather use that.
I believe that the problem comes from a dimensiion of 15px and top of 50% -> that gives a fractional size
I have changed the size to 16px, that is even:
#searchOptions label {
display: inline-block;
cursor: pointer;
font-size: 14px;
text-transform: uppercase;
color: #000;
font-weight: 400;
margin-right: 40px;
}
#searchOptions label .circle {
display: inline-block;
position: relative;
border: 2px solid #000;
width: 16px;
height: 16px;
border-radius: 50%;
margin-right: 12px;
}
#searchOptions label .circle:before {
display: none;
position: absolute;
content: '';
background-color: #000;
border-radius: 50%;
top: 50%;
transform: translateY(-50%);
left: 0;
right: 0;
margin: 0 auto;
width: 2px;
height: 2px;
}
#searchOptions label .txt {
position: relative;
top: -3px;
}
#searchOptions input[type=radio] {
height: 0;
width: 0;
opacity: 0;
}
#searchOptions input[type=radio]:checked + label .circle:before {
display: block;
width: 100%;
height: 100%;
animation: fillRadio ease-in 1s;
}
#-webkit-keyframes fillRadio {
0% {
top: 50%;
transform: translateY(-50%);
width: 1%;
height: 1%;
}
100% {
top: 0%;
transform: translateY(0%);
width: 100%;
height: 100%;
}
}
<div id="searchOptions">
<input type="radio" name="searchType" value="option1" id="option1" />
<label for="option1"><span class="circle"></span> <span class="txt">Option 1</span>
</label>
<input type="radio" name="searchType" value="option2" id="option2" />
<label for="option2"><span class="circle"></span> <span class="txt">Option 2</span>
</label>
</div>
<!-- id="searchOptions" -->