Rotating image via CSS - html

I am working on an app that uses Bootstrap. You can see it for yourself here. When a user clicks a link, I want it to rotate. The code is very small. It looks like this:
<div class="form-group">
<ul class="list-inline">
<li><button class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></button></li>
<li><h5>category</h5></li>
</ul>
</div>
When a user clicks the "v" I want it to animate from "v" to ">". In other words, I want the chevron to rotate counter-clockwise 90 degrees when someone clicks it. After looking at the powerful features in CSS 3, it looks like there is a way to do this using pure CSS. Am I correct, if so, how?

Try this:
DEMO
<div class="form-group">
<ul class="list-inline">
<li><button class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></button></li>
<li><h5>category</h5></li>
</ul>
</div>
SCRIPT:
$('.glyphicon').on('click', function(){
$(this).toggleClass('glyphicon-chevron-down glyphicon-chevron-right');
});

To rotate an element using CSS you can simply use transform: rotate(-90deg)
However, this will not rotate it on click just yet. You will probably need javascript for that. One way to do it (using jquery, since bootstrap already requires it):
CSS:
.rotated {
transform: rotate(-90deg);
}
JS:
$('.yourElement').click(function() {
$(this).toggleClass('rotated');
});
The 'toggleClass' will make sure the rotation is reverted when you click it again. Otherwise, just use 'addClass' to only use it once.
edit
As pointed out by Harry, you could also use the already present 'icon-chevron-right' in a similar fashion:
$('.yourElement').click(function() {
$(this).toggleClass('icon-chevron-down icon-chevron-right');
});
As long as your html started with only one of those two classes, this code will always remove one and add the other.

Css :
.spinEffect{
-webkit-animation: spin 0.5s infinite linear;
}
jQuery :
$(function(){
$(".whatIsClicked").click(function(){
$("#yourDiv").addClass("spinEffect");
});
});

You can use a simple script like this.
Script:-
$(document).ready(function(){
$( ".btn.btn-link" ).click(function() {
$(this).toggleClass( "rotate" );
});
})
css:-
.rotate{
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
html:-
<div class="form-group">
<ul class="list-inline">
<li><button class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></button></li>
<li><h5>category</h5></li>
</ul>
</div>
Hope it eill work for you!

Related

how to make a rotate animation in css angular

i am using angular and my question is simple how can i make to rotate this icon when i click on it?:
<div class="col-lg-1 col-md-4 col-sm-2 col-2 alend-text">
<i class="pomrgto iconfa fas fa-chevron-circle-right view_cir" title="Ver" aria-hidden="true" (click)="isCollapsed = !isCollapsed"
[attr.aria-expanded]="!isCollapsed" aria-controls="collapseBasic"></i>
</div>
the icon is the pomrgto iconfa fas fa-chevron-circle-right view_cir class, i want to do this:
When i click the icon, i want to make this rotate 90 degrees to the right making a little rotate animation, and when i click again go to the original state...
I know i can do it with css, but can you give me an idea of how can i do that?
Thank you!.
try something like this:
By default set transition property on the arrow.
On click of the icon, add a new class to it (let say "active")
then in CSS:
.pomrgto{
transition: transform 1s;
}
.active{
transform: rotate(90deg)
}

Active color with CSS3 & HTML

I'm suffering to active color on my template, I have used this template http://codepen.io/suez/pen/XJGOyL
How can I active menu, like when I clicked another menu not active. how to do this?
This is my code:
//HTML
<div class="demo__content">
<h2 class="demo__heading">What do you need help with?</h2>
<div class="demo__elems">
<div class="demo__elem demo__elem-1">With advertising online</div>
<div class="demo__elem demo__elem-2">With a website</div>
<div class="demo__elem demo__elem-3">I need help with both</div>
<span class="demo__hover demo__hover-1"></span>
<span class="demo__hover demo__hover-2"></span>
<span class="demo__hover demo__hover-3"></span>
<div class="demo__highlighter">
<div class="demo__elems">
<div class="demo__elem">With advertising online</div>
<div class="demo__elem">With a website</div>
<div class="demo__elem">I need help with both</div>
</div>
</div>
</div>
//CSS
.demo__hover-2 {
top: 7rem;
}
.demo__hover-2:hover ~ .demo__highlighter {
-webkit-transform: translateY(7rem);
transform: translateY(7rem);
}
.demo__hover-2:hover ~ .demo__highlighter .demo__elems {
-webkit-transform: translateY(-7rem);
transform: translateY(-7rem);
}
.demo__hover-3 {
top: 14rem;
}
.demo__hover-3:hover ~ .demo__highlighter {
-webkit-transform: translateY(14rem);
transform: translateY(14rem);
}
.demo__hover-3:hover ~ .demo__highlighter .demo__elems {
-webkit-transform: translateY(-14rem);
transform: translateY(-14rem);
}
.demo__elem a:active, a:hover, a:focus {
text-decoration: none;
outline: none;
}
If you are able to use jQuery in you code you can do it by adding "active" class to selected element of your menu.
For instance
$(".demo__elem").click(function() {
$(".demo__elem").removeClass("active"); // remove active from all
$(this).addClass("active"); // add active to this
});
and you "active" css should be styled as well.
If you're wanting to click a link, go to that page, and have that link retain the active state once you're on that page, you'll need to do one of three things.
Using HTML and CSS only, every page can be built completely and individually. This is called a static website. The menu will live on each page, and the link for the page you're on will need a unique ID (usually class="active") in order to set it apart as the active link. Using CSS, you can style to appear how you want.
You can use javascript to dynamically detect the page you're on, usually by reading your URL, and apply the active state to the appropriate link.
You can use a server side codding language such as PHP, ASP, RUBY, etc., and set your menus to dynamically detect which page you're on based on internal/server side code and apply the active state to the menu. This is a very clean, and once you get the hang of the language you choose, it's a very easy and effective method. This is the most popular choice by developers and is called a dynamic website.
In each case, you'll still use CSS the exact same way to style the active link.

animate.css animating distance

I am using animate.css for a login form. It works except not the way I want it to work. Currently I am using fadeInDown but it fades in down from a longer distance that I want. It fades in from off the viewport versus just fading in about 20px. I hope that makes sense.
https://daneden.github.io/animate.css/
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.1/animate.min.css" rel="stylesheet" />
<div id="login">
<div class="row animated fadeInDown">
<img src="logo.png"/>
<input type="text">
<input type="password">
</div>
</div>
Just overwrite the default fadeInDown animation to what ever you like.
If you take a look at the source on GitHub - animate.css/source/fading_entrances/fadeInDown.css you'll see that it is just a simple #keyframes rule. Just copy that and change the transform property to your needs.
In your case like so:
transform: translate3d(0, -20px, 0);
Here is an example changing the fadeInDown animation to appear from left to right instead of going from top to bottom, which makes no sense at all, but just to show you that it can be changed.
You could as well do a custom build and add your own animations or a helper class to change the offset.
#import url('https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.1/animate.min.css');
#keyframes fadeInDown {
from {
opacity: 0;
transform: translate3d(-100%, 0, 0);
}
to {
opacity: 1;
transform: none;
}
}
<div id="login">
<div class="row animated fadeInDown">
<input type="text">
<input type="password">
</div>
</div>

FontAwesome icons inside anchors not animating on chrome

I'm trying to animate a fontawesome icon, inside a span it works fine, but when I put the icon inside an anchor it stops working on chrome, on IE it works.
I am using FontAwesome 3.2.1
and this is my code
Html:
<a>
<i class="icon-wrench rotator"></i>
</a>
CSS:
.rotator {
display: inline-block;
-webkit-animation: rotate 2.5s 4 ease;
-webkit-transform-origin:90% 35%;
}
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(-12deg);
}
to {
-webkit-transform: rotate(112deg);
}
}
I tried it with FontAwesome 3.0.2 and it works, when I upgraded to 3.2.1 it stopped working, on chrome at least.
Thanks in advance
Edit
I also have more html inside the anchor and I don't want that to rotate so adding the 'rotator' class to the anchor won't do it
Edit
This is the actual html (the example above is simplified):
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-bell-alt icon-animated-bell icon-only"></i>
<span class="badge badge-success">5</span>
</a>
Add the rotator class to the anchor instead. It will start rotating on page load, assuming this is what you want?
http://jsfiddle.net/7kANu/4/
<a class="rotator">
<i class="icon-wrench"></i>
</a>
EDIT: Are you not able to wrap the icon in a div and assign the rotator class to that as a workaround?

Achieve click event using just CSS

My question is: It is possible to achieve this example using only css? If not what would you do? Jsfiddle examples are really appreciated ;)
How to obtain also the slashes? Should i use an image or in css is possible? And the triangle that change when is clicked? I know it is possible to do it with Js maybe in css :after and :before would help me?
PS: Javascript to Hide Menu:
<script language="javascript">
function toggle() {
var ele = document.getElementById("toggleMenu");
var text = document.getElementById("displayMenu");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "Menu";
}
else {
ele.style.display = "block";
text.innerHTML = "Hide";
}
}
</script>
<div class="menu-toggle"><div id="wrap"><a id="displayMenu" href="javascript:toggle();">Menu</a></div></div>
<div id="toggleMenu" style="display: none">
<div class="menu">
<ul><li> Home </li>
<li> Item </li>
</ul>
</div>
</div>
Usually I do something like this with images to achieve the click event with just css
<figure>
<img id="zoom" src="http://cargowire.net/Content/images/events/stackoverflow.jpg" alt="EE" />
<figcaption>
<ul>
<li>
Zoom In
</li>
<li>
Zoom Out
</li>
</ul>
</figcaption>
</figure>
and CSS:
figure { background: #e3e3e3; display: block; float: left;}
#zoom {
width: 0px;
-webkit-transition: width 1s;
}
#zoom:target {
width: 400px;
}
Check here: http://jsfiddle.net/dCTeW/ Maybe something similar can be done for menus too
It is perfectly possible, but only when the mouse hovers, not on click as far as I am aware. You will want to use CSS :hover states.
There is an in depth article here: http://csswizardry.com/2011/02/creating-a-pure-css-dropdown-menu/
and the demo for that article here: http://csswizardry.com/demos/css-dropdown/
If you want to use click then a small bit of jquery may help you something like:
$('.menu-item').click(function(){
$(this).find('hover-div').toggle()
})
http://api.jquery.com/toggle/
that is the Documentation for toggle which is what you need to achieve.
If you insist on using click in stead of hover, you could try to use :focus as suggested, but it would actually be a hack, and not considered correct use of HTML and css. Just for demonstration though, have a look at this: http://jsfiddle.net/9efMt/1/
As you can see, I use an input, with the :focus pseudo class and the + sibling selector. Nothing really wrong with that css, but putting the menu in an input is just not done!
I used jquery for the js in the, imo, correct example that is in the same fiddle. All i do is toggling a class when the menu link is clicked. It looks like this:
$('#menu2').click(function() {
$('#menu2-sub').toggleClass('active');
});
The css should be fairly straight forward.