Everywhere people asks for how to align an element inside a DIV they are told that the container must have a relative position.
In my case, I have a floating dialog, with absolute position. How can I make a button element always stick to the bottom of this dialog?
<div class="dialog">
<div class="dialog-content">
</div>
<button>Close</button>
</div>
Try to use absolute positioning with bottom: 0px for your button. It will position relative to the parent of button which is .dialog.
Something like this: http://jsfiddle.net/0rohooj9/
You would need to give the dialog absolute dimensions, and then set the button's position to absolute, and bottom: 0;
Here's a Fiddle with your code:
http://jsfiddle.net/erlingormar/d8sa43s8/
Related
I'm using z-index on my page ( -link no longer needed- ), and it doesn't work properly: it doesn't place certain divs above all others...
You can see it yourself, by clicking one of the items in the left, or right bar.
Then, the mask will fade in, but show the message box, beneath it.
I've tried a lot, but I just can't get the message box to show above all others...
What can I do to fix this? [note: 2nd question below!]
If you don't want to check the page, the message box is located in some other divs:
<div>
<div>
<div>message box</div>
</div>
</div>
The CSS positioning is like this:
.window {
position: fixed;
left: 0px;
top: 0px;
z-index: 100;
}
I use position:fixed, because position:absolute is not absolute here, the div is not aligned to the body, but something else somehow.
Is there a way to reset the positioning and absolute position it again?
For as long as I can remember, z-index issues often come from the fact than the parents of the z-indexed elements are not positioned. Sibling parents should be positioned.
If you're using jquery check the top Z Index Plug In, you can apply it when the object has a mouse over event like:
<div id="modal" onmouseover="$(this).topZIndex();"></div>
Then change the position to absolute with jquery also or viceversa:
$(document).ready(function(){ $('#modal').css('position','absolute'); });
if you remove z-index from #leftbar it fixes your problem. The position should not matter, as long as you have one.
I have a fixed height scrollable <div id="overlay"> positioned over all the page elements using position:fixed. In the div I have elements higher than the fixed height, so the scrollbar appears. I also have a tooltip that I want to stay with a paragraph even if it is scrolled.
That's what I want to happen here, but unfortunately neither of my solutions work properly:
I add position:absolute to the tooltip and position:relative to #overlay(the tooltip's parent): http://jsfiddle.net/4qTke/
The tooltip scrolls as expected but it is not visible outside of #overlay.
I only add position:absolute to the tooltip: http://jsfiddle.net/Yp6Wf/
The tooltip is visible outside of the parent #overlay but doesn't move when the div is scrolled.
I want the tooltip to always be visible AND for it to move when scrolled.
What you want is not possible using just CSS and HTML.
The main problem you have is that you have set overflow: scroll on the container your #tooltip is relative to. Because this overflow property is stopping any content from appearing outside of its edges when you position #tooltip "outside" of the div it will be hidden and only visible when scrolled to.
The reason it was visible in your second scenario is because without setting position:relative your #tooltip was relative to the page and not the container. Which meant it was not affected by the overflow:scroll property of the container.
HTML:
<div id="overlay">
<div class="elemRel">
<div class="elemAbs">
<!-- Your Code -->
</div>
</div>
</div>
CSS:
#overlay { position:fixed; }
.elemRel { position:relative; }
.elemAbs { position:absolute; }
Maybe this is an alternative for you? See demo fiddle.
I have a div that contains a smaller div with some text. The container div has a webkit transition that moves it off the screen. I want the smaller div to move with it, until it gets to the edge of the page, then remain fixed, almost as if it gets 'stuck' on the side of the page, while the container div continues to move underneath it out of sight. Can this be done?
//CSS
.move{
-webkit-transition-property:left;
-webkit-transition-timing-function:ease-in-out;
-webkit-transition-duration:1s;
left:-200px;
}
//HTML
<div onclick="this.className='move'">
<div>
some text here
</div>
</div>
Here's an example for you: http://jsfiddle.net/LjjRM/
A couple points:
1.) jQuery
2.) position: absolute
I am trying to use jQuery to calculate the window height then apply that value to a DIV (the container div) finally i want the jQuery to align an element to the bottom of the page.
<div id="wrapper">
<div id="element-align">Here is the element i wish to align to the bottom</div>
</div>
Further to my question on your OP, this can be done in CSS:
#element-align {
position: fixed;
bottom: 0;
}
If needs be you can also add left/right to the element, but the fixed positioning will mean that the element will always appear in the same place relative to the browser chrome, regardless of the scroll position of the page.
there
Below is the html code:
<div class="cont">
<p class="fix">fixed text</p>
</div>
and css:
.cont{position:relative; width:500px; background-color:red; height:2000px;}
.fix{position:fixed; right:0;}
I want set the p.fix's right position relative to the .cont element. But the code I applied does not work correct.(it relatives to the body element)
Any suggestions?
Thank you very much.
As far as I can make out, the top, bottom, left and right attributes of a position:fixed element are relative to the browser's viewport. It wouldn't make much sense if they worked differently, because position:fixed elements are meant to be in a fixed position in the browser window, regardless of scrolling of the remaining content.
If you want to have the element in a certain position initially, you can wrap it in a div with position:absolute and layout that to be in the desired position instead, and don't aupply top, bottom, left and right attributes for the position:fixed element.