I have the following code: http://jsfiddle.net/pefGx/1/ and for some reason the nav area hides content as opposed to just making it go to the next line. What kind of code do I need to put in there to make the words move around it. I have tried putting the ul in a div but to no avail.
Remove position: absolute;.
Content won't flow around things that are taken out of normal flow (which is what absolute positioning does).
All you need is to remove position:absolute; from your nav class. And all will be ok.
This is your updated jsfiddle http://jsfiddle.net/pefGx/4/
As the others said, remove the position absolute. You can then use the margin properties to move it upward if needed.
Here's your JS Fiddle with the nav moved 40px upward
http://jsfiddle.net/pefGx/5/
The key line is margin-top in the css.
Related
I know this question has been asked multiple times, but I can't get it to work.
I have 1 screen container, in which I want 2 div's (1 content, 1 menu) next to each other.
1 div is positioned relative,
left:-830px.
So I can create a slide in effect using overflow:hidden and jQuery.
Here is a JSFiddle: http://jsfiddle.net/XWsS8/4/
Does anyone know why this isn't working?
I've seen more examples using inline-block which causes two div's to be next to each other, why does it not work in my example?
Thanks in advance :)
P.S. I don't want to use float
Has nothing to do in this case with inline-block but rather that you have #menu as position: relative instead of position: absolute. See fiddle with change.
A position: relative still causes the element to occupy the same space in the layout as it would if it were static (here's a good explanation), it just shifts the element's display rendering by the adjusted amount (-830px in your case) relative to itself (where it would have been if static).
So the second element in your case is being displaced by the "void" left from where the first element is still taking up layout space, but has been shifted outside it for rendering.
Another solution would be to keep the relative on #menu and set margin-left: -830px on the #content div to "pull" it over the space the #menu layout is taking up, as seen in this fiddle.
Both solutions offered, when the menu animates, will "overlay" the #content assuming #menu is given a z-index: 1 (see 1st solution fiddle and 2nd solution (with menu at -430px), whereas if you wanted the second solution offered to "push" the #content down below the menu on animation, then you would also have to change the margin-left back to 0 at the time of menu animation, like this fiddle shows.
So I know there are a plethora of questions about position fixed/relative/absolute in relation with z-index, but I still couldn't figure out my question using those.
Essentially I have a header that is fixed. It works perfectly fine, everything goes behind it when scrolling down the page.
I recently wanted to add links to div ids, but in order to account for the header, I had to add the following code where link is the parent element, and then linkTo is the class of something with an ID that we actually link to. This functionality works completely, providing the correct offset so that the header is above the div we want.
.link {position: relative;}
.linkTo {position: absolute; top: -80px;}
The problem with this, is that for some reason now my div is behind everything on the page. I can still see it but the text and images are in front.
I've tried adding z-index to my header (of like 9999) but it isn't working. I don't understand why adding position relative would mess up the order of how things are displayed.
I'd like to provide an example, but my code is rather large. If this isn't enough I can try to make a jfiddle later.
Add position: relative; z-index:9999 to the parent element it will keep this element stick inside the menu.
As Ganesh said, adding position: relative to the parent element of the header was the starting step. After that adding z-index to the same parent element fixed the problem completely.
Check for a lower z-index on a parent element, it appears to override the z-index of children.
I've run into z-index issues in the past with drop down menus and jquery UI tabs. I thought it had something to do with the stacking effects created us rules like opacity or transition, but for me the problem was a parent element having a lower z-index than a child element.
Struggling a bit with HTML positioning. I'm sure it's a pretty simple problem, but just can't crack it.
Please see fiddle: http://jsfiddle.net/HMyXW/2/
Basically, I am trying to position the yellow div (#logo) above everything else, so it will push any other content on the page down, even if the screen is resized vertically.
I've tried messing with z-positions, etc. but am not having much luck.
I suggest remove all the fixed positions if it is not necessary and add a outer div to wrap all the child divs.
Check this DEMO
If it is necessary to use the position:fixed to the #logo then you need to check the height of the #logo and give the same value as margin-top to the content div.
Your #logo has position: fixed; which means the element is removed from the normal page flow.
Basically, I have a form, outside of that form in this random space on my page I want to position a div (containing two buttons). I've looked at using absolute positioning. However, it is positioning it outside of the page wrapper.
How can I get the positioning to be specified from the corner point of the actual page and not the window?
How can I get the positioning to be
specified from the corner point of the
actual page and not the window?
You need to add position: relative to the element you would like the top and left values to be offset from.
That might be your form, or it might be your #container/#wrapper element.
See here for details and a visual: http://css-tricks.com/absolute-positioning-inside-relative-positioning/
Looks like you have your answer by now. But ill post this anyways.
A simple and short example which shows how relative positioning to parent is done.
http://jsfiddle.net/EadXw/
If you want it positioned top:0;left:0 on the page, place it immediately after the <body> tag.
If it is wrapped in anything the containers may change it's position. Make sure it is independant and not influenced by any containers.
Sounds like you should read up a bit on the flow of the DOM.
Positioning with CSS and HTML
Make sure your <form> element wraps your whole "page" and that the <div> with the buttons is the first child of <form>.
When you do this you can add the rule position:relative to the form and position:absolute to the <div> and move it around with top and left.
Another option is to have no position rule on the form and have position:relative on the <div>. This is more compatible with iPad and iPhone devices, which don't like absolute positioning. When you go for this approach be sure to have a fixed height for the <div> and a negative margin-bottom of the same size.
What's the recommended & most elegant way of getting rid of the gap caused by position:relative?
I have a front page and want to put a banner that will be partially above the header and content section, but using position:relative produces an empty area...
See example (I want the text to be just below the red box):
http://jsfiddle.net/Ru2CT/
I know I could create another relative positioned div as a parent of my text, but then I'll still have the gap but between content section & footer...
Any ideas? :)
Take the entire contents of the grey box, and place it within a div (stretched to be the same size). Then move that box up with position:relative. This will have the effect of moving the text with the red "slider"/banner thing, without moving the gray background.
Here we go:
http://jsfiddle.net/4BLFJ/ [animated and annotated]
This is not what you asked, but is one of the two ways I would do it:
The main idea here is to make the banner an absolutely-positioned div (not absolutely-positioned on the page, though you can do that too; it may in fact be better).
First set the #content area to be position:relative, but NOT change anything else. This creates a new stacking context (child elements use top/right/bottom/left and percentages relative to it).
Then put the banner-thing as a child element of the #content area, and set it as follows:
position:absolute;
width:80%; height:100px; /*there are other ways to set the height and width*/
bottom:100%; /*this puts it at the top*/
/*you can also use bottom:105% or bottom:90% or other things, or if you really
want to use non-relative units like px, you can create a third nested div that is
relatively positioned by whatever px amount*/
Negative margin would be a much more elegant solution in this situation (revised jsFiddle). Note that I've had to move the #eee background to div#main, as it would otherwise overlay on the background of div#top.
As a general rule of thumb, I'd also recommend avoiding relative positioning unless absolutely necessary - can often lead to z-index headaches in older versions of IE.
I've finally resolved this issue, simple:
position: relative;
bottom: 200px;
margin-bottom: -200px;
Does the magic! :)