I have a simple language select page with pure CSS animated transitions. I've made a jsFiddle here.
How it's supposed to behave is as follows:
User mouses over one of two (or more) language selectors.
That language selector transitions upward and comes to full opacity. The relevant language text (e.g., English, Español) appears as well.
The user either clicks on the link or mouses out, in which case the transition reverses.
In Chrome, it behaves as expected.
In Firefox, when I mouse over one image, both move up.
In Opera, it behaves mostly as expected, but the text jumps back down after moving up.
I'm trying to understand why this would happen in these browsers, and how I can fix it, if possible.
In the case that jsFiddle is down, the relevant code is:
HTML
<div id="container"><div id="cell">
<div class="langcell"><a href="en/index.html">
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/200px-Flag_of_the_United_States.svg.png" /><br/><p>English</p></a>
</div>
<div class="langcell"><a href="es/index.html">
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/9/9a/Flag_of_Spain.svg/200px-Flag_of_Spain.svg.png" /><br/><p>Español</p></a>
</div>
</div></div>
CSS
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#container {
width: 100%;
height: 100%;
display: table;
}
#cell {
display: table-cell; vertical-align: middle; text-align: center;
}
.langcell {
display: inline-block;
margin: auto 1em;
}
a {
position: relative;
top: 0;
-webkit-transition: top 0.25s;
-moz-transition: top 0.25s;
-o-transition: top 0.25s;
transition: top 0.25s;
color: black;
text-decoration: none;
}
a:hover {
top: -16pt;
}
a p {
font-size: 14pt;
font-weight: bold;
text-transform: uppercase;
font-family: Verdana, Geneva, sans-serif;
letter-spacing: 0.05em;
opacity: 0;
-webkit-transition: opacity 0.25s;
-moz-transition: opacity 0.25s;
-o-transition: opacity 0.25s;
transition: opacity 0.25s;
}
a:hover p {
opacity: 1;
}
a img {
opacity: 0.65;
-webkit-transition: opacity 0.25s;
-moz-transition: opacity 0.25s;
-o-transition: opacity 0.25s;
transition: opacity 0.25s;
}
a:hover img {
opacity: 1;
}
I got weird problems on firefox(v12) as well, where it was moving both elements up on hover. Later versions (19v), it seemed resolved.
I think there was something going on with your selectors and how mozilla interprets things versus webkit. See if this jsfiddle works for you.
All I really did was change a lot of the selectors of a to .langcell and it seem to work. I had to re-adjust a bit of css to achieve the same style, like the nested .langcell a selector. I have a suspicion that it may be due to a being inline by default while p is block and img is inline-block.
I won't lie and say I understand fully why that was happening to begin with, but just in general, giving styles to classes over elements is not just a preference, it is more efficient at render time as well.
CSS Selector Performance
Code:
.langcell {
display: inline-block;
margin: auto 1em;
position: relative;
top: 0;
-webkit-transition: top 0.25s;
-moz-transition: top 0.25s;
-o-transition: top 0.25s;
transition: top 0.25s;
}
.langcell a {
color: black;
text-decoration: none;
}
.langcell:hover {
top: -16pt;
}
.langcell p {
font-size: 14pt;
font-weight: bold;
text-transform: uppercase;
font-family: Verdana, Geneva, sans-serif;
letter-spacing: 0.05em;
opacity: 0;
-webkit-transition: opacity 0.25s;
-moz-transition: opacity 0.25s;
-o-transition: opacity 0.25s;
transition: opacity 0.25s;
}
.langcell:hover p {
opacity: 1;
}
.langcell img {
opacity: 0.65;
-webkit-transition: opacity 0.25s;
-moz-transition: opacity 0.25s;
-o-transition: opacity 0.25s;
transition: opacity 0.25s;
}
langcell:hover img {
opacity: 1;
}
CSS3 is pretty new. And many of the features are still not compatible in many browsers. Compatibility Chart
So it is kind of off-putting if your clients have a bit older browsers (even if they have a year old version), in which case CSS3 transition wont work.
Your safest bet to make the transition is to do it using javascript or some javascript library such as jQuery
Related
I have an input field with a placeholder. On focus of it, I need a transition of placeholder and it should stay at a different position.
I cannot modify the HTML as it's getting generated from a plugin.
I have achieved the transition, but the placeholder disappears after it.
Need it by CSS-only.
Demo
.container {
margin-top: 80px;
}
input {
width: 500px;
font-size: 16px;
}
input::-webkit-input-placeholder {
-webkit-transition: all 0.3s ease, font-size 0.3s ease;
transition: all 0.3s ease, font-size 0.3s ease;
}
input:hover::-webkit-input-placeholder {
-webkit-transition: all 0.3s ease, font-size 0.3s ease;
transition: all 0.3s ease, font-size 0.3s ease;
}
input:focus::-webkit-input-placeholder {
-webkit-transform: translateY(-40px);
transform: translateY(-40px);
-webkit-transition: all 0.4s ease, font-size 0.4s ease;
font-size: 12px;
transition: all 0.4s ease, font-size 0.4s ease;
}
<h3>Todo: Make placeholder persistent</h3>
<div class="container">
<input type="text" placeholder="This placeholder should stay" />
</div>
Since we cannot change the HTML we will have to use a pseudo-element...and a new pseudo-class to target the .container when the input receives :focus
:focus-within
The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus
.container {
margin-top: 80px;
position: relative;
}
.container::before {
content: "This placeholder should stay";
position: absolute;
font-size: 16px;
color: grey;
top: 0;
opacity: 0;
}
.container:focus-within::before {
font-size: 12px;
top: -100%;
opacity: 1;
transition: all 0.4s ease;
}
input {
width: 500px;
font-size: 16px;
}
input:focus::-webkit-input-placeholder {
opacity: 0
}
<h3>Todo: Make placeholder persistent</h3>
<div class="container">
<input type="text" placeholder="This placeholder should stay" />
</div>
You need to achieve this effect with the inputs <label>. You can't achieve it with a placeholder as this is how placeholders work, you can't not hide them when there is focus.
If you position: absolute the <label> over the input then you can transform: translateY() it to achieve the same effect you have there.
Edit: To add this should provide you slightly better UX and accessibility by doing this with a label instead of relying on the placeholder as well.
This is also a very simple version of what you want to achieve: http://plnkr.co/edit/WCdSajNRyM4mj4GBXCHh?p=preview
I've a h1 text that is very faded on a background. Once you roll over it / hover over the block that it is in, it slowly start to light up until it is completely white. This is great and just like I want it to be. Here's the problem. Once you leave the hover, the color goes back to being faded. I'd like for it to stay white as the whole point of having it faded is that it should not be in your sight until you are hovering past it.
TL:DR / When I hover a h1 it starts to light up, I want the new color to remain after you remove the hover.
The HTML I use
<h1 style="color: #fff;">Sammen flytter vi<br> de digitale grænser.</h1>
The CSS I use
.lovernemarketingtitle h1 {
font-size: 50px;
line-height: 54px;
font-weight: 900;
opacity: 0.5;
}
.lovernemarketingtitle:hover h1 {
opacity: 1;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-out;
-ms-transition: all 1s ease-out;
transition: all 1s ease-out;
}
SOLUTION BY PRAVEEN KUMAR
http://jsbin.com/dufarofoto/1/edit?html,css,output
Use transition-delay, but beware, improper use affects the hovered state as well.
a {text-decoration: none; display: inline-block; padding: 5px; border: 1px solid #ccc; border-radius: 3px; line-height: 1; color: #000; transition: all 0.5s linear 2s;}
a:hover {transition: all 0.5s linear 0s; background: #ccf;}
Hover Me<br />
Lights up immediately but goes back after 2 seconds.
ps: There's no opacity: 2.
I want to replicate the effect of the that you see in the pictures here: http://www.akqa.com/work/
I thought this was the code necessary for it but it doesn't work. What is missing?
div {
opacity .4s,transform .4s
}
There are three things wrong here.
Firstly opacity .4s,transform .4s is not a valid CSS declaration.
The correct syntax looks like this:
div {
-webkit-transition: opacity .4s ease .4s;
transition: opacity .4s ease .4s;
}
Secondly, a transition rule implies that there are different values for the first and second instance (a point A and point B if you will). In the example below, you will notice that I have specified opacity:0; unless the div has a class .showing in which case it now has a rule that states opacity:1;
div {
opacity: 0;
-webkit-transition: opacity .4s ease .4s;
transition: opacity .4s ease .4s;
}
div.showing {
opacity: 1;
}
Lastly, you will also require something to change the state of the div to "let it know it needs to change it's opacity". We already told it in the CSS above that when it has a class .showing it's opacity is different.
A nice way to do this is to add a tiny jQuery script to give it the new class once the page has fully loaded.
jQuery(window).load(function(){
$('div').addClass('showing');
});
Are you focus on the text popup effect after mouse over the image? If yes, i did some trace from the html and css file.
<article class="work-item in-view" ...>
<picture>
<source></source>
<source></source>
<source></source>
<img></img>
<div class=content>
/* pop up text content*/
</div>
</picture>
</article>
.work-item {
background-color: #000;
cursor: pointer;
float: left;
overflow: hidden;
position: relative;
width: 100%
}
.work-item .content {
background-color: rgba(0,0,0,0);
bottom: 0;
color: #FFF;
height: 100%;
left: 0;
padding: 0 30px;
pointer-events: none;
position: absolute;
right: 0;
top: 0;
-webkit-transition: background-color .4s;
transition: background-color .4s;
width: 100%
}
I hope this findings may help you.
If the direction is correct, you can grep 'work-item' and 'content' from the css and follow the logic.
I am using SquareSpace, and I am trying to add custom CSS to 3 images on my cover page. Currently on hover the images change opacity, and then a blue block appears with the title of the image. I am trying to make the blue block larger, but also make sure the block is trim to the actual image. As you can see in the following image, there is a little overhang:
Any help would be appreciated!
.sqs-gallery-block-grid .slide .margin-wrapper .image-slide-title {
display: block;
position: relative;
top: -15px;
text-align: center;
opacity: 0;
background-color: #1E75BB;
margin-bottom: 0px;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
.sqs-gallery-block-grid .slide .margin-wrapper:hover .image-slide-title {
display: block;
opacity: 50;
background-color: none;
text-align: center;
width: 100%;
}
.sqs-gallery-block-grid .slide .margin-wrapper .image-slide-title {
font-family: adelle-sans;
font-size: 16px;
color: #fff;
text-transform: uppercase;
}
.sqs-gallery-block-grid .slide .margin-wrapper:hover .image-slide-title {
font-family: adelle-sans;
font-size: 16px;
color: #fff;
text-transform: uppercase;
}
#media only screen and (max-width: 75px) {
.sqs-gallery-block-grid .slide .margin-wrapper .image-slide-title {
opacity: 50;
}
}
The thing is each image has different dimensions and share a common class (div.image-slide-title).
There are 2 ways I could think of, either photoshop all images to equal dimensions (say 248px wide as the last one) and impact div.image-slide-title with the same as above, only this time 248px width should work for all of them.
Or, isolate each image with a new class/id (example: div.image-slide-title-1, div.image-slide-title-2 & div.image-slide-title-3) and give it the following in addition to the proper width:
margin: 0 auto; to center.
Give the image's width to the blue block (example: last one should be width: 248px;)
I'm trying to scale the :before content of my <span> when hovering over it. So far the style gets applied when hovering but there are no visual changes, the :before remains the same scale.
What I've got so far:
<div class="comment-actions">
<span class="comment-likes icon-ico-heart">
12
</span>
</div>
SASS (CSS):
.comment-likes
transition: all 100ms ease-in-out
color: #92a3b9
cursor: pointer
&:hover::before
transform: scale(1.5)
Icomoon:
.icon-ico-heart:before {
content: "\e914";
}
[class^="icon-"], [class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
Increase the font-size on hover and add transition property to it.
.icon-ico-heart:before {
font-size: 10px;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.icon-ico-heart:hover:before {
font-size: 15px;
}
You can use just transition: font 0.3s ease; to apply transition only for font instead of all
Don't transform it with the scale property but use the font-size. So:
.icon-ico-heart:hover:before {
font-size: 20px;
}
You may not able to use the scale property for fonts or icon fonts,
Instead of this you can use font size property.
You can't transform the ::before element because it's display type is: display: inline,
you have to change it to display: inline-block or another.
.icon-ico-heart:before {
content: "\e914";
display:inline-block;
}