I'm making a div on top of the tweet (and also the Facebook like) button. I want it to move up as soon as I hover above the div (button) so you can actually press the real tweet button. I've tried the following.
HTML:
<div class="tweet-bttn">Tweet</div>
<div class="tweet-widget">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
CSS:
.tweet-bttn{
position: relative;
top: -30px;
left: -10px;
display:block;
opacity: 1;
width: 80px;
padding: 10px 12px;
margin:0px;
z-index:3;}
.tweet-bttn:hover{
-webkit-animation-name: UpTweet;
-moz-animation-name: UpTweet;
-o-animation-name: UpTweet;
animation-name: UpTweet;
-webkit-animation-duration:.5s;
-moz-animation-duration:.5s;
animation-duration:.5s;
-webkit-transition: -webkit-transform 200ms ease-in-out;
-moz-transition: -moz-transform 200ms ease-in-out;
-o-transition: -o-transform 200ms ease-in-out;
transition: transform 200ms ease-in-out;}
#-webkit-keyframes UpTweet {
0% {
-webkit-transform: translateY(0);
}
80% {
-webkit-transform: translateY(-55px);
}
90% {
-webkit-transform: translateY(-47px);
}
100% {
-webkit-transform: translateY(-50px);
}
... and all other browser pre-fixes.
}
I'm not sure what's going wrong. It looks like that as soon as I hover, it moves, but if I move the cursor one more pixel, it has to do a new calculation which causes the flickering.
I don't know why you need animations for this when you can simply achieve the above using transitions
The trick is to move the child element on parent hover
Demo
div {
margin: 100px;
position: relative;
border: 1px solid #aaa;
height: 30px;
}
div span {
position: absolute;
left: 0;
width: 100px;
background: #fff;
top: 0;
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
}
div span:nth-of-type(1) {
/* Just to be sure the element stays above the
content to be revealed */
z-index: 1;
}
div:hover span:nth-of-type(1) { /* Move span on parent hover */
top: -40px;
}
Explanation: Firstly we wrap span's inside a div element which is position: relative;
and later we use transition on span which will help us to smooth the flow of the animation, now we use position: absolute; with left: 0;, this will stack elements on one another, than we use z-index to make sure the first element overlays the second.
Now at last, we move the first span, we select that by using nth-of-type(1), which is nothing but first child of it's kind which is nested inside div, and we assign top: -40px; which will transit when the parent div is hovered.
Related
super beginner here. I'm trying to get an image caption to show on hover so I've set the opacity to 0 on the .caption class then 100% on the .caption:hover (not sure if this is best practice but it's the only way i could get it to work...)
Anyway, I'm now trying to get the caption to ease in & out on hover. I've tried adding transition: 0.5s ease-in-out; to both the .caption and the .caption:hover class. Adding it to the .caption:hover class makes it so it only eases in (then jumps straight back to its original state when i move my cursor away). Adding it to the .caption class works, however the caption shows briefly when I reload the page as well as when I hover over the image. I only want it to show on hover.
Any help would be appreciated!
CSS
.caption {
opacity: 0%;
position: absolute;
top: 20px;
left: 20px;
width: 318px;
height: 318px;
background: white;
transition: 0.5s ease-in-out;
}
.caption:hover {
opacity: 100%;
}
HTML
<div class="caption">
<h2 class="artname">Caption 1</h2>
<h3 class="artcategory">Caption2</h3>
</div>
p {
width: 100px;
height: 100px;
background: red;
opacity:0;
transition: opacity 2s;
transition-timing-function: ease-in-out;
visibility:hidden;
}
div:hover > p {
opacity:1;
visibility:visible;
}
div{
height:100px;
}
<div>
<p></p>
</div>
I've coded it in css where if you hover over a div it expands and show more details about the div, the issue is that whenever I remove the mouse some of the color is still left as lines, I'll attach a picture.
This is the css code where movie card is the details and movie is the div to hover on
.movie-card{
transition: 500ms ease-in-out;
background-color: #a851ff;
opacity: 0;
visibility: hidden;
border: 1px solid #a851ff;
}
.movie-box-content:hover .movie-card{
transition-delay: 250ms;
transition-duration: 500ms;
visibility: visible;
opacity: 1;
}
This is the result of hovering over:
And this is after removing the mouse over it:
its worth noting that after I scroll once, all the lines get removed.
Removing the transition: 500ms ease-in-out; from the movie-card class gets rid of the spurious 'shadows'.
.movie-box {
position: relative;
display: block;
width: 300px;
height: 168.75px;
}
.movie-box-content {
transform: scale(1);
transition: 500ms ease-in-out;
background-image: url('https://wallpaperaccess.com/full/1508305.jpg');
background-repeat: no-repeat;
background-size: 300px 168.75px;
width: 100%;
height: 100%;
rborder-radius: 2%;
}
.movie-box-content:hover {
transition-delay: 250ms;
transition-duration: 500ms;
transform: scale(1.3);
border: 1px solid #a851ff;
box-shadow: #a851ff;
}
.movie-card {
/* transition: 500ms ease-in-out;*/
background-color: #a851ff;
opacity: 0;
visibility: hidden;
}
.movie-box-content:hover .movie-card {
transition-delay: 250ms;
transition-duration: 500ms;
visibility: visible;
opacity: 1;
}
<div class="movie-box">
<div class="movie-box-content">
<div style="width: 100%; height: 100%;"></div>
<div class="movie-card hidden">
<div class="text-center">
<strong>Drama, psycho, crime</strong>
</div>
</div>
</div>
</div>
There is the question of whether this alters anything else visually.
Incidentally, changing scale(1.2) to scale(i) where i is an integer also seemed to remove the problem which perhaps indicates difficulty with mapping CSS pixels (which can take up several display pixels each) so that as the div scales down it 'leaves behind' parts of the CSS pixel. It would be good if someone could explain this phenomenon.
I don't think it's necessary to have both visibility and opacity change as they essentially achieve the same thing. As you have a general transition set on the class, perhaps the two are interfering with each other.
if you hover over a project some text will appear, but if you mouse over the text it kills the hover style because that's not what triggers the hover.
p.description {
position:absolute;
top:50%;
left:50%;
margin: 40px 0 0 -125px; /*offset 50px from center*/
transform: translateY(-50%); /*vertically centered*/
width:250px;
height:80px;
z-index:1000;
color: #ffffff;
opacity: 0;
}
.holder:hover p.description {
margin-top: 0; /*makes me slide up*/
opacity:1;
visibility:visible;
-moz-transition: all .2s ease-in;
-o-transition: all .2s ease-in;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
p.description span {
font-family: 'aileronbold';
font-size: 110%;
}
This is my css for trying to accomplish this. I am not sure how to re-target to achieve this. Everything works as I want it minus when you mouse over the text.
You can check this at: http://darrenbachan.com/
Change the selector from .holder a:hover to .holder:hover a. You were seeing this flicker issue because the transition would end when you hover over the p description element that would transition in. By moving the :hover pseudo class to the parent element, the transition will remain intact even when you aren't hovering over the a element:
.holder:hover a {
opacity: 0;
-moz-transition: all .2s ease-in;
-o-transition: all .2s ease-in;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
In order for the anchor element to be positioned over the p description element, you could absolutely position it relative to .holder (since it's relatively positioned).
.holder a {
position: absolute;
z-index: 10;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
Then remove z-index: 1000 from p.description.
It is a z-index issue:
z-index: 9999; /* Or anything more than 1000 */
Give the above z-index to .grow:
.grow {
z-index: 9999;
}
And just because you are using transition, that jerk happens. Guess there's no way.
Change
.holder:hover p.description
to
.holder:hover p.description, p.description:hover
A little bit of a hack, but it'll work.
P.S. Love the site! Very pretty.
Change
.holder a:hover {
opacity:0;
}
To
.holder:hover a {
opacity:0;
}
The key point is to prefix all hover style's selector with .holder:hover.
I am setting up a new homepage for my website. It will have a 2x2 grid of four images that change size with the window and they'll all have a hover text. I was able to do everything so far but I got stuck at one point, which possibly have an easy answer that I can't find. When I hover over the image, I want to make the text centered, no matter what the size of the window is. But I can not find the proper way to do it. The methods I've tried either don't center it both vertically and horizontally or the text goes off center when I resize the window. Any help would be appreciated. Thank you!
Here's my code: jsfiddle
HTML
<section id="photos">
<img src="image1"><span>GALLERY ONE</span>
<img src="image2"><span>GALLERY TWO</span>
<img src="image3"><span>GALLERY THREE</span>
<img src="image4"><span>GALLERT FOUR</span>
</section>
CSS
#photos {
/* Prevent vertical gaps */
line-height: 0;
margin-left:150px;
-webkit-column-count: 2;
-webkit-column-gap: 0px;
-moz-column-count: 2;
-moz-column-gap: 0px;
column-count: 2;
column-gap: 0px;
}
#photos img {
/* Just in case there are inline attributes */
width: 100% !important;
height: auto !important;
}
a.darken {
display: inline-block;
background: black;
padding: 0;
position:relative;
}
a.darken img {
display: block;
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
-ms-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
}
a.darken:hover img {
opacity: 0.3;
}
a.darken span{visibility:hidden; font-size:16px;}
a.darken:hover span{color:#fff; visibility:visible;
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
-ms-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
}
This wont work in older browsers, but you can use a combination of "translate" and absolute positioning to vertically and horizontally align the text. Just add the following:
a.darken span{
visibility:hidden;
font-size:16px;
/* new styles below: */
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
line-height: 100%;
}
Here is an example:
http://jsfiddle.net/bk2Sd/2/
You need to add these styles to the <span>:
position: absolute;
top: 50%;
left: 35%;
You can play with these values until you get it where you want. Here is a working example.
Since your a.darken selector already has relative positioning enabled, you can enable absolute positioning on the span attribute.
http://jsfiddle.net/EfrainReyes/bk2Sd/4/
a.darken span {
display: block;
height: 100%;
width: 100%;
visibility:hidden;
position: absolute;
top: 50%;
font-size:16px;
}
I added display: block and full height and width so I could use text-align: center on the a.darken selector.
I propose something little more generic.
Since the size of the images is not known we can center horizontally the text using the text-align property and then centre it vertically by using an absolutely positioned element with top set to 50%.
Code to add:
a.darken span {
width: 100%;
text-align: center;
top: 50%;
left: 0
position: absolute;
}
http://jsfiddle.net/bk2Sd/5/
I'm trying to rotate the double angle bracket set as the content in an :after pseudo-element using the css transform value rotate(90deg) for a tab across the top of the screen. Here's the relevant code:
.header {
-moz-transition: top .5s ease;
-webkit-transition: top .5s ease;
-o-transition: top .5s ease;
transition: top .5s ease;
position: absolute;
left: 0;
right: 0;
top: -60px;
height: 80px;
background-color: #2d2;
}
.header.in-top {
top: 0;
}
.header-tab {
position: absolute;
bottom: 0;
width: 100%;
height: 20px;
text-align: center;
color: #000;
-moz-transition: color .5s ease;
-webkit-transition: color .5s ease;
-o-transition: color .5s ease;
transition: color .5s ease;
}
.header-tab:hover {
color: #e22;
}
.header-arrow:after {
font-size: 20px;
line-height: 1;
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.header .header-arrow:after {
content: "\00bb";
}
.header.in-top .header-arrow:after {
content: "\00ab";
}
<div class="header">
<div class="header-tab" data-toggle="in-top">
<span class="header-arrow"></span>
</div>
</div>
The data-toggle attribute is used in JavaScript to toggle the in-top class in order to switch the direction of the double angle bracket as well as to expose the content of the header by bringing it down. The transform properties I have specified seem to do nothing though. Any solutions?
Use display: inline-block on the pseudo-element. Alternatively, inline-table or block should also work.
See jsFiddle.
Your pseudo-element is displayed inline by default, which makes it a nontransformable element. From the CSS Transforms Working Draft specification:
transformable element
A transformable element is an element in one of these categories:
an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose ‘display’ property computes to ‘table-row’, ‘table-row-group’, ‘table-header-group’, ‘table-footer-group’, ‘table-cell’, or ‘table-caption’
You need to set the pseudo-element as a block or inline-block element:
.header-arrow:after {
display: block;
}
The specification says rotation should work on inline elements, but in WebKit based browsers it doesn't works: https://www.webkit.org/blog/130/css-transforms/
Rotate property will apply on pseudo-element(after/before) only when you will use display:inline-block; or display:inline-block; property in your class or selector.
.className:before{
-webkit-transform: rotateZ(180deg); /* Safari */
transform: rotateZ(180deg); /* Standard syntax */
display: inline-block;
}