Hello I would like to transition only my css transform and nothing else. It hard to explain through text so check out my code below:
HTML:
<section class="success">
<ul>
<li>
<div class="circle-spin-wrapper">
<img src="ellipse_sm_blue.png" >
</div>
</li>
</ul>
</section>
CSS:
.circle-spin-wrapper {
transition: all 1s ease;
}
.success li:hover .circle-spin-wrapper {
transform:scale(1.25);
position: relative;
top: 95px;
}
As you can see, I have a div and when you hover over it, it scales by 1.25. It also moves down 95 px by, top: 95px;
The transition works, but it transitions both the scale(1.25) as well as the top: 95px.
I would like to make it so the transition (transition: all 1s ease;) only works on the transform:scale(1.25) and not the top: 95px.
I know it has something to do with the "all" keyword in the transition css, but I dont know what to replace it with to only target the transform.
I tried replacing "all" with "transform" and "scale" and it didn't work.
Does anyone have any suggestions?
Thanks!
I tried replacing "all" with "transform" and "scale" and it didn't work.
Replacing "all" with "transform" is exactly what you should be doing - that will result in the transition applying only to the transform property. It's tough to debug why it isn't working without seeing the rest of the code - can you set up a quick CodePen?
.circle-spin-wrapper {
transition: transform 1s ease;
-webkit-transition: -webkit-transform 1s ease;
}
.success li:hover .circle-spin-wrapper {
transform: scale(1.25);
position: relative;
top: 95px;
}
<section class="success">
<ul>
<li>
<div class="circle-spin-wrapper">
<img src="test.jpg">
</div>
</li>
</ul>
</section>
this should work. note: "-webkit-transition: -webkit-transform 1s ease;" is for safari
.circle-spin-wrapper {
transition: transform 1s ease;
}
But it looks buggy since .circle-spin-wrapper has no width set, so it's the full width of the page, which means .circle-spin-wrapper becomes 125% of the width of the page and the image inside moves out of the page.
Solution? Set a width on .circle-spin-wrapper.
As you said, instead of all in your transition use transform. It is working actually!
Maybe its the vendor prefixes that you are missing. Try adding that too.
.circle-spin-wrapper {
transition: transform 1s ease;
}
.success li:hover .circle-spin-wrapper {
transform:scale(1.25);
position: relative;
top: 95px;
}
<section class="success">
<ul>
<li>
<div class="circle-spin-wrapper">
<img src="http://placehold.it/50x50" >
</div>
</li>
</ul>
</section>
Related
I have a website, on it, links that container img tags will transition the opacity for the image tag to be less than 100%. This seems to work well with all images except for one and it only happens on ONE page. At the bottom of this page http://www.saerdesigns.com/ there is a VetPros imag, when I hover over it on Chrome (unsure of other browsers), the transition stops and starts and ultimately looks very bulky. It doesn't appear to do this with any other images on the same page, and also, the image in this page using the same stylesheet file appears to work fine http://www.saerdesigns.com/jobs.
Here is my relevant CSS:
a {
text-decoration: none;
-webkit-transition: all 0.5s linear;
-moz-transition: all 0.5s linear;
-ms-transition: all 0.5s linear;
-o-transition: all 0.5s linear;
transition: all 0.5s linear;
&:hover, &:active, &:link {
text-decoration: none;
}
}
a {
img {
#extend a;
&:hover {
opacity: 0.8;
}
}
}
And here is the HTML code (it might look weird, but that's because I am using Angular):
<section class="container-fluid buffer" id="scroll-send-3">
<div class="center-block text-center" ng-show="jobs[0]">
<div class="row">
<div ng-repeat="job in jobs" class="col-md-4 job">
<a ui-sref="^.jobs.show({id: job.id})">
<img class="img-responsive center-block" alt="{{job.company}}" ng-src="{{job.image_small}}"/>
</a>
<ul>
<li>{{job.title}}</li>
</ul>
</div>
</div>
<div class="btn-group">
<a class="btn btn-default btn-lg" ui-sref="^.jobs">Work history</a>
</div>
</div>
</section>
How can I prevent this from happening? And why is this happening?
Thanks so much!
~The :hover works fine if you add position: relative;.
Maybe better to add transform: translate3d(0, 0, 1px); instead. I think the issue is because you are using opacity.
I don't have the explanation at hand right now, would have to go digging. Maybe tomorrow I can find the explanation again.
I have 2 images on top of each other, positioned absolute, in my example they are square but in my real project they are pngs with some transparency in the borders so the one in the back needs to be hidden until it appears on hover.
My problem is I need the transition to have some kind of delay so that the back pic appears a bit before the one on top so you don't see the background in between. I have made a fiddle to illustrate this:
http://jsfiddle.net/L21sk0oh/
You can clearly see the red from the background, that shouldn't happen. Also there is some weird moving going on, I haven't noticed this in my actual project.
Also my HTML:
<div class="product1">
<img class="active" src="http://lorempixel.com/400/200/sports" alt="">
<img class="inactive" src="http://lorempixel.com/400/200/" alt="">
</div>
And my css:
body{
background: red;
}
.product1{
position: relative;
width: 400px;
height: 200px;
}
img{
position: absolute;
top:0;
left:0;
}
.product1 img.active{
transition: all 1s ease-in-out;
opacity: 1;
}
.product1 img.inactive{
transition: all 1s ease-in-out;
opacity: 0;
}
.product1:hover img.active{
opacity: 0;
}
.product1:hover img.inactive{
opacity: 1;
}
You could specify a value for the transition-delay property.
In this case, I added a 1s delay to the transition shorthand of .product1 img.active:
Updated Example
.product1 img.active {
transition: all 1s 1s ease-in-out;
opacity: 1;
}
The above is equivalent to:
.product1 img.active{
transition: all 1s ease-in-out;
transition-delay: 1s;
opacity: 1;
}
Make sure you're adding the transition shorthand properties in the correct order.
How would I go about hovering over an image that then blurs the background image behind it within css? The way I have it set up now is the background image blurs upon hover.
Here's my css:
.blur img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.blur img:hover {
-webkit-filter: blur(5px);
}
.wrapper{
width:900x;
height: 100px;
position: absolute;
top: 2400px;
z-index: 50;
}
.logo{
postion: absolute;
margin: 0 auto;
top: 2420px;
z-index: 50;
left: 400px;
}
html:
<div class="blur"><img src="/homepic1.jpg"></div>//This is the image I want blurred
<div class="wrapper">
<div class="row">
<div class="span12 pagination-centered">
<img src="/transparanetsnu.png">//How do I hover over any of these images to trigger a blur on "homepic1.jpg"
</div>
<div class="span4 offset3">
<div class="box2"><img src="/greek_logo.gif"></div>
</div>
<div class="logo"><img src="/UM-Main-Logo-Maroon.gif">
</div>
I think the best way is to use JQuery. All images and add a class like 'blur' to them everytime user hover over one image, but you should remove the class from the one you don't want.
$('.img1').mouseover(function(){
$('img').addClass('blur');
$('.img1').removeClass('blur');
});
Add the effect using css or javascript.
Use jQuery for that purpose.
First of all dowload jQuery from: http://code.jquery.com/jquery-1.10.2.min.js
Then.
$('.yourImage').mouseover(function(){ //'.yourImage' are the last three images in your case.
$('.homepic1').addClass('blur'); //'.homepic1' is the class of first image in your case
});
.addClass('blur') , Will add the class 'blur' from your CSS to that '.homepic1' element, As soon as your mouse hovers over ANY of the three images.
Heres where I'm at:
http://codepen.io/qdarkness/pen/FyIJh
Ideally, how I imagine it at least, is when a user hovers over the <a> that the <div>'s "img-holder" and "tag" both have a transition to color, with the "img-holder" showing a "+" in the middle.
I'm suspecting the fact that I have the <img> inside the <div> that it is not working properly, but I am using that div to constrain the img width and height.
I'd prefer not to add additional divs, is this possible by just apply a class, like i attempted to, to the <div>?
HTML:
<li class="b c d">
<a href="" class="link">
<div class="img-holder overlay"><img src="img/test.jpg"></div>
<div class="tag overlay">
<h3>test</h3>
<h4>test</h4>
</div>
</a>
</li>
CSS:
.img-holder {
width: 235px;
height: 195px;
overflow: hidden;
}
.tag {
clear:both;
position:relative;
float:left;
width: 100%;
overflow:hidden;
background-color: #FFF;
text-align: center;
-webkit-transition: 1s;
-moz-transition: 1s;
-ms-transition: 1s;
-o-transition: 1s;
transition: 1s;
}
a:hover .overlay {
background: #909090;
z-index: 301;
}
OK, I THINK I have an understanding of what you want to do...
I've forked your Codepen sketch: http://cdpn.io/uzfrk
Main points are to position the overlay absolute over your image (relative to .link), and then transition opacity to have it appear.
<old example removed>
UPDATED: fresh sketch with cleaned up markup and styling. Simple example for your purposes.
Codepen sketch here: http://cdpn.io/zhBcA
The main point is the direct child selector to target elements related to your container.
figure:hover > figcaption {
background: #ccc;
}
figure:hover > .overlay {
opacity: 0.85;
}
Let me know if this is what you are looking for.
Could this be what you want? It's just a simple approach.
UPDATE:
Covering text area now.
http://codepen.io/anon/pen/tlKCJ
I'm trying to understand the simplest background transition possible using only HTML5 and CSS3. Searching through stackoverflow I've learned it can be easily implemented using external libraries such as jQuery but for this project I've decided not relying on any of those.
Markup
<nav>
<ul>
<li><a id="foobar" href="http://www.google.com/search?q=foobar">Foobar</a></li>
</ul>
</nav>
Styles
body {
background: url('background-default.png'), no-repeat;
}
#foobar a:hover {
background: url('background-hover.png'), no-repeat;
-webkit-transition: // TODO;
-moz-transition: // TODO;
-o-transition: // TODO;
-ms-transition: // TODO;
transition: // TODO;
}
As I mentioned in my comment, you can't transition the background-image property but you can get the sort of effect you're looking for if you're willing to add extra markup and then transition the opacity. So you'll have some markup like this:
<nav>
<ul>
<li>
<img src="no-icon.png">
<img src="yes-icon.png">
<a id="foobar" href="http://www.google.com/search?q=foobar">Foobar</a>
</li>
</ul>
</nav>
Then set the transition on the images, absolute position them (so they'll be like backgrounds), and hide one of them by default (I've left out the vendor extensions for clarity):
nav li img {
position: absolute;
transition-duration: 1.5s;
opacity: 1;
}
nav li img:first-child {
opacity: 0;
}
Then swap the opacity values on li:hover:
nav li:hover img {
opacity: 0;
}
nav li:hover img:first-child {
opacity: 1;
}
Here's a full working example. Not an ideal solution because you have to add extra markup, but it'll work.
Here's an example of the code I use to achieve this. The images are sprites which each contain normal and hover state. The trick is to add the img to both li and a, and to use opacity to change the appearance of the image. You can then use css3 transitions to make this appear smoother.
<ul id="homenav">
<li class="h"><a href="#><span>Home</span></a></li>
<li class="i"><span>Inloggen</span></li>
<li class="v"><span>Voorbeelden</span></li>
</ul>
#homenav li.h, #homenav li.h a {background-image: url('img/btn_home.gif');}
#homenav li.i, #homenav li.i a {background-image: url('img/btn_inloggen.gif');}
#homenav li.v, #homenav li.v a {background-image: url('img/btn_voorbeelden.jpg');}
#homenav li {background-position: 0 170px;}
#homenav li a {background-position: 0 0;}
#homenav li a:hover
{opacity: 0;
-webkit-transition: opacity .8s ease-in;
-moz-transition: opacity .8s ease-in;
-o-transition: opacity .8s ease-in;
transition: opacity .8s ease-in;}
#homenav a {display: block; height: 100%;}
#homenav a span {display: none;}