I positioned a form to the right of a document showing only a part of it
<form class="right-form">
<textarea></textarea>
<input type="submit" value="submit"></div>
</form>
and I styled like this(simplified example)
body{
height: 100%;
width: 100%;
}
.right-form{
position:absolute;
rigth: -220px;
width: 250px
transition: width 0.5s ease 0s, right 0.5s ease 0s;
}
.right-form:hover{
right: 0px;
}
Everything works well except the scroll bar at the bottom appears to scroll left to the right when the form is hidden, and I do not want it to appear. Someone knows how to deal with this css problem? Hope the problem is understandable...
Thanks a lot
EDIT:
with the overflow rule proposed by matthias.p the user can still press the arrow key pad a scroll to the right
Add
overflow: hidden;
to the body rule.
Edit:
You could do this:
body {
height: 100%;
width: 100%;
}
.right-form {
position:absolute;
right: 0;
width: 30px;
overflow: hidden;
transition: width 0.5s ease;
}
.right-form:hover {
width: 250px;
}
Instead of changing the right value I have changed the width of the form and did the overflow on the form instead on the body. Now you cannot use the arrow keys anymore to display the form when not hovering.
Usage of overflow does still allow the usage of arrow keys..
You can kill the usage of arrow keys like this:
$(document).keydown(function(event) {
switch(event.keyCode){
case 37:
case 39:
return false;
break;
}
});
Use the below code, the 100% + the default margin is causing the issue
body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.right-form{
position:absolute;
rigth: -220px;
width: 250px
transition: width 0.5s ease 0s, right 0.5s ease 0s;
}
.right-form:hover{
right: 0px;
}
Related
Im trying to understand CSS Transition - but I cant make it happen. I want to make a line go from 0 to 100% width with a small delay on pageload. I understand that CSs transition needs a trigger, and tried to read up to a jQuery or Vanilla Js solution, but get stuck.
Why is this ot working? Jsfiddle: https://jsfiddle.net/1fzzgnwy/
<div class="container">
<span class="h-line"></span>
</div>
.h-line {
position: absolute;
z-index: -1;
width: 0%;
height: 10px;
right: 0;
background-color: #000;
top: 400px;
transition: right 1.5s linear;
transition-delay: 2s;
}
.h-line.ready {
width: 100%;
background-color: #000;
}
.container {
height:100%;
width:100%;
}
$(function(){
$('.h-line').addClass('ready');
});
In your transition line, you are telling it to transition right, but that doesn't change in the added class. Your width does. So you need to transition the width like transition: width 1.5s linear;: JS Fiddle
And if you want it to expand left to right, remove right: 0: JS Fiddle
In your jsfiddle link (https://jsfiddle.net/1fzzgnwy/) there are some errors.
Here a simplified example of your code that work https://jsfiddle.net/50t3qwmL/ .
.h-line {
position: absolute;
top: 0;
right: 0;
width: 20px;
height: 20px;
background-color: #000;
transition: .3s;
transition-delay: 2s;
}
.h-line.ready {
width: 100%;
}
I have a div .box with which has absolute position set at the bottom of the parent div. It does not have the top position set because the height differs for different .box divs. On hover over the parent div, I want to change its top position to 0 with the transition effect.
In the following code transition does not work if I do not define the top position by default. I have tried using top: auto and it still does not work. How can I use transition without defining the top position.
Here's my code:
HTML:
<div class="wrap">
<div class="box">
Box
</div>
</div>
CSS:
.wrap{
position: relative;
height: 200px;
width: 200px;
background: green;
}
.box{
background: yellow;
position: absolute;
bottom: 0;
left: 0;
transition: all 0.9s ease 0s;
top: 50%; /*== does not work without it ==*/
}
.wrap:hover .box{
top: 0;
bottom: 0;
}
Fiddle: http://jsfiddle.net/5hs09apn/
A slight different approach than using top: http://jsfiddle.net/5hs09apn/2/
set the height for the box, and on hover set it to 100%; let the bottom be zero, so you don't even need to use top
.box{
background: yellow;
position: absolute;
bottom: 0;
left: 0;
height:20px;
transition: all 1s ease 0s;
}
.wrap:hover .box{
height:100%;
bottom: 0;
}
.wrap {
position: relative;
height: 200px;
width: 200px;
background: green;
}
.box {
background: yellow;
position: absolute;
bottom: 0;
left: 0;
height: 20px;
transition: all 1s ease 0s;
}
.wrap:hover .box {
height: 100%;
bottom: 0;
}
<div class="wrap">
<div class="box">
Box
</div>
</div>
Add Top property in JQuery getting the current value of the Top of the .box using position().
This will be dynamic allocation of Top and will not effect your condition of varying .box height.
While doing this, you will have to add the hover effect in the JQuery part too, since the Top will be defined here and CSS wont know what to do with the hover.
Check the Fiddle here
This is the JQuery function added:
$(document).ready(function(){
var x = $('.box').position();
var myTop = x.top;
$('.box').css("top",myTop+"px");
$('.box').css("transition","all 0.9s ease 0s");
$('.wrap').bind('mouseover',function(){
$('.box').css("top","0px");
$('.box').css("bottom","0px");
});
$('.wrap').bind('mouseout',function(){
$('.box').css("top",myTop+"px");
$('.box').css("bottom","0px");
});
});
Hope this gives you what you need.
You can use:
.wrap:hover .box{
margin-bottom: 100%;
}
And try with different percentages until you get one you like. It's crude but I think it can work.
Main question
I have two divs, one nested inside the other and i wish to shift inner div outside (upwards) of outer div and slide-in it on a hover.
Markup is looking like so:
<div class="body">
<div class="inner">Green is variable-height text which slides in on viewport hover</div>
Blue is a viewport (<body>, visible part of a page), which content should be compressed upon green slide-in
</div>
And (a little pseudo) css:
.body {
background: #aaf;
height: 300px;
width: 300px;
overflow: hidden;
}
.inner, .body:hover .inner {
-webkit-transition:all linear 0.2s;
transition:all linear 0.2s;
}
.inner {
background: #afa;
width: 300px;
margin-top:-some-magic-to-get-this-div-height;
}
.body:hover .inner {
margin-top: 0;
}
And a final result animation i'd like to get, without using fixed height of green div:
Also, this example (with a guessed and hard-coded height value of 2.5em) on jsfiddle to experiment with:
http://jsfiddle.net/n7vyLoh4/20/
Possible partial work-around (not satisfactory)
It is possible to partially implement what i want, using transitioning max-height instead of transitioning margin-top, the transition of max-height: 0; -> max-height: 100%; with overflow: hidden; set at all times
works, but has two draw-backs:
it doesn't slide in, it's more like drops the curtain
it doesn't stop transition at the end of green div, it transits till the end of outer blue div, which especially noticeable at reverse transition, when it first travels all the way from bottom of blue div to bottom of green div before any effect is visible. Also, this means that despite transition time set to 0.2s, it will spend only fraction of this time on transiting trough green div, because this 100% are 100% of parent div, not inner one (and my question could be answered if there is a way to calculate the 100% of inner div height).
Here is an illustration:
And fiddle for that:
http://jsfiddle.net/bsd7vnwu/1/
This is the pure css solution, which means it does not require any scripts, just a browser that support transitions:
.body {
background: #aaf;
height: 300px;
width: 300px;
overflow: hidden;
}
.inner {
-webkit-transition:all cubic-bezier(0,.81,.4,1) 0.5s;
transition:all cubic-bezier(0,.81,.4,1) 0.5s;
}
.inner {
background: #afa;
width: 300px;
position: absolute;
margin-top: -100%;
float: left;
}
.body:hover .inner {
position: relative;
margin-top: 0;
}
And Fiddle is here
I think this is the effect you want. CSS doesn't allow you to get the height of an element to use in calc() for positioning and margins, so a little JS is needed.
CSS:
.body {
background: #aaf;
height: 300px;
width: 300px;
overflow: hidden;
}
.inner, .body:hover .inner {
-webkit-transition:all linear 0.2s;
transition:all linear 0.2s;
}
.inner {
background: #afa;
width: 300px;
overflow: hidden;
}
.body:hover .inner {
margin-top : 0 !important;
}
JS:
Array.prototype.forEach.call(document.getElementsByClassName('inner'), function (item) {
item.style.marginTop = (item.clientHeight * -1) + 'px';
});
Demo:
http://jsfiddle.net/09tyLr9b/
I added transition to your fiddle to get what i think you are looking for
.inner {
background: #afa;
width: 300px;
overflow: hidden;
max-height: 0;
transition:0.5s ease-out;
}
.body:hover .inner {
max-height: 100%;
transition:0.5s ease-in;
}
JSFIDDLE
and by lowering the time for transition:ease-out you will get a more responsive slide up when you mouse out of the div
like this JSFIDDLE
Another CSS solution after 2.5 years, using flex layout:
.body {
background: #aaf;
height: 300px;
width: 300px;
overflow: hidden;
}
.inner {
display: flex;
align-items: flex-end;
-webkit-transition: all cubic-bezier(0, 1, 0, 1) 0.5s;
transition: all cubic-bezier(0, 1, 0, 1) 0.5s;
background: #afa;
max-height: 0;
overflow: hidden;
}
.body:hover .inner {
-webkit-transition: all ease-in-out 0.5s;
transition: all ease-in-out 0.5s;
max-height: 100%;
}
<div class="body">
<div class="inner">Green is variable-height text which slides in on viewport hover</div>
Blue is a viewport (<body>, visible part of a page), which content should be compressed
Also on JSFiddle.
Okay so the question was a bit difficult to word but I'm gonna try and explain this as clearly as possible.
I have a "pan on mouse hover" effect that I am trying to achieve. Everything is correct so far except the image pans to the left on mouse hover. I want it to start on the right of the image and pan to the right.
Simply changing the margin-left to margin-right perimeter doesn't work because the image is still aligned to the left within the 421x840 box.
So my question is, how do I align the image to the right within the box, so that when I hover the mouse, it pans to the right -150px and reveals the left part of the image.
I appreciate any help in advance. Thank you.
HTML code:
<div class="sidepan pic">
<img src="http://dvqlxo2m2q99q.cloudfront.net/000_clients/192648/file/19264814292KWf1.jpg" ></img>
</div>
CSS code:
.pic {
border: 0px;
position: absolute;
float: left;
height: 840px;
width: 421px;
margin: 0px;
overflow: hidden;
}
.sidepan img {
margin-left: 0px;
-webkit-transition: margin 1s ease;
-moz-transition: margin 1s ease;
-o-transition: margin 1s ease;
-ms-transition: margin 1s ease;
transition: margin 1s ease;
}
.sidepan img:hover {
margin-left: -150px;
}
Swapping margins it does the trick:
.sidepan img {
margin-left: -150px;
}
.sidepan img:hover {
margin-left: 0px;
}
Fiddle: http://jsfiddle.net/7ava1y31/42/
Ok so i have my tex in my div, and i set my div to move but i need my text to stay on the same place, can anyone help me with this?
<div id="nav_bar_menu">
<div id="pocetna" ><div class="moving_background_nav_bar_img"><p id="pocetna_paragraf">POCETNA</p></div></div>
</div><!-- Menu -->
and here is my css
#nav_bar_menu {
height: 38px;
width: 580px;
float: right;
margin-left: 25px;
margin-right: 25px;
margin-top: 93px;
overflow: hidden;
}
.moving_background_nav_bar_img {
background: url(../Images/images/nav_bar_pictures_01.jpg);
-moz-transition: top 0.7s;
-webkit-transition: top 0.7s;
-o-transition: top 0.7s;
transition: top 0.7s;
position: relative;
height: 76px;
top: 0;
}
#pocetna {
height: 38px;
width: 131px;
}
.moving_background_nav_bar_img:hover {
top: -38px;
position: relative;
}
here is picture how it should look like http://i.imgur.com/0HhAiGT.png
if i set position fixed for text then if i scroll down it is still on its position on page... i dont want nav bar to follow me on scroll.
All you need to do add the fixed positioning to the ID of the paragraph
#pocetna_paragraf{
position:fixed;
}
Ok That's right the text wont move down when you scroll down. I'm sorry I released that later Anyway I tried different method but the problem when you hover over the text the ease effect will not work and when you hover over the image will work perfectly.
Hope someone will figure out what we need to do. Here is the code
CSS:
a#one {
width:64px;
height:64px;
display:block;
text-indent:-9999px; /* hide the text */
background:url(background.png) top left;/* Do not forget to set your own image*/
}
a#one:hover {
background-position:bottom left;
}
a#one {
width:64px;
height:64px;
display:block;
text-indent:-9999px; /* hide the text*/
background:url(background.png) top left;
-moz-transition:background 300ms ease-in-out;
-webkit-transition:background 300ms ease-in-out;
transition: background 300ms ease-in-out;
}
#two{
position:absolute;
top:25px;
left:25px;
}
HTML:
Hover image
Text
Basically I made two links I hid the first one text with text-indent and made the background ease. This second one is just to show the link without scrolling up and down.