How to animate an element on hover - html

How can I make my <div> elements grow (and the content changes text size to a higher one), when hovered over? I put them in a class and tried:
size: 150%;
and
height: +30px;
width: +30px;
the first try didn't work at all, and the second code just made the div's flash and dissappear partially.

CSS3 solution:
div {
background: #999;
width: 200px;
height: 20px;
transition: width 1s;
}
div:hover{
width: 300px;
}
<div>
<p>Im content</p>
</div>
http://jsfiddle.net/MrdvW/

I did something like this for a similar problem (you can change the scale to whatever works for you):
div:hover {
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
-ms-transform: scale(1.1);
}
Note that this will scale both the div and its content, which I think is what you want.

Using CSS you can add a hover style to the div:
div.container {
width: 80%;
background-color: blue;
}
div.container:hover {
width: 100%;
background-color: red;
}
See this jsFiddle for a demonstration.
jQuery Solution
Another option that might work for you is jQuery. It's a JavaScript library that simplifies commonly needed functionality such as this. Using jQuery, you can easily add hover effects to the elements:
//hover effect applies to any elements using the 'container' class
$(".container").hover(
function(){ //mouse over
$(this).width($(this).width() + 30);
},
function(){ //mouse out
$(this).width($(this).width() - 30);
}
);
See this jsFiddle for a demonstration.

Related

How to rotate an input toggle image properly?

I've got a simple input toggle that reveals text when 'toggled'.
Codepen
HTML
<div class="window">
<input type="checkbox" id="punch" class="toggle">
<label for="punch">
<img class="arrow" src="http://45.79.67.59/moreinfo_arrow.png">
</label>
<div>
<h3>codepen.io</h3>
</div>
</div>
CSS
div.window {
color: #000;
width: 100%;
background: #fff;
margin: 0px;
font-family: Arial Black, sans-serif;
font-size: 20px;
}
div.window label{
display: block;
width: 1%;
transition: all 0.75s 0.25s;
transform: rotate(0);
}
input.toggle ~ div {
height: 0px; margin: .1rem;
overflow: hidden;
transition: .6s all cubic-bezier(0.730, -0.485, 0.145, 1.620)
}
input.toggle:checked ~ div { height: 60px; }
input.toggle:checked + label { transform: rotate(180deg); }
input.toggle { display: none; }
When the toggle <img> is 'checked', I'd like it to rotate 180˚, however, I've had trouble making the image rotate on it's center axis. It currently rotates on it's edge: good for eliciting a chuckle... not so good for potential users.
Any help is very much appreciated!
Problem
The origin of your transformation is not the center of the image. So it rotates about the wrong reference point. See the following picture:
This picture is showing the result of rotating a square using transform: rotate(45deg) with different transform-origin values.
Solution
Normally just add transform-origin: center center; to the transform property (but to be honest, that's also the default value).
So your actual problem is that you specified the transition on the parent (of the image) what means it will take the center of the parent. Since you specified the width as 1% the center isn't the same as the center of the image. So to solve this I've felt free to change this to the width of the image (what is in this case width:200px;).
Alternatively you could specify the origin manually with absolute values (in your case transform-origin:100px 100px;).
See JSFiddle.

HTML circle div with image trying to get hovering text

I'm trying to get a square div that says "read more" when hovering over a circle div with a picture inside it. Been trying different things and haven't found a working solution on google.
HTML
<div class = "portfolio" id = "first"> <!-- makes the circle -->
<a href = "cake-page.html">
<div class = "readm"> Read more </a> </div>
<img src = "cake.jpg" />
<p> The cake </p> </div>
CSS
.portfolio {
/* the circles on the portfolio-page */
position: relative;
border-radius: 100%;
display: inline-block;
height: 150px;
width: 150px;
border: 2px solid purple;
}
.portfolio.img {
opacity: 1;
transition: 1s ease;
background-size: 90px 0px;
overflow: hidden;
border-radius: 100px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
width: 150px;
height: 150px;
}
.portfolio:hover {
/* hover effect on portfolio circles */
opacity: 0.6;
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
transition: 1 ease;
visibility: visible;
}
So either the text pushed the image down or it stays in the top of the circle and I can't get it to hover together with the other hover effect. I want the "read more" to pop-up in a rectangular div when hovering over together with the other hover effect.
I did not include the div class "readm" since I can't get it to work. FYI I'm pretty new to this. Thanks.
A little tough without a working example and it'd be good to see the readm css since we need to see what isn't working. That said, have you tried something like this:
.readm {
opacity:0;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}
.portfolio:hover .readm {
opacity:1;
}
Also I would place the start of that a tag inside the readm div.
First, you need to fix your markup.
You are closing the anchor ("a") tag before closing a DIV. That alone will make your CSS fail.
I presume you want to close the DIV like so:
<div class="readm">Read more</div>

WordPress image resize on hover

I have a wordpress website and I'd like to add some features that my current theme doesn't offer. I'd like the 3 images in the "Pages" section to reduce in size or switch to a different image (same content, smaller resolution) so as to appear smaller then you hover over it. I've managed to accomplish this with a custom HTML page, adding ID's to the images and then adding a version of this to my style.css for each image
#techbutton {
display: block;
width: 125px;
height: 125px;
background: url("http://rafsk.co.uk/wp-content/uploads/2015/10/Logo21-e1445171629993.png") no-repeat 0 0;
}
#techbutton:hover {
background: url("http://rafsk.co.uk/wp-content/uploads/2015/10/Logo2-hover-e1445296643552.png") no-repeat 0 0;
}
#techbutton span {
position: absolute;
top: -999em;
}
After uploading the custom HTML to my server I realised that instead of just overriding the homepage of rafsk.co.uk it also overrode the homepages of all my subdomains.
So how can I do this?
You could do this with a css transform, that would be the easiest way, and you can apply it to all three with a class instead of an id (which should only be used once per page):
So first give the same class to all of the images (meaning to the actual image tag, like <img class="imageclass" src="blah.png" />), and use this in your css:
.imageclass {
display: block;
width: 125px;
height: 125px;
transform: scale(1,1);
}
.imageclass:hover {
transform: scale(0.9,0.9);
}
You could then add a css transition effect if you want it to be smoother:
.imageclass {
display: block;
width: 125px;
height: 125px;
transform: scale(1,1);
transition: transform 0.6s ease-in-out;
}
.imageclass:hover {
transform: scale(0.9,0.9);
}
Here is a working example:
https://jsfiddle.net/f9teea7L/
ALTERNATIVE OPTION #1:
If you can't edit the HTML and can only get an image into the div through the background, you could try adding a background-size property like this. Be aware though that it won't work in IE 8 or lower:
#techbutton {
display: block;
background-image: url('http://vignette1.wikia.nocookie.net/deadliestfiction/images/d/d5/2138464123_1360632315.jpg/revision/latest?cb=20140513035922');
background-size: 100%,100%;
width: 125px;
height: 125px;
transform: scale(1,1);
transition: transform 0.6s ease-in-out;
}
#techbutton:hover {
transform: scale(0.9,0.9);
}
Working Example: https://jsfiddle.net/azx962a9/
ALTERNATIVE OPTION #2:
I've looked at your site though and if I'm understanding what you want to do, it seems to me that simply adding this to your css should work...:
.service-icon {
transform: scale(1,1);
transition: transform 0.6s ease-in-out;
}
.service-icon:hover {
transform: scale(0.9,0.9);
}

Remove applied CSS transformation

I have applied -webkit-transform:rotateY(180deg); to flip an image. I am applying -webkit-transform:rotateY(0deg); to rotate it back to original position. Now I have some other classes to be applied, but when I check in Chrome Inspect Element I can see that rotateY(0) is still there which should be completely removed.
How can I remove the animation completely from an Element?
.transition
{
-webkit-transform:rotateY(180deg);
transform:rotateY(180deg);
}
.notransition {
-webkit-transform:rotateY(0deg);
transform:rotateY(0deg);
}
just do this:
.transition {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.notransition {
-webkit-transform: none;
transform: none;
}
none seems to be the default value
.transition {
-webkit-transform:rotateY(180deg);
transform:rotateY(180deg);
}
.notransition {
-webkit-transform:unset;
transform:unset;
}
In my case i needed a way to override an inline transform that was being setted by third party component and i didn't want it to remove it manually.
According to Mozilla documentation, you can only transform elements:
Only transformable elements can be transformed. That is, all elements
whose layout is governed by the CSS box model except for: non-replaced
inline boxes, table-column boxes, and table-column-group boxes.
So, you can disable transform by just modifing display to a non-element one, I changed it to display:inline so the transform stops working:
.transition {
-webkit-transform:rotateY(180deg);
transform:rotateY(180deg);
}
.notransition {
display: inline;
}
Of course this will mess up with animation, however it's usefull when you are working with responsive CSS:
// small resolution / animation will stop working, and element will expand to the whole screen
.transition {
-webkit-transform:rotateY(180deg);
transform:rotateY(180deg);
}
.notransition {
display: inline;
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
}
// medium resolution / animation works
#media print, screen and (min-width: 40em) {
.notransition {
-webkit-transform:unset;
transform:unset;
}
}

Triangular image with CSS

I've searched everywhere for many weeks but I can't find an answer for my problem.
Is it possible to have an image inside a regular triangle?
I've seen many ways to create a shape or a mask, but I need a real triangle because I need to have several triangles next to each other, with some of them aligned upside-dwn, like in this= image:
http://www.tiikoni.com/tis/view/?id=d49c960
I've used color to divide the two types of triangle, but all of them have images instead colors.
I've tried using skewX, skewY and rotate, I have a sufficient result but it's not perfect:
<div class='pageTri2'>
<a href='#' class='option2'>
<img src='image.jpg'>
</a>
</div>
<style>
.pageTri2 {
overflow: hidden;
position: relative;
margin: 40px auto;
width: 250px; height: 250px;
display: inline-block;
}
.option2, .option2 img { width: 100%; height: 100%; }
.option2 {
overflow: hidden;
position: absolute;
transform: skewX(-25deg) skewY(45deg);
transform-origin: 50% 50% 0;
}
.option2:first-child {
transform-origin: 100% 0;
}
.option2:last-child {
transform-origin: 0 100%;
}
.option2 img { opacity: .75; transition: .5s; }
.option2 img:hover { opacity: 1; }
.option2 img, .option2:after {
transform: skewX(-20deg) skewY(-20deg) rotate(-50deg);
transform-origin: 0 100% 0;
}
.option2:first-child:after { top: 0; left: 0; }
.option2:last-child:after { right: 0; bottom: 0; }
</style>
Is it possible to have a perfect result?
Or maybe I'm thinking in the wrong direction?
Thanks
Ale
EDIT: I've done it!! Thanks to #Spudley for address me to SVG and thanks to #o.v. for the suggestion to use jsfiddle.
Here's my code: http://jsfiddle.net/wkJKA/
In all seriousness, having seen your mock-up image of what you're trying to achieve, I'd say drop the idea of doing it in CSS.
Stuff like this is much better done using SVG rather than CSS. CSS simply wasn't designed for creating complex shape patterns. It can do it, but it gets messy quickly, and for something like the effect you're after, you'll end up needing some extra HTML markup. SVG is designed for exactly this kind of thing, and does it well.
The only downside is lack of support for SVG in old IE versions, but there are work-arounds for this. (and in any case, old-IE support clearly isn't a priority for you, given that you're already using transform and other CSS that doesn't work with old IE)
use transparent png or simply do triangles with css. Here is a link to css shapes http://www.css3shapes.com
You could rely on specifics of border rendering to achieve a triangle-looking shape. The shape could then be added with pseudoelements.
.pointy:before {
border:50px solid transparent;
border-bottom:86px solid green;
border-top:0px solid transparent;/*renders looking like a triangle with 100px sides*/
width:0;
height:0;
display:inline-block;
content:"";
margin:0 -75px -5px 0; /*for a 50x50 icon*/
}
Fiddled