What I want: Stick text or an element to the right of the document, instead of window.
However, without currently implementation (position: absolute; right:0;), when I resize the window, the text always stay on the right side of the window, even there is a scrollbar showing up (because the element on the top of that has a fixed width). When I scroll right, the text is not right aligned any more.
Here is the example:
http://jsfiddle.net/N5jc9/
Note that, I have no control on container1. Anyone having a good solution for this using CSS?
Put container 2 inside container 1 and make container 1's position relative.
You can use the :after pseudo element and position it to the right of your <body> element. This of course will be evident only if you have set a fixed/min width for your <body> element.
Demo: http://jsfiddle.net/PPtD5/2/
Code:
body {
width: 70%;
height: 200px;
position: relative;
}
body::after {
content: "This one sticks to the right of <body>";
width: 100px;
position: absolute;
right: -120px;
top: 0;
}
Not sure if I understand completely what control you have for container1, but if you apply display:inline-block to each class the text will appear to the right of the container 1
Related
I have a main wrapper div with a content div and a button. The button is supposed to go underneath the content div but for some reason it's overlapping with it.
The content div has css:
#groupMembers {
position: absolute;
height: 50%;
width: 90%;
left: 5%;
overflow: scroll;
display: inline-block;
}
and the button has:
button {
display: inline-block;
width: 70%;
left: 15%;
}
I thought since they're both inline-block that they wouldn't overlap, but for some reason they are. I made a JsFiddle to show: http://jsfiddle.net/b5hp6boz/
Can anybody help me get the button to display beneath the content div?
Remove the (extensive) use of absolute positioning.... Change it to position: relative; if necessary. But on many elements even that is not necessary.
Move the button div up to under the <h4>add members</h4> in the HTML where you appear to want it.
Then adjust margins for #DIV_05 and the button.
Fiddle Update or Fiddle Update 2
(Note I merely performed a search to change absolute to relative in your CSS, then adjusted from there.)
By using absolute positioning so extensively you were forcing elements into unnatural positions. Then when it wasn't working out.. you are left wondering why. Let things fall where they naturally want to fall. Change the HTML for overall render order, don't force things with absolute positioning.
Use of absolute position is most commonly used to adjust z-index and make elements not alter positioning of other elements. (like a global float of sorts) It should not be the fall back for positioning everything in any layout.
The problem in your code is that you have given the #DIV_5 the following CSS:
position: absolute;
By giving a HTML element an absolute position it is removed from the normal rendering process by not obtaining any space in the document. That means it is not affecting the position of the following BUTTON_105 element. That's why the button is positioned right underneath the H4_4 element (which is the first element not having an absolute position).
To fix that simply remove the position: absolute; declaration for #DIV_5. (Btw: You should try not to make heavy use of absolute positioning as it can cause further issues.)
Try giving your div tag a higher z-index value.
I have one element (a div) floating to the right of content, and below the content (which can be varying in height) I have another div that I want to stack above the floated right div, but stay below the content.
Here's an example: https://jsfiddle.net/8nap0qm6/
While this is close, I need the content within the ".over" div to not wrap when it hits that right-hand div, but instead fill up the whole ".over" div while still overlapping the right-hand div.
Putting a "clear: both/left" on the ".over" div pushes the div below the right-hand div instead of overlapping it.
I know I could absolute position the over div:
.over {
position: absolute;
top: 200px; // or xx%
left: 0px;
z-index: 5;
}
but I need it to be vertically controlled by the content so I can't put a set "top" on it.
Is there a way to achieve this? (Make white text in blue box go full width of blue box.) I'm open to using completely different code if necessary.
You just need to set position: absolute;
.over {
position: absolute;
z-index: 5;
}
JSFiddle
As the given answers don't seem to satisfy exactly what's expected, I decided to change some things to make the output closer to what you expect. Check my fiddle.
Major changes:
1) Added a #parent div to wrap the whole content
2) Absolutely positioned the .right div, relative to #parent
3) Added width to .right and all #parent's p elements so that summing both results in 100%
Just add clear: both; to your .over class:
.over{
clear: both;
/* your properties */
}
I have a div and i want to put an image at the bottom right of the div and some images to the bottom left. They are different heights so i want to make sure they both align to the bottom of the div.
At first, i made the bottom right align by using:
position: absolute:
bottom: 0;
right: 0;
but then i couldn't put a margin around it (as it is out of the document flow). So then, based on some answers below, i tried to create the jsfiddle above to get it to work without any position: absolute.
Here is my jsFiddle example: http://jsfiddle.net/leora/FYw2D/.
My only issue now is that I want the images on the left hand side to align to the bottom of the div (versus aligning to the top of the right image). Also in certain cases i don't have any images on the bottom left but i want to have the same vertical spacing (so if i add an image dynamically, it doesn't reset the container height.
.images
{
float: left;
margin-top: 4px;
}
I tried adding vertical-align and a few other properties but couldn't get both to align to bottom.
Any suggestions?
You can use relative positioning to achieve the same bottom: 0; and right: 0; placement... but that won't take your .bottom element out of the document flow (like position: absolute; does). That said, your element needs to be within the document flow in order for margin and padding to be respected anyway.
It sounds like you just need to float it right, apply display: inline;, and apply your margin and padding. Place your text content above the image in the source order, and then the image should always fall beneath and to the right of the content above (depending on other unknown layout variables, that is).
.bottom {
float: right;
display: inline;
padding: 20px 0 0 20px;
margin: 20px 0 0 20px;
}
Updated
To fix your new challenge, I added position: relative; on .container and position: absolute; and bottom: 0; on .images:
http://jsfiddle.net/FYw2D/6/
I can't see a good way to achieve this with CSS alone.
position: absolute; will remove image from text flow.
The only approach I can see is to place your image in the middle of the text and float it right.
See this JSFiddle.
But, you will have to find a good spot in the text to place the image in order for it to look good. You can even write a JavaScript script for this.
The other approach is just to add bottom padding to image's container.
And probably it's a good time to revisit page's design and maybe re-design this element.
UPDATE:
Considering your updated question, I've edited your JSFiddle.
You can use position: absolute; bottom: 0; left: 0; to position left images wrapper inside of a parent container. This will work fine if your right image is taller that left ones (like in your example).
I've also refactored your Fiddle to fix some other issues. Please see the code.
I have an image representation of graph made with .png images and -moz-border CSS trick (div id=gholder) I want that graph to be positioned as where the picture shows, And I did it using CSS position: absolute/relative tags, but I'm having problem using the two tag. When I use this CSS code
#gholder {
float: left;
bottom: 460px;
left: 60%;
position: relative;
}
The site shows a big space below the footer, is there a way to remove that big space when using the relative code?
Relative positioning always leaves a space where the element originally was. If you use absolute it should work correctly.
`#gholder { bottom: 460px; left: 60%; position: absolute;}`
You also don't need the float tag.
If the problem is that you want the main content div lines to stretch to the width of both divs, I'd create a div which contains both the content and the graph, and set it to a defined width and have the top and bottom line in it.
Then inside that div define a width for your content div and position it, then do the same for the graph div.
Think that makes sense.
please see my fiddle: http://jsfiddle.net/qVHg8/1/
Why isn't the fixedRightCol being positioned at right:0 of the outer container div? Right now it's going outside of the container div which I don't want.
I could use position absolute, which puts the fixedRightCol in the right position but scrolls. I want the fixedRightCol to be fixed (no scroll).
so how can I get fixedRightCol position correctly and fixed on scroll?
Thanks
If you want the green div to be fixed inside the red div, you need to use position: absolute;
http://jsfiddle.net/qVHg8/2/
position: fixed; fixes the element to the viewport, rather than the parent.
EDIT:
If you're able to use a bit of javascript & jQuery, then this will work with your dynamic margins:
$(function(){
$('.fixedRightCol').css({right: $('.container').offset().left});
});
What thats doing is setting the right CSS property to be the calculated left property of the container. As the margins are the same on both side (auto), then this will shit the red div to the correct position.
http://jsfiddle.net/qVHg8/4/ is a working example of this.
When you give something a position fixed, it breaks out of any divs it may be in.
Edit:
You could just do this:
.fixedRightCol{
position: fixed;
margin-left: 350px;
width: 50px;
background: green;
}
Use margin-left: 350px; for green box with NO right: 0px; or anything...
i think you are meaning to use position:absolute;