Hi I have menu which is three dots with animation. I have to transform to X when I click the three dots. The demo link is: demo
HTML:
<div class="dots">
<div class="dot"></div>
</div>
CSS:
html, body {
height: 100%;
background: black;
}
.dots {
position: absolute;
right: 20px;
}
.dot,
.dot:before,
.dot:after {
position: absolute;
width: 6px;
height: 6px;
border-radius: 20px;
background-color: #fff;
transform: rotate(270deg);
cursor: pointer;
}
.dot {
top: 50px;
right: 0;
}
.dot:before,
.dot:after {
content: "";
}
.dot:before {
right: 10px;
transition: right .3s ease-out;
}
.dot:after {
left: 10px;
transition: left .3s ease-out;
}
.dots:hover .dot:before {
right: -10px;
}
.dots:hover .dot:after {
left: -10px;
}
In the current code on hover the dots moves left to right.What I wanted is on hover the the dots should move from it's position and then transform to X on click. Confused how to fix this I want something like hamberger menu but with the dots instead of three lines. Any suggestions?
So the author confirmed, that the following fiddle solved the problem:
https://jsfiddle.net/dhmr44ua/6/
HTML:
<div class="dots">
<label for="toggle"></label>
<input id="toggle" type="checkbox" />
<div class="dot"></div>
</div>
CSS:
html, body {
height: 100%;
background: black;
}
.dots {
position: absolute;
right: 20px;
}
.dots input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
.dots label {
display: inline-block;
cursor: pointer;
position: absolute;
width: 15px;
height: 32px;
top: 38px;
left: -10px;
z-index: 999;
}
.dot,
.dot:before,
.dot:after {
position: absolute;
width: 6px;
height: 6px;
border-radius: 20px;
background-color: #fff;
transform: rotate(270deg);
cursor: pointer;
}
.dot {
top: 50px;
right: 0;
}
.dot:before,
.dot:after {
content: "";
}
.dot:before {
right: 10px;
transition: right .3s ease-out, width .3s ease-out;
}
.dot:after {
left: 10px;
transition: left .3s ease-out, width .3s ease-out;
}
.dots:hover .dot:before {
right: -10px;
}
.dots:hover .dot:after {
left: -10px;
}
.dots input[type=checkbox]:checked ~ .dot:before {
right: -8px;
width: 22px;
transform: rotate(225deg);
}
.dots input[type=checkbox]:checked ~ .dot:after {
left: -8px;
width: 22px;
transform: rotate(135deg);
}
I used the css checkbox trick mentioned in this answer: https://stackoverflow.com/a/13975505/1293849
Related
I have a problem. I want to use a animated checkbox and tried adding it to my code. The first problem I have is that the checkbox was floating a row above the <p> tag. For that I tried to create a flexbox with align-items: center;, but that results in a row that is aligned for some reason to the right side and the checkbox is still not at the same height as the <p> tag.
Here is the code snippet:
._checkbox
{
display: none;
}
label
{
width: 20px;
height: 20px;
margin: 0 auto;
background-color: #3f97fc;
transform: translateY(-50%);
border-radius: 50%;
cursor: pointer;
transition: 0.2s ease transform, 0.2s ease background-color, 0.2s;
overflow: hidden;
z-index: 1;
}
label:before
{
content: "";
position: absolute;
top: 50%;
right: .5%;
left: 0;
width: 15px;
height: 15px;
margin: 0 auto;
background-color: #fff;
transform: translateY(-50%);
border-radius: 50%;
transition: 0.2s ease width, 0.2s ease height;
}
#tick_mark
{
position: absolute;
top: 3px;
right: 0;
left: -11px;
width: 12px;
height: 10px;
margin: 0 auto;
margin-left: 14px;
transform: rotateZ(-40deg);
}
#tick_mark:before, #tick_mark:after
{
content: "";
position: absolute;
background-color: #fff;
border-radius: 2px;
opacity: 0;
transition: 0.2s ease transform, 0.2s ease opacity;
}
#tick_mark:before
{
left: 0;
bottom: 0;
width: 3px;
height: 8px;
transform: translateY(-68px)
}
#tick_mark:after
{
left: 0;
bottom: 0;
width: 100%;
height: 3px;
transform: translateX(78px)
}
._checkbox:checked + label
{
background-color: #07d410;
}
._checkbox:checked + label:before
{
width: 0;
height: 0;
}
._checkbox:checked + label #tick_mark:before, ._checkbox:checked + label #tick_mark:after
{
transform: translate(0);
opacity: 1;
}
.checkbox_container
{
display: flex;
align-items: center;
space-between: 0px
}
.teskt {
padding: 0px;
}
<div class="option 0, checkbox_container"><input type="checkbox" id="Air Quality" class="_checkbox"><label for="Air Quality"><div id="tick_mark"></div></label><p class="tekst"> Air Quality - 7 Project(s)</p></div>
So just to be clear... I want the checkbox next to the <p> tag and the height of them needs to be on the same level. Also, the content needs to be aligned to the right side!
Can someone tell me how to achieve this?
Everything aligned to left, vertically on the same level, like this?
I removed transform from label, not sure why you had it there and set it to position relative and replaced margin with margin right for spacing. On the flex container I updated it to
.checkbox_container {
display: flex;
align-items: center; // vertically centers flex items
}
._checkbox {
display: none;
}
label {
width: 20px;
height: 20px;
background-color: #3f97fc;
position: relative;
border-radius: 50%;
cursor: pointer;
transition: 0.2s ease transform, 0.2s ease background-color, 0.2s;
overflow: hidden;
z-index: 1;
margin-right: 10px;
}
label:before {
content: "";
position: absolute;
top: 50%;
right: .5%;
left: 0;
width: 15px;
height: 15px;
margin: 0 auto;
background-color: #fff;
transform: translateY(-50%);
border-radius: 50%;
transition: 0.2s ease width, 0.2s ease height;
}
#tick_mark {
position: absolute;
top: 3px;
right: 0;
left: -11px;
width: 12px;
height: 10px;
margin: 0 auto;
margin-left: 14px;
transform: rotateZ(-40deg);
}
#tick_mark:before,
#tick_mark:after {
content: "";
position: absolute;
background-color: #fff;
border-radius: 2px;
opacity: 0;
transition: 0.2s ease transform, 0.2s ease opacity;
}
#tick_mark:before {
left: 0;
bottom: 0;
width: 3px;
height: 8px;
transform: translateY(-68px)
}
#tick_mark:after {
left: 0;
bottom: 0;
width: 100%;
height: 3px;
transform: translateX(78px)
}
._checkbox:checked+label {
background-color: #07d410;
}
._checkbox:checked+label:before {
width: 0;
height: 0;
}
._checkbox:checked+label #tick_mark:before,
._checkbox:checked+label #tick_mark:after {
transform: translate(0);
opacity: 1;
}
.checkbox_container {
display: flex;
align-items: center;
}
.teskt {
padding: 0px;
}
<div class="option 0, checkbox_container">
<input type="checkbox" id="Air Quality" class="_checkbox">
<label for="Air Quality">
<span id="tick_mark"></span>
</label>
<p class="tekst"> Air Quality - 7 Project(s)</p>
</div>
I was searching for a way to make some kind of toggle button and I found one that is exactly how I wanted but this example is using the toggle on an input field and I want to use it on a div. I tried several things changing the CSS classes but for some reason I can't get it working properly.
This is the example CSS I am using:
.switch {
position: relative;
display: inline-block;
width: 90px;
height: 34px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ca2222;
-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: #2ab934;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(55px);
}
/*------ ADDED CSS ---------*/
.slider:after
{
content:'OFF';
color: white;
display: block;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
font-size: 10px;
font-family: Verdana, sans-serif;
}
input:checked + .slider:after
{
content:'ON';
}
/*--------- END --------*/
This is the example HTML:
<label class="switch"><input type="checkbox" id="togBtn"><div class="slider round"></div></label>
When I use it like this everything is working fine but my HTML and the div I want to toggle is like this:
<div class="facetwp-facet facetwp-facet-aanbieding facetwp-type-checkboxes" data-name="aanbieding" data-type="checkboxes">
<div class="facetwp-checkbox" data-value="ja">Ja</div>
</div>
I made changes to the example CSS to make it work on the div I want to toggle but I'm a bit lost here on how to get this working.
Maybe it is very simple but I'm lost so if somebody could help me out a little bit that would be great!
I added checked class to slider div instead of :checked the input checkbox.
So some changes in CSS code.
.slider.checked{...} instead of input:checked + .slider {...}
.slider:focus{...} instead of input:focus + .slider {...}
.slider.checked:before {...} instead of input:checked + .slider:before {...}
Try the Demo in Jquery
Using Jquery for clicking the slider div to toggle class checked.
$(".slider").click(function(){
$(this).toggleClass("checked");
});
.switch {
position: relative;
display: inline-block;
width: 90px;
height: 34px;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ca2222;
-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%;
}
.slider.checked{
background-color: #2ab934;
}
.slider:focus{
box-shadow: 0 0 1px #2196F3;
}
.slider.checked:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(55px);
}
/*------ ADDED CSS ---------*/
.slider:after
{
content:'OFF';
color: white;
display: block;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
font-size: 10px;
font-family: Verdana, sans-serif;
}
.slider.checked:after
{
content:'ON';
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="switch">
<div class="slider round"></div>
</div>
Try the Demo in Javascript
Using Javascript for clicking the slider div to toggle class checked.
function sliding(obj){
obj.classList.toggle("checked");
}
.switch {
position: relative;
display: inline-block;
width: 90px;
height: 34px;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ca2222;
-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%;
}
.slider.checked{
background-color: #2ab934;
}
.slider:focus{
box-shadow: 0 0 1px #2196F3;
}
.slider.checked:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(55px);
}
/*------ ADDED CSS ---------*/
.slider:after
{
content:'OFF';
color: white;
display: block;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
font-size: 10px;
font-family: Verdana, sans-serif;
}
.slider.checked:after
{
content:'ON';
}
<div class="switch">
<div onclick="sliding(this);" class="slider round"></div>
</div>
I created a hamburger menu that, when clicked, rotates two of its children and one is hidden. The hamburger has 30px width and 13px height. The thing is: when the two children rotate, the height increases, but only the central area (which is 30px/13px is clickable).
How can I make the whole "X" clickable?
var hamburger = document.getElementById("menu-icon-css");
var menuMobile = document.getElementById("menu-links");
hamburger.addEventListener("click", function open() {
hamburger.classList.toggle("rotate");
})
#menu-icon-css {
z-index: 50;
margin-top: 50px;
width: 30px;
height: 13px;
position: relative;
cursor: pointer;
display: block;
}
#menu-icon-css span {
transition: 0.3s all ease-in-out;
height: 3px;
background-color: #000;
position: absolute;
width: 100%;
}
#menu-icon-css span:nth-child(1) {
top: 0;
}
#menu-icon-css span:nth-child(2) {
top: 6px;
width: 70%;
right: 0;
}
#menu-icon-css span:nth-child(3) {
top: 12px;
}
#media screen and (min-width: 920px) {
#menu-icon-css {
display: none;
}
}
#menu-icon-css.rotate span:nth-child(1) {
transform: rotate(135deg);
top: 6px;
}
#menu-icon-css.rotate span:nth-child(2) {
opacity: 0;
transition: 0.1s all ease-in-out;
}
#menu-icon-css.rotate span:nth-child(3) {
transform: rotate(-135deg);
top: 6px;
}
<div id="menu-icon-css">
<span></span>
<span></span>
<span></span>
</div>
I'll leave a print of the issue on Inspect.
Thank you!
Try a few tweaks on the main top margin, height of the menu-icon-css div, and the position of the child elements, such as the following. (The lines in your code that I changed, I commented out and replaced with a line containing my changes.)
#menu-icon-css {
z-index: 50;
//margin-top: 50px;
margin-top: 42px;
width: 30px;
//height: 13px;
height: 30px;
position: relative;
cursor: pointer;
display: block;
}
#menu-icon-css span {
transition: 0.3s all ease-in-out;
height: 3px;
background-color: #000;
position: absolute;
width: 100%;
}
#menu-icon-css span:nth-child(1) {
top: 0;
}
#menu-icon-css span:nth-child(2) {
top: 6px;
width: 70%;
right: 0;
}
#menu-icon-css span:nth-child(3) {
top: 12px;
}
#media screen and (min-width: 920px) {
#menu-icon-css {
display: none;
}
}
#menu-icon-css.rotate span:nth-child(1) {
transform: rotate(135deg);
//top: 6px;
top: 14px;
}
#menu-icon-css.rotate span:nth-child(2) {
opacity: 0;
transition: 0.1s all ease-in-out;
}
#menu-icon-css.rotate span:nth-child(3) {
transform: rotate(-135deg);
//top: 6px;
top: 14px;
}
I've had a look around but couldn't find anyone else experiencing anything similar.
As the title states I'm getting a weird "glitch" in a transform transition when the parent element changes from absolute to fixed positioned ONLY in Firefox (looks completely fine in Chrome).
Thought I would throw it in here just in case someone has found a fix for this issue before.
OS: OS X El Capitan
Firefox version: 51.0.1
Codepen: http://codepen.io/anon/pen/dNmJPK
Html:
<div class="menu">
<button id="btn-menu" type="button">
<span class="menu-bars"></span>
</button>
</div>
SCSS:
#btn-menu {
position: absolute;
z-index: 100;
top: 50px;
right: 30px;
height: 49px;
width: 49px;
background-color: transparent;
padding-left: 0;
padding-right: 0;
cursor: pointer;
transition: .5s;
transform: translate(0, -50%);
border: 3px solid #000;
border-radius: 10px;
&:focus {
outline: none;
}
.menu-open & {
border-color: transparent;
position: fixed;
}
.menu-bars {
display: inline-block;
position: relative;
vertical-align: middle;
width: 21px;
height: 3px;
background-color: #000;
transition: .3s;
&:before, &:after {
content: "";
display: block;
position: absolute;
left: 0;
width: 100%;
height: 100%;
background-color: #000;
transition: .3s;
}
&:before {
top: -10px;
transform-origin: 0 0;
}
&:after {
bottom: -10px;
transform-origin: 0 100%;
}
.menu-open & {
background-color: transparent;
&:before {
top: -7px;
transform: rotate(45deg);
}
&:after {
bottom: -7px;
transform: rotate(-45deg);
}
}
}
}
JQuery:
// Open/close menu
$('#btn-menu').on('click', function() {
$('.menu').toggleClass('menu-open');
});
Thank you to #MichaelCoker for the solution of using transforms instead of top, bottom. See updated codepen below.
http://codepen.io/anon/pen/xgWpQa
&:before {
transform: translate(0, -10px);
}
&:after {
transform: translate(0, 10px);
}
.menu-open & {
background-color: transparent;
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
}
I need to center horizontally a button with aboslute position (because it must keep on top when to click and launch overlay and click to close overlay) on a position fixed topbar, here is the code:
.topbar {
text-align: center;
min-width: 100%;
height: 50px;
background-color: #29343a;
position: fixed;
top: 0;
}
.button {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
}
.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(153,204,51,0.9);
}
Thats is just the css of the three parts, the website is more complex but i think that 3 parts are the key. the topbar must be fixed on top, the buton have to be centered into the topbar div, and the overlay launch and the buttop keeps on top of the overlay.
What is working: the overlay works fine and the button keeps on top but its not horizontally centered on the topbar.
How i can hack this?
You could to the left:0 and right:0 trick.
.button {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 0; /*added*/
right: 0; /*added*/
}
Or do the left:50% with negative left margin (half width).
.button {
display: inline-block;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 50%; /*added*/
margin-left: -30px; /*added*/
}
Or use CSS3 transform.
.button {
display: inline-block;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 50%; /*added*/
transform: translateX(-50%); /*added*/
}
Based on the information you provided this is what I could come up with:
/* CSS */
.topBar {
position:fixed;
top:0;
left:0;
width:100%;
height:auto;
background-color:#29343a;
}
.overlay {
display:none;
width: 100%;
background: rgba(153,204,51,0.9);
margin:0;
}
.button, .button:active, .button:visited, .button:hover {
display: block;
position:relative;
text-align:center;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
margin:0 auto;
padding:10px;
}
.topBar:hover > .overlay {
display:block;
}
And I added some html because you didn't provide any:
<!-- HTML -->
<div class="topBar">
Button
<div class="overlay">
<p>Some text shows when button hover</p>
</div>
</div>
JSFIDDLE: https://jsfiddle.net/0napm6y3/
Here is the complete code of this component made on react:
This is the react component, the overlay launch is the overlay var, the other one is for one animation on the button:
var React = require('react');
var StatusBarButtonView = React.createClass({
getInitialState: function() {
return {cliked: false};
},
handleClick: function(event) {
this.setState({cliked: !this.state.cliked});
},
render: function() {
var fondo = this.state.cliked ? 'active' : '';
var overlay = this.state.cliked ? 'open' : '';
return (
<div>
<div className={"aui-profit-statusbar-button-container " + (fondo)} onClick={this.handleClick}>
<img src="images/aui-navbar-element-icon-cross.png" className={"rotate " + (fondo)}/>
</div>
<div className={"overlay overlay-slidedown " + (overlay)}>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Clients</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
);
}
});
module.exports = StatusBarButtonView;
Here is the topbar scss:
.aui-profit-statusbar-container {
text-align: center;
min-width: 100%;
height: 50px;
background-color: #29343a;
position: fixed;
top: 0;
}
Here is the button scss:
.aui-profit-statusbar-button-container {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 0;
right: 0;
&:hover {
background-color: #56d9f6;
}
&.active {
background-color: #ff4b39;
border-bottom: 2px solid #e43f30;
}
.rotate {
margin-top: 13px;
width: 23px;
height: 23px;
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-ms-transition-duration: 0,2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-ms-transition-property: -ms-transform;
-o-transition-property: -o-transform;
transition-property: transform;
}
.active {
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
}
Here is the overlay css:
/* Overlay style */
.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(153,204,51,0.9);
}
/* Overlay closing cross */
.overlay .overlay-close {
width: 80px;
height: 80px;
position: absolute;
right: 20px;
top: 20px;
overflow: hidden;
border: none;
background: url(../img/cross.png) no-repeat center center;
text-indent: 200%;
color: transparent;
outline: none;
z-index: 100;
}
/* Menu style */
.overlay nav {
text-align: center;
position: relative;
top: 50%;
height: 60%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.overlay ul {
list-style: none;
padding: 0;
margin: 0 auto;
display: inline-block;
height: 100%;
position: relative;
}
.overlay ul li {
display: block;
height: 20%;
height: calc(100% / 5);
min-height: 54px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.overlay ul li a {
font-size: 54px;
font-weight: 300;
display: block;
color: #fff;
-webkit-transition: color 0.2s;
transition: color 0.2s;
}
.overlay ul li a:hover,
.overlay ul li a:focus {
color: #e3fcb1;
}
/* Effects */
.overlay-slidedown {
visibility: hidden;
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
-webkit-transition: -webkit-transform 0.4s ease-in-out, visibility 0s 0.4s;
transition: transform 0.4s ease-in-out, visibility 0s 0.4s;
}
.overlay-slidedown.open {
visibility: visible;
-webkit-transform: translateY(0%);
transform: translateY(0%);
-webkit-transition: -webkit-transform 0.4s ease-in-out;
transition: transform 0.4s ease-in-out;
}
#media screen and (max-height: 30.5em) {
.overlay nav {
height: 70%;
font-size: 34px;
}
.overlay ul li {
min-height: 34px;
}
}
Now it works perfectly, thanks to all.
Next thing i have to do is separate overlay of buttom component. and keep it running, but im wondering to to pass the action to one component to another.... i have to learn more about react.js