CSS3: Prevent transition-delay when transition is reversed - html

I'm trying to create an effect where:
The cursor hovers over a box
The bar slides out
As the sliding motion eases out a title appears
The cursor leaves the box
The title begins to disappear as the bar slides back
The bar finishes sliding back
But instead when the cursor leaves the box the delay is invoked again so the title fades out as the bar finishes it's transition back which looks ugly. How can I achieve the desired effect?
HTML:
<div class="slidingbar">
<h1 class="slidingbar-content" id="title">My Awesome Web App</h1>
</div>
CSS:
.slidingbar{
width: 50px;
height: 50px;
transition: width 2s;
-webkit-transition: width 2s;
}
.slidingbar .slidingbar-content{
margin: 0px;
opacity: 0;
white-space: nowrap;
overflow: hidden;
transition: opacity 1s 1s;
-webkit-transition: opacity 1s 1s;
}
.slidingbar:hover{
width: 100%;
}
.slidingbar:hover .slidingbar-content{
opacity: 1;
}

You can set different transitions in the base state and in the hover state.
In this case, the delay should be only in the hover state, and the base state should be un-delayed.
.slidingbar .slidingbar-content{
margin: 0px;
opacity: 0;
white-space: nowrap;
overflow: hidden;
-webkit-transition-property: opacity;
-webkit-transition-duration: 0.5s;
-webkit-transition-delay: 0s;
-webkit-transition-timing-function: linear;
transition-property: opacity;
transition-duration: 0.5s;
transition-delay: 0s;
transition-timing-function: linear;
}
.slidingbar:hover .slidingbar-content{
opacity: 1;
transition-delay: 1.5s;
-webkit-transition-delay: 1.5s;
}
demo

If i understood the instructions, try applying the transition on the same element... like this
HTML
<div class="slidingbar">
<h1 class="slidingbar-content" id="title">My Awesome Web App</h1>
</div>
CSS
.slidingbar{
border: 1px solid #cccccc;
height: 50px;
}
.slidingbar-content{
width: 50px;
margin: 0px;
white-space: nowrap;
overflow: hidden;
opacity: 0;
transition: opacity 1.5s, width 2s ;
-webkit-transition: opacity 1.5s, width 2s;
}
.slidingbar-content:hover{
width: 100%;
opacity: 1;
}
Hope it help you

Related

weird color stain from css

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.

Center both elements like "display: none;"

.Button_Image {
width: 40px;
-webkit-transition: opacity 0.5s linear;
-moz-transition: opacity 0.5s linear;
-ms-transition: opacity 0.5s linear;
-o-transition: opacity 0.5s linear;
opacity: 1;
}
.Button:hover .Button_Image {
opacity: 0;
}
.Button_Name {
font-size: 18px;
color: black;
line-height: 40px;
-webkit-transition: opacity 0.5s linear;
-moz-transition: opacity 0.5s linear;
-ms-transition: opacity 0.5s linear;
-o-transition: opacity 0.5s linear;
opacity: 0;
}
.Button:hover .Button_Name {
opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<a href="#" class="Button btn btn-success btn-block">
<img class="Button_Image" src="https://i.stack.imgur.com/hiAkR.png">
<span class="Button_Name">Football</span>
</a>
I have a button which has 2 elements inside.
Image of a sport
Name of the sport
When either of these have the css value display: none; the visible one is aligned to center perfectly.
But I needed to add a fade-in-out functionality, so I wasn't able to use display keyword. Instead I went for opacity.
Which resulted these 2 elements to stay side by side even if one is hidden.
How can I center these, when the other one is hidden?
This image has been captured during the transmission event:
The current state is like this:
But I need it like this:
You can achieve what you want with absolute positioning of the image. Is something like this what you want?:
.sportbtn {
border: green 1px solid;
width: 150px;
height: 40px;
position: relative;
line-height: 40px;
}
.sportimg {
/* centered in button */
width: 30px;
transition: left 1s, margin-left 1s;
position: absolute;
left: 50%;
margin-left: -15px; /* half the image width */
margin-top: 5px;
}
.sportname {
transition: opacity 1s;
opacity: 0;
margin-left: 40px;
}
.sportbtn:hover .sportname {
opacity: 1;
}
.sportbtn:hover .sportimg {
margin-left: 0px;
left: 5px;
}
<div class="sportbtn">
<img class="sportimg" src="https://d30y9cdsu7xlg0.cloudfront.net/png/23344-200.png" />
<span class="sportname">Football</span>
</div>

CSS3 - Opacity transition is not working

I'm trying to change a div opacity depending on having the class active or not.
When the div has the active class, I want to change the opacity to 1. If the div does not have the active class, I want to change the opacity to 0.
Follows my CSS code:
.high-light{
position: fixed;
width: 100%;
height: 100%;
top: 0;
background-color: black;
background-color: rgba(0, 0, 0, 0.61);
opacity:0;
left: 0;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 3s linear;
}
#multicanvasArea.active .high-light {
opacity:1;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 0.5s linear;
}
Thank you
[EDIT]
One of the problems was that I change the css property to "block" and "none". The other was solve by the answer choosen.
When the div has the active class, I want to change the opacity to 1. If the div does not have the active class, I want to change the opacity to 0.
You need to combine the classes like so.
As it was you have .highlight as a child of .active.
.high-light{
position: fixed;
width: 100%;
height: 100%;
top: 0;
background-color: black;
background-color: rgba(0, 0, 0, 0.61);
opacity:0;
left: 0;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 3s linear;
}
.high-light.active {
opacity:1;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 0.5s linear;
}
The problem here is not the transition, it's the height 100% which is not taking effect because the parent element (body) is not tall 100%.
$('button').on('click', function(e) {
$("#multicanvasArea").toggleClass('active');
})
.high-light{
position: fixed;
width: 100%;
height: 30px;
top: 0;
background-color: black;
opacity:0;
left: 0;
color: white;
transition: opacity 3s linear;
}
#multicanvasArea.active .high-light {
opacity:1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="multicanvasArea">
<p class="high-light">Highlight</p>
<p class="">Other text</p>
</div>
<button>Toggle class</button>
Your code was 95% there, just a few tweaks I made seem to do the trick. Here is the new css:
#multicanvasArea .high-light{
position: fixed;
width: 100%;
height: 100%;
top: 0;
background-color: black;
background-color: rgba(0, 0, 0, 0.61);
opacity:0;
left: 0;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
transition: opacity 3s linear;
}
#multicanvasArea.active .high-light {
opacity:1;
}
Here is a link to a pen with a working example:
http://codepen.io/anon/pen/pEjrJo
this is a working example. The Javascript is only to toggle the class.
.box {
width: 200px;
height: 200px;
background: pink;
opacity: 0;
transition: opacity 3s linear;
&.active {
opacity: 1;
}
}
https://plnkr.co/edit/RZRygZieCUMVWiOVEJR8?p=preview

how can i set this button to appear with the transition

in my present code, button initially is visible and with the transition, it becomes hidden behind the box. What i want is "my button initially should be hidden and should appear with the transition". Thanks in advance..
P.S. No jQuery
<!DOCTYPE HTML>
<body>
<div id="anim">
</div>
<input type="button" value="this should be behind" id="btn" />
</body>
</html>
<style>
#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}
#anim:hover{
height:400px
}
#btn{
z-index: -1;
position:fixed;
margin-top: 300px;
}
</style>
You can set the opacity of the button on hover without changing the structure of your document using the adjacent sibling selector.
Here's how:
#anim:hover + #btn
{
opacity: 1;
}
Edit: You can also delay this using transition-delay on the button:
#btn
{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}
Below is the complete CSS, as some changes were also made to initially hide the button, and to properly set the z-index property.
JSFiddle here.
#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}
#anim:hover{
height:400px
}
#anim:hover + #btn{
opacity: 1;
}
#btn{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}
I think this is what you want:
#anim{
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: width 2s ease;
-moz-transition: width 2s ease;
-ms-transition: width 2s ease;
-o-transition: width 2s ease;
transition: width 2s ease;
}
#anim:hover{
width: 600px;
}
#btn{
margin-left: 100px;
margin-top: 100px;
opacity:0;
-webkit-transition: opacity 2s linear;
-moz-transition: opacity 2s linear;
-ms-transition: opacity 2s linear;
-o-transition: opacity 2s linear;
transition: opacity 2s linear;
}
#anim:hover #btn{
opacity:1;
}
and add your button inside #anim div, just like this:
<div id="anim">
<input type="button" value="this should be behind" id="btn" />
</div>
and all this without javascript, only css.
JSBIN

CSS - tooltip only with css and html doesn't work

I am trying to do simple tooltip only with css3 and html, but the transition doesn't work. What am I doing wrong?
HTML
<p>
This has tooltip
</p>
<div class="tooltip">Tooltip content</div>
CSS
p {
width: 200px;
background-color: aqua;
padding: 10px;
margin-top: 50px;
}
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: 0px;
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
display: block;
opacity: 1.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
http://jsfiddle.net/MCDg4/
Update / Alternate solution
For a modern browser CSS3 solution you could use pseudo elements..
<span data-tooltip="I am the tooltip">This has a tooltip</span>
and
[data-tooltip]{
position:relative;
}
[data-tooltip]:before{
content:attr(data-tooltip);
position:absolute;
bottom:110%;
padding:10px;
background:#666;
opacity:0;
color:white;
font-size:smaller;
-webkit-transition:opacity 1s ease;
-o-transition:opacity 1s ease;
transition:opacity 1s ease;
pointer-events:none;
}
[data-tooltip]:hover:before{
opacity:1;
}
Demo at http://jsfiddle.net/BJ2tr/
(this could be done without pseudo-elements by nesting the tooltip inside the elements that it refers to, and adjusting the css accordingly)
Unfortunately when you change display from none to something else, you cannot have transitions.
Instead of display:none you could just offset it outside of the window (with top:-9999px) and bring it to position when showing it.
div.tooltip {
position: absolute;
width: auto;
padding: 10px;
background-color: rgba(0,0,0, 0.5);
top: -999px; /*CHANGED THIS AND REMOVED display:none*/
display: none;
opacity: 0.0;
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
p:hover + div.tooltip {
opacity: 1.0;
top: 0px; /*ADDED THIS AND REMOVED display:block*/
transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-moz-transition: opacity 1s;
}
This will, however, not fade out (only in) since it moves it away on mouseout (so it actually does fade but you do not see it because it is outside the viewport)..
Explanation
You put transition only on opacity, while when changing to display:block; it is shown as a block with opacity:1; by default.
Solution
(JSFiddle)
Delete the display:none; and display:block on your tooltip element.