I have created a simple check-box switch, here is a JSFiddle: http://jsfiddle.net/aseVX as you have noticed, when you click the little circle jumps, i am trying to make it smoothly shift from left to right and right to left. I tried adding CSS transition and that didn't make it work. Any ideas of what I am doing wrong?
/*Checkbox Switch*/
.switch p, .switch label {
display: inline;
}
.switch label {
margin-left: 10px;
}
.switch label > span {
background-color: rgba(0, 0, 0, 0.1);
border: 1px solid #A6A6A6;
width: 50px;
height: 30px;
position: relative;
display: inline-block;
vertical-align: middle;
cursor: pointer;
border-radius: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-webkit-transition: all .15s linear;
-moz-transition: all .15s linear;
-ms-transition: all .15s linear;
-o-transition: all .15s linear;
transition: all .15s linear;
}
.switch input[type="checkbox"]:checked + span {
background-color: #316C94;
border: 1px solid rgba(0, 0, 0, 0.4);
}
.switch span span {
background-color: #fff;
border: 1px solid #A6A6A6;
width: 24px;
height: 24px;
position: absolute;
top: 2px;
left: 2px;
cursor: pointer;
border-radius: 50px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
-webkit-transition: all .15s ease;
-moz-transition: all .15s ease;
-ms-transition: all .15s ease;
-o-transition: all .15s ease;
transition: all .15s ease;
}
.switch label > span:hover span {
width: 30px;
}
.switch input[type="checkbox"]:checked + span span {
right: 2px;
left: auto;
border: none;
}
/*Checkbox Switch > Disabled*/
.switch input[type="checkbox"]:disabled + span {
background-color: rgba(0, 0, 0, 0.1) !important;
border: 1px solid #A6A6A6 !important;
}
.switch input[type="checkbox"]:disabled + span span, .switch input[type="checkbox"]:disabled + span span:hover {
background-color: #fff !important;
border: 1px solid #A6A6A6 !important;
width: 24px !important;
}
As Adrift said in the comments, you cannot animate to a state of auto
But, since you said the width is set, you can animate to the left value that fits the width like so
.switch input[type="checkbox"]:checked + span span {
left: 23px;
border: none;
}
Demo
In addition I added a change the left position when the checkbox was checked and it was hovered
The prefixed versions of border-radius are not needed because -moz-border-radius was never a thing and browsers that don't support border-radius will not support transitions or anything like that either
Also, the !importants are not needed, if the selector is has a higher precedence or the same precedence but is further down the stylesheet, the styles will automatically be overridden. This is because CSS is a cascading language, meaning styles will apply over previous ones if they can. !important should try to be avoided as it causes issues when projects get large and such
Related
I'm using this simple css code by Tiffany Ong to generate a lightbox effect for my images. It works fine until I click an image further down the page; when I close the lightbox below the fold it brings me back to the top of the page rather than where I left off. Could someone advise me on how to fix this? Code is pasted below.
/*Eliminates padding, centers the thumbnail */
body, html {
padding: 0;
margin: 0;
text-align: center;
}
/* Styles the thumbnail */
a.lightbox img {
height: 150px;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0,0,0,.3);
margin: 94px 20px 20px 20px;
}
/* Styles the lightbox, removes it from sight and adds the fade-in transition */
.lightbox-target {
position: fixed;
top: -100%;
width: 100%;
background: rgba(0,0,0,.7);
width: 100%;
opacity: 0;
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
overflow: hidden;
}
/* Styles the lightbox image, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */
.lightbox-target img {
margin: inherit;
position: absolute;
top: 0;
left:0;
right:0;
bottom: 0;
max-height: 0%;
max-width: 0%;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0,0,0,.3);
box-sizing: border-box;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Styles the close link, adds the slide down transition */
a.lightbox-close {
display: block;
width:50px;
height:50px;
box-sizing: border-box;
background: white;
color: black;
text-decoration: none;
position: absolute;
top: -80px;
right: 0;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:before {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
-o-transform:rotate(45deg);
transform:rotate(45deg);
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:after {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top:10px;
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
-o-transform:rotate(-45deg);
transform:rotate(-45deg);
}
/* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox-target anchor */
.lightbox-target:target {
opacity: 1;
top: 0;
bottom: 0;
}
.lightbox-target:target img {
max-height: 100%;
max-width: 100%;
}
.lightbox-target:target a.lightbox-close {
top: 0px;
}
I am making a bootstrap wordpress theme and I have a problem about adding pure smooth drop-down menu effect for primary menu like this example such as it does not seem to work properly after clicked "M logo" to open drop-down menu. You can check out my theme on this link for more detail
Here are my CSS classes at the moment:
.navbar-nav>li>.dropdown-menu {
margin: -1px 0 0 45%;
border-top-right-radius: 0;
border-top-left-radius: 0;
}
.dropdown-menu {
/* background: url(img/submenu.png) no-repeat scroll right/ 91% 100%; */
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 153px;
padding: 1px 0;
margin: 2px 0 0 0;
list-style: none;
font-size: 14px;
text-align: center;
background-color: #5c4d4a;
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,0.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,0.175);
box-shadow: 0 6px 12px rgba(0,0,0,0.175);
background-clip: padding-box;
}
.dropdown-menu li a {
display: block;
background: url(img/submenu.png) no-repeat scroll right/ 104% 108%;
padding: 10px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571;
color: #fff;
white-space: nowrap;
}
.dropdown-menu li a:hover,
.dropdown-menu li a:focus {
background: url(img/submenu.png) no-repeat scroll right/ 104% 108%;
color: #ccc;
text-decoration: none;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff357ebd', GradientType=0);
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.dropdown-menu ul {
list-style: none;
}
The salient features required are:
.dropdown-menu {
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li:hover .dropdown-menu {
opacity: 1;
top: 50px;
visibility: visible;
}
The float:left is a furfy, it is over-ridden by position:absolute;
I'm working on my search toolbar for my website. Everything is running ok, except for the hide effect of the toolbar that has a weird behaviour. The transition works fine to display the writting bar, when I clock again in the search icon its suppose to hide the full bar, but instead hides only about half. If I click outside the search toolbar the bar hides correctly. Here is my code: Jsfiddle. And the relevant code:
#input {
position: absolute;
top: 0;
right: 30px;
width: 200px;
height: 30px;
z-index: 5;
overflow: hidden;}
#input input {
display: block;
position: absolute;
top: 0;
right: -200px;
width: 200px;
height: 100%;
margin: 0;
padding: 0 10px;
border: none;
background-color: #ededed;
color: #000;
font-size: 12px;
-webkit-backface-visibility: none;
-moz-backface-visibility: none;
-ms-backface-visibility: none;
backface-visibility: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
-webkit-transition: right 0;
-moz-transition: right 0;
-ms-transition: right 0;
-o-transition: right 0;
transition: right 0;}
#input input:focus {
outline: none;}
#input.focus {
z-index: 20;}
#input.focus input {
right: 0;
-webkit-transition: right 0.3s;
-moz-transition: right 0.3s;
-ms-transition: right 0.3s;
-o-transition: right 0.3s;
transition: right 0.3s;}
Thanks in advance!
Its seems the reason input box not hidding completely due to padding given for input element
.input input { padding: 0 10px;
The actual width is calculated by browser for input box is
width:200px + padding-left:10px + padding-right:10px = Actual width goes to 220px;
Solution for this is by adding
.input input { box-sizing:border-box;
property to input element class
Sample code can be seen here
.input {
position: absolute;
top: 0;
right: 30px;
width: 200px;
height: 30px;
line-height: 30px;
z-index: 5;
overflow: hidden;
border:1px solid #ccc;
background-color:#fff;
}
.input input {
box-sizing:border-box;
display: block;
position: absolute;
top: 0;
right: -200px;
width: 200px;
height: 100%;
margin: 0;
padding: 0 10px;
border: none;
background-color: #fff;
color: #000;
font-size: 12px;
-webkit-backface-visibility: none;
-moz-backface-visibility: none;
-ms-backface-visibility: none;
backface-visibility: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
-webkit-transition: right -200px;
-moz-transition: right -200px;
-ms-transition: right -200px;
-o-transition: right -200px;
transition: right -200px;
}
.input input:focus { outline: none; }
.input.focus { z-index: 20; }
.input:hover input{
right:0px;
-webkit-transition: right 0px 0.3s;
-moz-transition: right 0.3s;
-ms-transition: right 0.3s;
-o-transition: right 0.3s;
transition: right 0px 0.3s;
}
.input.focus input {
right:0px;
-webkit-transition: right 0px 0.3s;
-moz-transition: right 0.3s;
-ms-transition: right 0.3s;
-o-transition: right 0.3s;
transition: right 0px 0.3s;
}
body { font:13px 'arial'; }
https://jsfiddle.net/ShirishDhotre/9gqa2bum/
I added hover effect for demo you can remove class
.input:hover input{
I use some pretty straightforward css to show a larger image on hover. This is the HTML structure:
<div class="Enlarge">
<img src="small.jpg" />
<span><img src="large.jpg" /></span>
</div>
And here's the CSS:
.Enlarge {
position:relative;
}
.Enlarge span {
position:absolute;
left: -9999px;
}
.Enlarge span img {
margin-bottom:5px;
}
div.Enlarge:hover{
z-index: 999;
cursor:pointer;
}
div.Enlarge:hover span{
top: 110px;
left: 0px;
z-index: 999;
width:500px;
height:300px;
padding: 10px;
background:#eae9d4;
-webkit-box-shadow: 0 0 20px rgba(0,0,0, .75));
-moz-box-shadow: 0 0 20px rgba(0,0,0, .75);
box-shadow: 0 0 20px rgba(0,0,0, .75);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius:8px;
font-family: 'Droid Sans', sans-serif;
font-size:12px;
line-height:18px;
text-align: center;
color: #495a62;
padding-bottom:20px;
}
However, I would like to add an ease in/out effect to the larger image. I couldn't work that out. If I apply the transition to the , the image will slide in from the left side. This is not what I want. If I apply the effect to the image, it won't work.
Here's the example: Example
Thanks in advance for your input!
Using visibility and opacity you can achieve a fade effect.
JSFiddle Demo
Add these styles:
.Enlarge span {
position:absolute;
left: -9999px;
visibility: hidden;
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-ms-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
div.Enlarge:hover span {
visibility: visible;
opacity: 1;
/* rest of your styles below */
Hello I was wondering whether this is possible. I have a horizontal menu created using CSS with submenus and it works just fine. However, I want to have submenus appear to the right of the submenus already appearing.
The menu is as such: http://jsfiddle.net/dvpKx/39/
And the code is:
/*First reset ul styles*/
.nav,
.nav ul,
.nav li,
.nav a {
margin: 0;
padding: 0;
border: none;
outline: none;
}
/*Now add fixed width & height to the menu along with rounded corners and gradients*/
.nav {
height: 50px;
width: inherit;
margin: 10px;
background: -webkit-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
background: -moz-linear-gradient(top, rgba(198,56,32,1) 0%, rgb(127,48,35) 100%);
background: -o-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
background: -ms-linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
background: linear-gradient(top, rgb(198,56,32) 0%, rgb(127,48,35) 100%);
-webkit-border-radius: 15px;
-moz-border-radius: 5px;
border-radius: 5px;
}
/*Float links left to align links horizontally & position relative to align submenus properly*/
.nav li {
position: relative;
list-style: none;
float: left;
display: block;
height: 50px;
}
/*
Styling menu links -
font, color, padding, etc. Then a dark text shadow and a color transition to create a smooth effect when the color changes on hover state. To create the links separator add a border to the left and right and then we will remove the left border from the first link and the right border from the last link. For the hover state we will only change the text color.
*/
.nav li a {
border-bottom: none;
background: none;
display: block;
padding: 0 14px;
margin: 6px 0;
line-height: 32px;
text-decoration: none;
border-left: 1px solid #393942;
border-right: 1px solid #4f5058;
font-family: Verdana, sans-serif;
font-weight: bold;
font-size: 14px;
color: #f3f3f3;
text-shadow: 2px 3px 0px rgba(0,0,0,0.6);
-webkit-transition: color .2s ease-in-out;
-moz-transition: color .2s ease-in-out;
-o-transition: color .2s ease-in-out;
-ms-transition: color .2s ease-in-out;
transition: color .2s ease-in-out;
}
.nav li:first-child a { border-left: none; }
.nav li:last-child a{ border-right: none; }
.nav li:hover > a {
color: rgb(114,163,45);
background: none;
font-size: 18px;
}
/*
SUB MENU 1
We will start to position the sub menu 50px from the top and 0px from the left of the menu item and add bottom rounded corners. We will set the opacity to 0 and on hover state to 1 to create the fade in/out effect. For the slide down/up effect we need to set the list height to 0px when is hidden and to 36px on hover state.
*/
.nav ul {
position:absolute;
top: 50px;
padding-left: 0px;
opacity: 1;
background: rgb(43,35,34);
-webkit-border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
-webkit-transition: opacity .25s ease .1s;
-moz-transition: opacity .25s ease .1s;
-o-transition: opacity .25s ease .1s;
-ms-transition: opacity .25s ease .1s;
transition: opacity .25s ease .1s;
}
.nav li:hover > ul { opacity: 1; }
/* Hiding submenu 1 */
.nav ul li {
height: 0;
overflow: hidden;
padding: 0;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/* When hovered over, show submenu 1 */
.nav li:hover > ul li {
height: 46px;
overflow: hidden;
padding: 0;
z-index: 8999;
}
/* Hiding submenu TWO */
.nav ul ul li {
height: 0;
overflow: hidden;
padding: 0;
-webkit-transition: height .25s ease .1s;
-moz-transition: height .25s ease .1s;
-o-transition: height .25s ease .1s;
-ms-transition: height .25s ease .1s;
transition: height .25s ease .1s;
}
/* When hovered over, show submenu 1 */
.nav li:hover > ul ul li {
height: 80px;
padding: 0;
z-index: 9000;
}
/* Setting width of submenu to 100px & add a bottom border instead of left and right ones
(also removing it from last link) */
.nav ul li a {
width: 250px;
padding: 4px 0 4px 40px;
margin: 0;
border: none;
border-bottom: 1px solid #343438;
}
.nav ul li:last-child a { border: none; }
I would recommend the Son of Suckerfish dropdown (a CSS solution).
Code: http://www.htmldog.com/articles/suckerfish/dropdowns/ (specifically the Multi-level dropdown section about 1/2 down). Also, links to examples are shown at the bottom of the page.
You can try this
.menus {
width:100px;
height:50px;
border: 5px solid #000000;
border-radius: 25px;
text-align: center;
line-height: 50px;
color: black;
background-color: #dcdcdd;
}
.submenus {
margin-top:10px;
display:none;
width:100px;
height:50px;
border: 5px solid #000000;
border-radius: 25px;
text-align: center;
line-height: 50px;
color: black;
}
#menu1outer:hover #submenus1 {
display: block;
}
Hope that helps and you can see the sample here:
reformas integrales madrid