Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move an entire div element up x pixels?

I want to reposition an entire div and its contents up about 10-15 pixels.

How can I do this?

Note: this is slider element, so when I click a button the slider slides down. Once it is finished I want to reposition it up about 15 pixels.

like image 772
codecompleting Avatar asked Aug 22 '11 19:08

codecompleting


People also ask

How do I move an entire div to the right?

If you want to move the div container, make sure the container is set as position "relative." Then adding style="float: right;" will work. If you want to only move the div within that container, then you need to use float="right" on that particular element (object) instead of positioning it with a style.

How do I move a div horizontally?

Answer: Use the CSS margin property If you would like to center align a <div> element horizontally with respect to the parent element you can use the CSS margin property with the value auto for the left and right side, i.e. set the style rule margin: 0 auto; for the div element.

How do you put an element above another in CSS?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).


1 Answers

$('#div_id').css({marginTop: '-=15px'}); 

This will alter the css for the element with the id "div_id"

To get the effect you want I recommend adding the code above to a callback function in your animation (that way the div will be moved up after the animation is complete):

$('#div_id').animate({...}, function () {     $('#div_id').css({marginTop: '-=15px'}); }); 

And of course you could animate the change in margin like so:

$('#div_id').animate({marginTop: '-=15px'}); 

Here are the docs for .css() in jQuery: http://api.jquery.com/css/

And here are the docs for .animate() in jQuery: http://api.jquery.com/animate/

like image 104
Jasper Avatar answered Oct 02 '22 14:10

Jasper