I would like add a clear input text feature to the existing search functionality. When user click the cross animation it should clear the input text instead of moving the arrows away. I have added display:none at last not valid, but not working as expected. Can someone please assist on how to implement this functionality ?.
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 1;
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
.search-box input[type="text"]:focus {
width: 280px;
height: 30px;
margin-right: 20px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
.search-box input[type="text"]:focus + span::before {
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
.search-box input[type="text"]:focus + span::after {
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.search-box:not(:valid) ~ span {
display: none;
}
<form name="search">
<label class="search-box">
<input type="text" />
<span></span>
</label>
</form>
https://jsfiddle.net/0wansxza/
You could do it using jQuery with that $('#element').val('');.
jQuery(document).ready(function(){
jQuery('.search-box input[type="text"]').focusout(function() {
jQuery(this).val('');
})
});
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 1;
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
.search-box input[type="text"]:focus {
width: 280px;
height: 30px;
margin-right: 20px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
.search-box input[type="text"]:focus + span::before {
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
.search-box input[type="text"]:focus + span::after {
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.search-box:not(:valid) ~ span {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="search">
<label class="search-box">
<input type="text" />
<span></span>
</label>
</form>
Using Just CSS. I had to modify your markup a little. To clear the input field i had to add a button that resets the form when clicked. See my code and comments below. Hope it helps
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 11;/**Changed This**/
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus,
.search-box .btn:focus + input{
width: 280px;
height: 30px;
margin-right: 30px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus + span::before,
.search-box .btn:focus + input[type="text"] + span::before{
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus + span::after,
.search-box .btn:focus + input[type="text"] + span::after{
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
/**
.search-box:not(:valid) ~ span {
display: none;
}**/
/**Added the below codes**/
.search-box .btn {
position: absolute;
top: 0;
right: 0;
bottom: 0;
background: transparent;
border: 0;
outline: 0;
width: 30px;
cursor: pointer;
z-index: 11;
}
<form name="search">
<label class="search-box">
<!--Added the button to clear the field on click-->
<button class="btn" type="reset"></button>
<input type="text" />
<span></span>
</label>
</form>
Related
Please I need your assistance to link the toggle to 2 separate links.. example..1 is www.google.com and second is www.ask.com
I need the 2 links linked to any of the ends of the switch so when it is selected , the switch moves to the selected end and also opens a new windows relating to the link above
.flipswitch {
position: relative;
width: 195px;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select: none;
}
.flipswitch input[type=checkbox] {
display: none;
}
.flipswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 50px;
}
.flipswitch-inner {
width: 200%;
margin-left: -100%;
-webkit-transition: margin 0.3s ease-in 0s;
-moz-transition: margin 0.3s ease-in 0s;
-ms-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s;
transition: margin 0.3s ease-in 0s;
}
.flipswitch-inner:before, .flipswitch-inner:after {
float: left;
width: 50%;
height: 34px;
padding: 0;
line-height: 34px;
font-size: 18px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.flipswitch-inner:before {
content: "ask view";
padding-left: 13px;
background-color: #256799;
color: #FFFFFF;
}
.flipswitch-inner:after {
content: "google View";
padding-right: 13px;
background-color: #EBEBEB;
color: #888888;
text-align: right;
}
.flipswitch-switch {
width: 31px;
margin: 1.5px;
background: #FFFFFF;
border: 2px solid #999999;
border-radius: 50px;
position: absolute;
top: 0;
bottom: 0;
right: 160px;
-webkit-transition: all 0.3s ease-in 0s;
-moz-transition: all 0.3s ease-in 0s;
-ms-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s;
transition: all 0.3s ease-in 0s;
}
.flipswitch-cb:checked + .flipswitch-label .flipswitch-inner {
margin-left: 0;
}
.flipswitch-cb:checked + .flipswitch-label .flipswitch-switch {
right: 0;
}
<div class="flipswitch">
<input type="checkbox" checked="" id="fs" class="flipswitch-cb" name="flipswitch">
<label for="fs" class="flipswitch-label">
<div class="flipswitch-inner"> </div>
<div class="flipswitch-switch"></div>
</label>
</div>
Like this
document.getElementById("fs").addEventListener("change",function() {
const loc = this.checked ? "https://www.google.com" : "https://ask.com/";
console.log(loc)
// window.open(loc,"_blank"); // only works if browser allows it
location = loc; // will work in all cases where the target allows it
})
.flipswitch {
position: relative;
width: 195px;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select: none;
}
.flipswitch input[type=checkbox] {
display: none;
}
.flipswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 50px;
}
.flipswitch-inner {
width: 200%;
margin-left: -100%;
-webkit-transition: margin 0.3s ease-in 0s;
-moz-transition: margin 0.3s ease-in 0s;
-ms-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s;
transition: margin 0.3s ease-in 0s;
}
.flipswitch-inner:before, .flipswitch-inner:after {
float: left;
width: 50%;
height: 34px;
padding: 0;
line-height: 34px;
font-size: 18px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.flipswitch-inner:before {
content: "ask view";
padding-left: 13px;
background-color: #256799;
color: #FFFFFF;
}
.flipswitch-inner:after {
content: "google View";
padding-right: 13px;
background-color: #EBEBEB;
color: #888888;
text-align: right;
}
.flipswitch-switch {
width: 31px;
margin: 1.5px;
background: #FFFFFF;
border: 2px solid #999999;
border-radius: 50px;
position: absolute;
top: 0;
bottom: 0;
right: 160px;
-webkit-transition: all 0.3s ease-in 0s;
-moz-transition: all 0.3s ease-in 0s;
-ms-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s;
transition: all 0.3s ease-in 0s;
}
.flipswitch-cb:checked + .flipswitch-label .flipswitch-inner {
margin-left: 0;
}
.flipswitch-cb:checked + .flipswitch-label .flipswitch-switch {
right: 0;
}
<div class="flipswitch">
<input type="checkbox" checked="" id="fs" class="flipswitch-cb" name="flipswitch">
<label for="fs" class="flipswitch-label">
<div class="flipswitch-inner"> </div>
<div class="flipswitch-switch"></div>
</label>
</div>
I would like to "draw" an outline around rectangle buttons, meaning I'd like for the border to transition but not fade in. I already have a bunch of effects on these buttons.. I tried to apply an already-made exemple of draw outline CSS but it didn't do anything..
Here's my code
function hoverIcons(classnm) {
document.getElementById(classnm).css({height: '+=30%', width: '+=30%'});
}
function nothoverIcons(classnm) {
document.getElementById(classnm).css({height: '+=30%', width: '+=30%'});
}
#menu {
position: fixed;
bottom: 20;
right: 20;
width: 80;
height: 30px;
background-color: Menu background;
z-index: 10;
}
#mainicons {
position: fixed;
bottom: 20px;
right: 193px;
text-align: center;
}
#mainicons i {
display: inline-block;
margin-top: 0;
margin-left: -3px;
height: 30px;
width: 50px;
padding: 10px;
color-color: Main icon;
background-color: Main icon background;
text-transform: uppercase;
font-size: 15px;
line-height: 30px;
-webkit-transition: all .7s ease;
-moz-transition: all .7s ease;
-o-transition: all .7s ease;
transition: all .7s ease;
}
#mainicons i:hover {
color-color: Hover;
background-color: Main icon;
transform: scale(1.1);
-webkit-transition: all .7s ease;
-moz-transition: all .7s ease;
-o-transition: all .7s ease;
transition: all .7s ease;
}
/*-- BEGINNING BORDER EFFECT (PASTED) --*/
#mainicons {
transition: color 0.25s;
box-sizing: border-box;
}
#mainicons::before, #mainicons::after {
box-sizing: inherit;
content: '';
position: absolute;
width: 100%;
height: 100%;
}
#mainicons::before, #mainicons::after {
border: 2px solid transparent;
width: 0;
height: 0;
}
#mainicons::before {
top: 0;
left: 0;
}
#mainicons::after {
bottom: 0;
right: 0;
}
#mainicons:hover {
color: #97c5e0;
}
#mainicons:hover::before, #mainicons:hover::after {
width: 100%;
height: 100%;
}
#mainicons:hover::before {
border-top-color: #97c5e0;
border-right-color: #97c5e0;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
#mainicons:hover::after {
border-bottom-color: #97c5e0;
border-left-color: #97c5e0;
transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
}
/*-- BEGINNING BORDER EFFECT (PASTED) --*/
/* originally written in SCSS
#mainicons {
transition: color 0.25s;
box-sizing: border-box;
&::before,
&::after {
box-sizing: inherit;
content: '';
position: absolute;
width: 100%;
height: 100%;}
&::before,
&::after {
border: 2px solid transparent;
width: 0;
height: 0;
}
&::before {
top: 0;
left: 0;
}
&::after {
bottom: 0;
right: 0;
}
&:hover {
color: #97c5e0;
}
&:hover::before,
&:hover::after {
width: 100%;
height: 100%;
}
&:hover::before {
border-top-color: #97c5e0;
border-right-color: #97c5e0;
transition:
width 0.25s ease-out,
height 0.25s ease-out 0.25s;
}
&:hover::after {
border-bottom-color: #97c5e0;
border-left-color: #97c5e0;
transition:
border-color 0s ease-out 0.5s,
width 0.25s ease-out 0.5s,
height 0.25s ease-out 0.75s;
}
}
*/
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"/>
<div id="menu">
<div id="mainicons" onmouseover="hoverIcons('mainicons')" onmouseout="nothoverIcons('mainicons')">
<i class="fa fa-home"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-pencil "></i>
<i class="fa fa-clock-o"></i>
</div>
</div>
I have to admit it's very complicated for me to understand what he/she tried to do for the outline thing (https://codepen.io/giana/pen/yYBpVY).. So if you have a better/easier way to do this, thanks a lot!!
your html seems funny - you have html for a center button and yet none appears??
you can use just 'purple' or 'blue' etc.. for colors if you don't want to use html codes/id you find it easier, you don't need to define these in your css - that dollar sign is usually used in jquery - i haven't seen it used in css before but that's just me, i won't say it can't be used [or i'd stand to be corrected]. EDIT: CSS vars are still experimental technology with no support in Chrome or IE (although supported in edge).. as there's no support in Chrome, I'd hold off using it for now
I adjusted your code somewhat. I added a display:block to the button code so now they display one under the other in the window. Remove this and they will display as the layout will display in your original code. For purposes of snippet/jsfiddle window it's just handier. I replaced the colours with the html colors that you had in your definitions but like i say, in future you can just say border-color:red etc.
Note that this is only meant as a guide. Adjust as you see fit!
button {
display: block;
background: none;
border: 0;
box-sizing: border-box;
margin: 1em;
padding: 1em 2em;
box-shadow: inset 0 0 0 2px #f45e61;
color: #f45e61;
font-size: inherit;
font-weight: 700;
position: relative;
vertical-align: middle;
&::before,
&::after {
box-sizing: inherit;
content: '';
position: relative;
width: 100%;
height: 100%;
}
}
.draw {
transition: color 0.25s;
border: 2px solid transparent;
height: 100%;
}
.draw::after {
bottom: 0;
right: 0;
}
.draw:hover {
color: #60daaa;
border-color: #fbca67;
width: 100%;
}
.meet {
border-top-color: #fbca67;
border-right-color: #fbca67;
}
.meet::after {
top: 0;
left: 0;
}
.meet:hover {
color: #fbca67;
z-index: 1;
border-bottom-color: #fbca67!important;
border-left-color: #fbca67!important;
}
.center {
width: 200px;
height: 100px;
text-align: center;
padding: 10px;
border-style: solid;
border-top-width: 2px!important;
border-bottom-width: 2px!important;
border-color: #6477b9;
color: #6477b9;
}
.center:hover {
color: #FF0000;
border-left-width: 2px!important;
border-right-width: 2px!important;
z-index: 90!important;
}
.center:focus {
border: 3px dashed red;
color: forestgreen;
}
.spin {
width: 5em;
height: 5em;
padding: 0;
border-width: 2px;
border-style: solid;
border-color: transparent;
top: 0;
left: 0;
}
.circle {
border-radius: 100%;
box-shadow: none;
}
.thick {
color: #f45e61;
z-index: -1;
background: #ffffff;
border-color: #f45e61;
}
.thick:hover {
color: #fff;
font-weight: 700;
background: #f45e61;
}
.thick::after {
mix-blend-mode: color-dodge;
}
/* Page styling */
html {
background: #4b507a;
}
body {
background: #fefefe;
color: #4b507a;
font: 300 24px/1.5 Lato, sans-serif;
margin: 1em auto;
max-width: 36em;
padding: 1em 1em 2em;
text-align: center;
}
.buttons {
isolation: isolate;
}
h1 {
font-weight: 300;
font-size: 2.5em;
}
<!---<h1>CSS Border Transitions</1>-->
<section class="buttons">
<button class="draw">Draw</button>
<button class="draw meet">Draw Meet</button>
<button class="center">Center</button>
<button class="spin">Spin</button>
<button class="spin circle">Spin Circle</button>
<button class="spin thick">Spin Thick</button>
</section>
Fiddle here
oups, i finally understood, effect is actually set on the container and you wish to set it on the links.
You basicly need to update the selector .
example
function hoverIcons(classnm) {
// document.getElementById(classnm).css({height: '+=30%', width: '+=30%'});
}
function nothoverIcons(classnm) {
// document.getElementById(classnm).css({height: '+=30%', width: '+=30%'});
}
#menu {
position: fixed;
bottom: 20;
right: 20;
width: 80;
height: 30px;
background-color: Menu background;
z-index: 10;
}
#mainicons {
position: fixed;
bottom: 20px;
right: 193px;
text-align: center;
}
#mainicons a {
transition: color 0.25s;
display: inline-block;
position: relative;
margin: 0 25px;
padding: 10px 20px;
box-sizing: border-box;
}
a::before,
a::after {
content: '';
position: absolute;
box-sizing: border-box;
width: 100%;
height: 100%;
}
a::before,
a::after {
border: 2px solid transparent;
width: 0;
height: 0;
}
a::before {
top: 0;
left: 0;
}
a::after {
bottom: 0;
right: 0;
}
a:hover {
color: #97c5e0;
}
a:hover::before,
a:hover::after {
width: 100%;
height: 100%;
}
a:hover::before {
border-top-color: #97c5e0;
border-right-color: #97c5e0;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
a:hover::after {
border-bottom-color: #97c5e0;
border-left-color: #97c5e0;
transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
<div id="menu">
<div id="mainicons" onmouseover="hoverIcons('mainicons')" onmouseout="nothoverIcons('mainicons')">
<i class="fa fa-home"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-pencil "></i>
<i class="fa fa-clock-o"></i>
</div>
</div>
#mainicons a{ /* select here the links */
transition: color 0.25s;
box-sizing: border-box;
display:inline-block;
position:relative ;
margin:0 25px;
padding: 10px 20px;
box-sizing:content-box;
&::before,
&::after {
content: '';
position: absolute;
box-sizing: border-box;
width: 100%;
height: 100%;
}
&::before,
&::after {
border: 2px solid transparent;
width: 0;
height: 0;
}
&::before {
top: 0;
left: 0;
}
&::after {
bottom: 0;
right: 0;
}
&:hover {
color: #97c5e0;
}
&:hover::before,
&:hover::after {
width: 100%;
height: 100%;
}
&:hover::before {
border-top-color: #97c5e0;
border-right-color: #97c5e0;
transition:
width 0.25s ease-out,
height 0.25s ease-out 0.25s;
}
&:hover::after {
border-bottom-color: #97c5e0;
border-left-color: #97c5e0;
transition:
border-color 0s ease-out 0.5s,
width 0.25s ease-out 0.5s,
height 0.25s ease-out 0.75s;
}
}
I want a Button, with 2 elements in it, to slide the Background.
But I want both elements to center vertical and get height 100% even when the other element is bigger.
Here is the HTML
<button class="btn-cstm-slide">
<div class="btn-cstm-slide-logo"><span>Test Test 14343</span></div>
<div class="btn-cstm-slide-text">
<span>Just a Testtest</span>
<br/>
<span>Let's see</span>
</div>
</button>
And here the CSS
.btn-cstm-slide {
height: 100%;
padding: 0px;
display: flex;
position: relative;
text-decoration: none;
overflow: hidden;
background: #333C42;
border: none;
box-shadow: 0px 1px 1px rgba(0,0,0,.1);
}
.btn-cstm-slide-logo {
height:100%;
min-height:100%;
margin: 0;
padding: 10px;
position: relative;
text-decoration: none;
background: #474f54;
color: #fff;
}
.btn-cstm-slide-text {
padding: 10px;
position: relative;
text-decoration: none;
background: #333C42;
color: #fff;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.btn-cstm-slide-text * {
position:relative;
}
.btn-cstm-slide-text:before {
content: "";
position: absolute;
height: 100%;
width: 0;
bottom: 0;
left:0;
background-color: #474f54;
-webkit-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.btn-cstm-slide-text:hover:before {
width: 100%;
}
Demo
FIDDLE
Can you help me? :(
Is this what you had in mind?
https://jsfiddle.net/e07uc4kj/9/
.btn-cstm-slide {
height: 100%;
padding: 0px;
display: flex;
position: relative;
text-decoration: none;
overflow: hidden;
background: #333C42;
border: none;
box-shadow: 0px 1px 1px rgba(0,0,0,.1);
}
.btn-cstm-slide-logo {
padding: 10px;
min-width: 80px;
position: absolute;
top: 0px;
bottom: 0px;
text-decoration: none;
background: #474f54;
color: #fff;
vertical-align: middle;
}
.btn-cstm-slide-text {
margin-left: 100px;
padding: 10px;
position: relative;
text-decoration: none;
background: #333C42;
color: #fff;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.btn-cstm-slide-text:before {
content: "";
position: absolute;
height: 100%;
width: 0;
bottom: 0;
left:0;
background-color: #474f54;
-webkit-transition: all 0.4s ease-in-out 0s;
transition: all 0.4s ease-in-out 0s;
}
.btn-cstm-slide-text:hover:before {
width: 100%;
}
I want to use toggle button from Proto.io:
https://proto.io/freebies/onoff.
It works but when I place the button after an image, the switch is not round anymore. Have a look how it is on JSFiddle: https://jsfiddle.net/rvmcn7ju.
Pro forma, here's the CSS:
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "UP";
padding-left: 10px;
background-color: #009900; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "DOWN";
padding-right: 10px;
background-color: #000099; color: #FFFFFF;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
It works when I change top attribute to 292px in .onoffswitch-switch (with this particular image). I probably have to change the position to relative and do sth else. Any help appreciated.
Updated your fiddle you need position relative to contain the switch.
.onoffswitch-label {
position: relative;
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
https://jsfiddle.net/rvmcn7ju/1/
Updated again because the switch looked ovaly
.onoffswitch-switch {
...
margin: 4px; // changed margin
height: 18px; // added height
...
}
https://jsfiddle.net/rvmcn7ju/3/
I have the following checkbox:
<div class="onoffswitch">
<input type="checkbox" name="showOnNavigation" class="onoffswitch-checkbox" id="showOnNavigation" checked>
<label class="onoffswitch-label" for="showOnNavigation">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
The CSS for it:
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #A3D900; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #CCCCCC; color: #333333;
text-align: right;
}
.onoffswitch-switch {
width: 25px; margin: 2.5px;
background: #000000;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
When I'm submitting a form and checkbox is on the ON position, the checkbox value is ON. When it is on OFF position, the value is not set to OFF, so my script will issue an error that the index is not set. It used to work before, but for some reason it doesn't work anymore. Really frustrating, kindly HELP!! A CSS only approach would be most preffered, otherwsie I could easily do this with JavaScript.
I got the code generated from http://proto.io/freebies/onoff/
Put a hidden field with the same name before your checkbox with a value of "OFF"