I need an div that will be always at the bottom of the page, margin 172px at the left, and 383px at the right.
This div will have some images and text and left and right buttons. When you hover the mouse at the right button, for example, the content that was "invisible", after reaching the div's width limit, will start appearing from the right, sliding the content for the left.
I tried using position:fixed; bottom:0px, but I couldn't margin the div, and the width of it doesn't change when the screen size changes...
For example, this would be exactly what I want (the black div at the bottom):
If you know any jquery plugin that does what I want or if you know how to do something like this, please help me!
If you're using position: fixed, margin can not be applied. You can specify the left and right attributes though.
position: fixed;
right: 383px;
bottom: 0;
left: 172px;
I know it's not exactly what you're asking for, but you can then set the white-space and overflow attributes on that div to make it so that it will show a horizontal scrollbar.
white-space: nowrap;
overflow: auto;
The user would use the scrollbar on the bottom to move the content of the div. Here's an example: http://jsfiddle.net/rustyjeans/5nv84/
To use jQuery set overflow: hidden and add some functions that adjust the scrollLeft of the div, then add some controls that call those functions when they're hovered. Here's an example: http://jsfiddle.net/rustyjeans/FtSGn/
This shouldn't be too hard to do. You want a containing div that has the dimensions of the viewer. Then, have a div inside that one, with position absolute and dimensions that extend beyond the viewer in width. When the arrows are hovered over use jquery to change the "left" css property of the inner div. Did that help?
EDIT:
The outer div should have "position: relative;" to insure that the inner div is positioned relative to its margins.
Related
Currently, I have a block with a scrollable div tag inside it on the left side: https://paste.pics/2b27787ffd9e5671df4d34b0b656ba2a
I want to scroll the div tag on the left side of the attached image when the mouse hovers on the right side of the attached image (brown background),
how can this be done?
check Find mouse position relative to element to catch cursor position on your right panel
using right panel size you'll easily compute position in % if need
compute the visible box of your left panel from cursor center position and change properties scrollTop and scrollLeft of your left panel accordingly
https://developer.mozilla.org/fr/docs/Web/API/Element/scrollTop
div {
width: 300px;
height: 200px;
overflow-y: scroll
}
<div></div>
without js you can able to scroll with fix height of div and css overflow property
I have three divs aligned vertically and want the middle div to fade in and out with javascript by animating the opacity and setting 'display: none;'. However when I do this it causes the bottom div to move down the page to make room for the middle div.
How can I make the bottom div a constant height below the top div independent of whether the middle div is displayed or not?
You'll want to use visibility: hidden; instead of display: none;
visibility: hidden; hides an element, but it will still take up the same space as before.
I have a container div of other divs and I am trying to animate container divs position. Normally I can achieve this animating thing but I got a problem now. I am trying to animate this div to the center of the screen because there will be some other content( which I want to hide with the help of container div) behind the container div when it is animated to the center, and if it is not fixed at the center, the contents (which are behind the container div) becomes visible from left and/or right of the container.
when I set the container divs position as;
CSS:
#cont{ position:absolute; right: auto; left: auto; top: 130px;}
Container div appears at center and doesn't move when browser zoomed. This is the position that I want to have after animation.
Then I set the divs first position and the javascript animation like this;
CSS:
#cont{ position:absolute; right:20px; left: auto; top: 130px;}
This css works for me. Container's initial position is just perfect for me.
JS:
$('.open').on('click', function(){
$('#cont').animate({"right":"auto"},1000)});
But when I click on the '.open' element. Nothing happens.
Normally the JS codes works because I tried to change positions like that:
setting initial position in css like right:auto; and setting in JS like "right":"20px"
This is the fiddle that I have problem, not animating position:
http://jsfiddle.net/ctarimli/B9h2w/3/
This is the fiddle which I tried reverse (I set initial "right" and "left" as auto; and then changed in JS)
http://jsfiddle.net/ctarimli/B9h2w/5/
So, why the div is not animating the position in the first fiddle?
You can't animate to an auto value - how should the JS animate to it? Suppose you start from 20px, what values should it use to interpolate? 21..22..23.. or 19..18..17.. (it can't determine what the "target" value should be)
As you stated in your comment, you want it to be centered afterwards. Try giving the #cont a fixed width (like width: 150px;). Then animate to a right position of 50% (right: 50%) and correct the margin with an appropriate margin-right: -75px; like so:
$('.open').on('click', function() {
$('#cont').animate({
"right":"50%",
"marginRight":"-75px"
}, 1000)
});
See Fiddle: http://jsfiddle.net/B9h2w/17/
I have two divs whose widths are controlled by percentages. I want the right div to be exactly as tall as the left div, which expands and shrinks based on the width of the image it contains and the width of the browser window.
Is there a way to accomplish this without javascript?
http://jsfiddle.net/5JU2t/
The simplest way to achieve this is to make the .right div absolutely positioned and setting top and bottom to 0.
Just remember to position the parent (.main) div relatively and remove all of the floats:
.right {
bottom:0;
position: absolute;
right:0;
top: 0;
}
.main {
position: relative;
}
Working example: http://jsfiddle.net/5JU2t/1/
Note
The reason the right column is a little longer in the example is due to the white space added under an image. Should you only be using an image in this column then you can add float: left to the image to resolve this:
Working example: http://jsfiddle.net/5JU2t/2/
I'd try wrapping it in a third div and give your two divs either height:auto or height: 100%.
Set the parent (.main) to display as table
and set the children (.right, .left) to display as table cell.
I would say funk all the extra css and use a table layout
First, here's is my rough example: http://demindu.com/sandbox/simple.html
What I'm trying to do:
Create a content div: let's say 400px tall and 700px wide, like the example. The content box has a margin of 50px in each direction. The content div should always be centered both vertically and horizontally, regardless of screen resolution. The black background should extend from the centered content area all the way to the right side of the screen, but not to the left.
The only way I can think of possibly doing this is something using window.innerWidth & window.innerHeight in JavaScript, but I don't know enough to know if this is even possible.
The amount of blank space above and below the middle section would need to be:
window.innerHeight - height of the div (in this example: 500px [400px box with two 50px margins]) / 2
The blank space to the left of the black bar would need to be:
window.innerWidth - width of the div (in this example: 800px [700px box with two 50px margins]) / 2
My question to you is: Is this possible in JavaScript? Is this possible somehow with pure CSS?
You can do this entirely in CSS with 4-point absolute positioning. You will need two elements:
The first item spans from the right of the screen to the center where the content is positioned. This element uses absolute positioning for the top, left, and right coordinates of the element (we can leave bottom unspecified as it's taken care of by the height.)
The second item is nested in the former. This item has a fixed width to ensure the content itself remains in the specified width you've chosen. We can also set the height and padding on this object and the parent will inherit it's height. Don't use margins to simulate padding - it can cause cross browser issues when you're just trying to do some positioning tricks as we are here.
So your HTML code would look something like this:
<div id="my_centered_design">
<div id="my_centered_design_content">
<p>This is just some example text.</p>
</div>
</div>
And you're CSS would look like this:
div#my_centered_design {
background: #000;
margin-left: -400px;
margin-top: -250px;
left: 50%;
position: absolute;
right: 0;
top: 50%;
}
div#my_centered_design_content {
background: #333;
height: 400px;
/* I think you actually want padding for
the effect you're trying to accomplish */
padding: 50px;
width: 700px;
}
Essentially this is the same trick as the Joe2Tutorial except we are applying additional positioning rules to adhere the centered element to the right side of the screen.
I think this pure css solution would suit you best: http://www.joe2torials.com/view_tutorial.php?view=37
A very quick google resulted in this piece of code.
this code does not align a div in the middle. what you actually for your own website is that you put the following div css
.main {
width: 140px;background-color: #252525; float: left;margin-top: 25px; }
inside a table that is aligned to be centered. so, basically you're using the table's centering feature to center your left floated div simply as a content. you're not doing anything through div or css for that matter. the piece of css code you offered doesn't not anything about centering a div in the middle.