so I have a div which is a card and content in it. I achieved to make it moves up a bit but the transition property seems to not work.
Here is the HTML code
<div class="card">
<p> Title </p>
</div>
and here is the CSS code
.card:hover {
position: relative;
top: -10px;
transition: 1s;
}
So basically there is multiple cards and it works well every card with the .card class moves up when the mouse is over it, but it moves instantaneously, the transition does not work. Does anyone knows how to fix it? have a great day
This is because you have specified the position and transition only in the :hover block of code, meaning the transition timing is not specified until after the hover has already occurred. In other words, only the item that changes on hover (the top value) should be in the :hover.
Specify the position and transition outside the :hover block, like this for example:
.card {
position: relative;
transition: 1s
}
.card:hover {
top: -10px;
}
You can use transform: translateY
try this
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.box {
border: 1px solid black;
width: 150px;
height: 150px;
cursor: pointer;
transition: all .5s ease-in-out;
}
.box:hover {
transform: translateY(-10px);
}
<div class="box"></div>
Instead of playing with top which requires a positon attribute to move it out of flow, just add a margin to displace the element:
.card:hover {
margin-top: -20px;
margin-bottom: 20px;
transition: 1s;
}
/* for visualization purpose only */
body {
padding-top: 50px;
}
div {
border: 2px solid black;
display: flex;
justify-content: center;
align-items: center;
height: 40vh;
width: 10vw;
}
<div class="card">Card</div
Related
I wanted to make a landing page for fun, and see how to make it look better, and I figured that I could make a sentence with spinning text in the middle. I've added a GIF to let you guys see what I want it to look like. I did see another post on here similar to mine, but the person that replied had it messed up slightly
I tried using CSS scrolling text, but that made the entire sentence start moving. I tried putting the beginning and end in different DIVs but then they were all seperated.
It needs to be independent element but you can inline-block it. Within this also overflow:hidden element will be a bigger element to be scrolled inside.
h1 {
display: flex;
height: 40px;
/* to center: */
justify-content: center;
}
.scroll-container {
text-align: center;
display: inline-block;
overflow: hidden;
position: relative;
height: 40px;
/* border: 1px solid red; */
margin-left: 10px;
margin-right: 10px;
}
.text-inside .item {
height: 40px;
}
.text-inside {
margin-top: 0;
transition: 500ms;
animation: 3s infinite test;
}
#keyframes test {
0% {
margin-top: 0;
}
25% {
margin-top: 0;
}
50% {
margin-top: -40px;
}
100% {
margin-top: -80px;
}
}
<div style="inline-block">
<h1>Welcome to
<div class="scroll-container">
<div class="text-inside">
<div class="item">Paris</div>
<div class="item">Frankfurt</div>
<div class="item">Milano</div>
</div>
</div>, Joshua
</h1>
I have a block called case-card which consists of a child div called case-card__wrapper that houses text.
On case-card hover, I want the case-card__wrapper to move up slightly. Not in one action, but as transition.
I feel like I have the general idea, but unsure on how to get the transition to work? At the moment, it just phases from one spot to another:
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
position: absolute;
transition: 0.5s;
/*top: 0; Don't want to add this because I want the text to be centered in the div and rather not define a number since the div heights may vary */
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
top: 150px;
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
I'm trying to do this just via CSS. Any ideas?
If you cannot set initial value simply use transfrom. You can also remove position:absolute
.case-card {
height: 560px;
width:600px;
color: #ededed;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
transform: translateY(20px);
transition: all .3s ease-in-out;
background-color: #333;
overflow: hidden;
}
.case-card__wrapper{
transition: 0.5s;
}
.case-card__title{
font-size: 16px;
}
.case-card:hover .case-card__wrapper {
transform:translateY(-100%);
}
<div class="case-card">
<div class="case-card__wrapper">
<h4 class="case-card__title">Title</h4>
<p class="case-card__subtitle">Subtitle</p>
</div>
</div>
I'm using transition property in CSS in the navigation on my website. The navigation consists of 3 images. When you hover the image with the mouse, a transition is applied that displays an overlay with some text. This all works beautifully in Chrome and Firefox. Safari, however, is a mess. Not only does the transition behaviour not work at all, but no matter what I do, the menu stays on a second line rather than remaining on the first line with the logo (you'll see from the jsfiddle example what I mean if you open the fiddle in both Chrome and Safari).
CSS:
header nav a img {
width: 100%;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
}
.menuitem-content {
top: 15px;
padding: 5px;
margin: 0 auto;
width: 100%;
height: 100%;
position: absolute;
text-align: center;
vertical-align: middle;
color: #FFFFFF;
background-color: rgba(86, 81, 65, .8);
display: none;
transition: all 1.2s;
-webkit-transition: all 1.2s;
-moz-transition: all 1.2s;
font-size: 14pt;
z-index: 999;
left: 0px;
}
header nav a:hover > .menuitem-content {
display: inline-flex;
}
https://jsfiddle.net/35qnu4d1/
You might have to expand the output window a bit to see the menu and logo on the same line (which for our purposes is fine as the min resolution should be 1024x768 — this isn't build for mobile devices). Any ideas why it's behaving so weird in Safari?
Use http://caniuse.com/#search=flex, you need -webkit-... vendor prefixes for all flex properties.
display isn't animatable property. You can't apply transition to it. See this list of animatable CSS properties.
You don't need to use display: inline-flex with position: absolute — display: block is enough.
Check out my JSFiddle.
CSS:
header {
width: 100%;
background-color: #565141;
overflow: hidden;
display: -webkit-flex;
display: flex;
}
header nav a:hover > .menuitem-content {
display: block;
}
#content-body {
background-color: #efefef;
width: 97%;
padding: 15px;
display: -webkit-flex;
display: flex;
}
footer {
width: 100%;
background-color: #565141;
display: -webkit-flex;
display: flex;
}
I have these two images with corresponding labels: http://jsfiddle.net/Fdjtc/
I want to make it so that when I hover over one of the divs, the image animated downward and the text (initially invisible) animated downward and fades to full opacity, making the images and labels look like they do right now. How can I make sure that the images have enough space upwards to do this, and can I do this kind of animationg using CSS3's transition?
Are you looking for something like this:
http://jsfiddle.net/Fdjtc/9/
There are several ways of doing this. This example is using absolute positioning with transitions on top/bottom.
CSS:
div.wrap > img {
display: block;
position: absolute;
width: 200px;
top: 20px;
left: 20px;
-webkit-transition: top 500ms;
}
div.wrap:hover > img {
top: 5px;
}
div.wrap > span {
display: block;
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
opacity: 0;
-webkit-transition: bottom 500ms;
}
div.wrap:hover > span {
bottom: 2px;
opacity: 1;
}
Edit: (after your dynamic size request)
This is another way of doing it, using margins. Text caption is a bit of problem here but you will get the idea.
Updated Fiddle: http://jsfiddle.net/Fdjtc/11/
CSS:
div.wrap {
float: left;
text-align: center;
margin: 4px;
border: 1px solid gray;
}
div.wrap > img {
display: block;
text-align: center;
margin: 16px;
-webkit-transition: margin-top 500ms;
}
div.wrap:hover > img {
margin-top: 2px;
}
Based on what you wrote, I've came up with this for you:
http://jsfiddle.net/Fdjtc/6/
I've made quite a noticeable change to your html, too:
<div>
<img src="http://placekitten.com/256">
<span>Label 1</span>
</div>
Hopefully this is what you wanted, if not, please extend your question and be more descriptive.
Is this what you wanted to achieve ?
.box img
{
-webkit-transition:all 0.5s ease-in-out;
height:200px;
display:block;
margin-top:-200px;
}
.box:hover > img
{
margin-top:0px;
}
http://jsfiddle.net/4BtcR/
I have an animation on my site which goes from width: 100px to 800px when hover on.
But when hover out, it just goes to the normal position with no animation.
How could I get it so the animation would go back on hover-out the same way it came on hover?
I only found solutions for transitions, but I need it for animation.
<div id="blackbox"/>
<div id="blacktxt">
Navigation
</div>
See Here
Why not use transitions instead of animations? Working jsFiddle
#blackbox {
background: black;
width: 100px;
height: 80px;
color: white;
text-align: center;
font-family: Times;
font-size: 20px;
position: fixed;
left: 0px;
bottom: 100px;
opacity: 0.5;
margin-bottom: 10px;
transition: all 2s; /* Add this transition */
}
#blackbox:hover { /* Apply the new design on hover */
opacity: 0.8;
width: 800px;
}
#blacktxt {
margin-top: 10px;
height: 60px;
transition: opacity 0.5s, width 5s;
position: absolute;
font-family: cursive;
cursor: default;
}
#blacktxt:hover {
opacity: 0;
}
I wrote the jQuery Reversible plugin for this. Its main advantage over CSS transitions is that it works on IE9 and older browsers.