WordPress image resize on hover - html

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);
}

Related

How to apply hover effect on Material Icon?

I am using CSS modules for my project, but Material Icon is not making the changes specified via className prop
import SettingsIcon from "#mui/icons-material/Settings";
import css from "./LandingPage.module.css";
<SettingsIcon className = {css.settingsButton}/>
LandingPage.module.css file
.settingsButton{
position: absolute;
right: 20;
top: 20;
display: block;
height: 70px;
width: 70px;
transition: transform .7s ease-in-out;
color: white;
}
.settingsButton:hover{
transform: rotate(360deg);
}
The problem is the default transition property of .MuiSvgIcon-root is more specified than yours.
You need to increase the priority of your css in your module.css file using :global notation like this:
:global(.App) .settingsButton {
position: absolute;
right: 20;
top: 20;
display: block;
height: 70px;
width: 70px;
transition: transform 0.7s ease-in-out;
color: white;
}
:global(.App) .settingsButton:hover {
transform: rotate(360deg);
}
Note that, in this case .App exists my app, if it does not exist in your app, you can wrap your icon with another custom div with a specific className and use it instead of .App.
You can take a look at this sandbox for a live working example of this solution.

How to center my width/height transforms?

So, I was trying to get an image to, when hovered over, spin 360 degrees and scale up by 1.4, all with its centre staying in place. I tried this:
.logo img[data-v-4fbac4e1] {
width: 50px;
height: 50px;
content: url(https://i.imgur.com/txz1IXI.png);
transition: width 2.0s, height 2.0s, transform 2.0s;
}
with this:
.logo img[data-v-4fbac4e1]:hover{
width: 65px;
height: 65px;
transform: rotate(360deg);
}
and it works fine, but it moves off-centre as it expands. How do I make sure the width and height increase from the centre so it stays in the same place? Sorry if this seems elementary, I'm new to CSS.
Edit: the part of the HTML I'm using looks like this:
<a data-v-4fbac4e1 href="/home" class="logo">
<img data-v-4fbac4e1 src="/img/icons/icon.svg">
</a>
If more is required I can add it, but this is the HTML for the image I'm trying to transform.
Since I'm not entirely sure what you mean, point to which is your culprit and we'll get you sorted out but here's some examples of the differences between techniques.
img, div {
display: inline-block;
margin: 1rem;
height: 10rem;
width: 10rem;
}
.fancy-img1, .fancy-img3 {
object-fit: cover;
outline: red 2px solid;
}
.fancy-img2, .fancy-img4 {
background: url(https://picsum.photos/200) no-repeat center center / cover;
outline: blue 2px solid;
}
/* grow by height value change transition */
.fancy-img1 {
transition: transform .5s, height .5s;
}
.fancy-img2 {
transition: transform .5s, height .5s;
}
.fancy-img1:hover, .fancy-img2:hover {
transform: rotate(360deg);
height: 15rem;
}
/* Scale with transition */
.fancy-img3 {
transition: transform .5s;
}
.fancy-img3:hover {
transform: scaleY(1.5) rotate(360deg);
}
/* Scale with keyframes */
#keyframes spinGrow {
to { transform: scaleY(1.5) rotate(360deg); }
}
.fancy-img4:hover {
animation: spinGrow .5s forwards;
}
<h2>Are you talking about transition height which cause the jumpy effect?</h2>
<img class="fancy-img1" src="https://picsum.photos/200">
<div class="fancy-img2"></div>
<h2>Or actually scale so it remains in its original position?</h2>
<img class="fancy-img3" src="https://picsum.photos/200">
<div class="fancy-img4"></div>

How can a transformed Image transition back to it's original shape when hovered?

Hi i'm just a student I just wanna know if its possible to combine hover, transition, and transform by just using css.
How can transformed image transitioned back to it's original size and shape when hovered?
<html>
<style>
.sample {
display: inline-block;
border: 0px solid #fff;
margin: 10px;
overflow: hidden;
height: 500px;
width: 140px;
transform: rotate(0deg);
webkit-transition: 0.8s;
transition: 0.7s;
}
.sample img {
display: block;
transform: rotate(2deg);
transform-origin: 200% -600%;
}
.sample img:hover {
width: 600px;
height: 600px;
transform: rotate(0deg);
transform-origin: 0% 0%;
-webkit-transition-timing-function: ease-in-out;
}
</style>
<body>
<div class="sample">
<img src="http://www.freegreatpicture.com/files/39/1264-tree.jpg" height="600" width="600">
</div>
</body>
</html>
If you only define the CSS "transformed" rules in the hover pseudo-class, then when the image is no longer being hovered-over it will automatically transition back to its original state.
Here is a simplified example using part of your code (I changed the image to the Wikipedia logo since your image was coming up broken):
.sample img {
transform: rotate(30deg);
transition: ease-in-out 700ms;
}
.sample img:hover {
transform: rotate(0deg);
}
<div class="sample">
<img src="https://en.wikipedia.org/static/images/project-logos/enwiki.png">
</div>
The hover pseudo-class is an "active state class", meaning it only comes into play while that action is taking place (i.e., the pointer is hovered over the element).
If you want to include special easing and timing rules on the change from default state to hovered state then include the transition property in the default rule. You can specify lengths of time over which the transition takes place so the change can be more "animated". You'll notice that in the example above I stretched the rotation to 700ms so you can see it turning when hovered, then turning back when no longer hovered.

CSS Effect shrink from small to bigger

i really want to know how this effect is created.
check this video, only 12 secs.
https://youtu.be/cJqU8jW0xsg
i try with :
.zoom {transform:scale(0.1); }
.zoom:hover {transform:scale(2); }
how to make it start from (top-left) and will end at (bottom-right) just like that in the video?
thanks in advance..
What you're after is the transform-origin property.
Here's an example.
http://codepen.io/dropkick/pen/YqKzdG/
HTML
<div class="box"></div>
<button>click me</button>
CSS
.box {
background: #0f0;
width: 200px;
height: 200px;
margin: 20px auto;
transition: transform 0.5s linear;
transform-origin: top right;
transform-style: preserve-3D;
transform:scale(0.1);
}
.box-scale {
transform:scale(1.0);
}
button {
display: block;
margin: auto;
}
JS
$('.scale').click(function () {
$('.box').toggleClass('box-scale');
});
You need transform-origin! https://developer.mozilla.org/en/docs/Web/CSS/transform-origin
Setting the origin sets the start point for the transition. It'll grow out from there.

Similar command to "background-position" for divs/images in CSS

I want to style a metro-like gallery. I already achieved this in an example with background-images:
http://codepen.io/DanielCoding/pen/jlrgv
But I want to replace the background-images by ordinary image-tags in divs. Unfortunately all images are stretching themselves in the bottom-right direction:
http://codepen.io/DanielCoding/pen/fsKjE/
In the first code I resolved this by give the images different background-position values, but I don't know a similar command for simple image tags or divs.
You could use transform to scale the image and transform-origin to control the direction of the scale.
.star1:hover,
.star2:hover,
.star3:hover,
.star4:hover {
-webkit-transition: -webkit-transform 0.2s;
-webkit-transform: scale(1.2);
}
.star1:hover {
-webkit-transform-origin: bottom right;
}
.star2:hover {
-webkit-transform-origin: bottom left;
}
.star3:hover {
-webkit-transform-origin: top right;
}
.star4:hover {
-webkit-transform-origin: top left;
}
http://codepen.io/anon/pen/oxsge/
The most similar technique to "background-position" that you can use with simple images is "CLIP". Please, look at link in order to understand more about it.
I've replaced the background-images with simple img and check this out if this is what your looking for.
star1,
.star2,
.star3,
.star4{
background-size: 150px;
background-repeat: no-repeat;
background-clip: border-box;
transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
display: inline-block;
text-decoration: none;
cursor: pointer;
padding:0;
margin:0;
}
.star1:hover,
.star2:hover,
.star3:hover,
.star4:hover{
-webkit-transform: scale(1.2);
transform: scale(1.2);
}
Pen here