You’ve gone about your layout all wrong, I’m afraid. To make those boxes in the middle sit side by side, it’s best to remove any left/right margins and float them, and remove the “top” settings. With position: relative, you can move the boxes out of their normal position, but the space they should have occupied remains there, and hence the huge gap remains.
So remove all the top settings on all elements, and float those middle boxes, then we can look at how to do the final adjustments.
Thanks for your advice. I understand that concept - i.e. relative positioning only moves the box from it’s ‘original’ position and it makes sense that I would then have excess space below the footer.
I have done as you suggested and if you can help me go to the next step of aligning the elements correctly. I think my brain is nearly fried at this point.
Secondary, Tertiary, Quaternary and Footer elements all need adjusting.
I kept the ‘navigation’ and ‘main’ elements using ‘relative’ positioning. I kept the top setting on the ‘main’ element, however should I change these elements to float & remove the top setting from ‘main’ also?
OK, good work. The next thing I would suggest (as you asked) is to remove all the other top settings too, as they aren’t needed and will get you into a bit of trouble. If you need spacing, use padding/margin instead. I’m happy to help you through this, so perhaps first move all those top settings (and any other positioning) as that will hep to get the rest right.
I’ve just worked on my ‘index’ page and any CSS related to this. All other CSS I will change when I have this first page under control.
I removed position: relative from
html, body
navigation
main
I have left all css relating to content as is - should I also be positioning this content using padding and margins only and eliminating all references to relative or absolute positioning?
When I removed position:relative from the following some of my content also moved. So I’m presuming that I need to position my content using another method?
OK, it’s looking better now (don’t worry about things being out of place, as that will be fixed).
The next thing I’d suggest is to replace things like <aside> and <section> with <div>, as these new elements aren’t supported properly by browsers yet, and so there’s no advantage (but lots of disadvantages) in using them. That will make the remaining fixes a lot easier.
One of the reasons why I probably began using position: relative is I wanted my site to sit centered on the viewport. So if you go to the site at the moment, I have used margins to position the three boxes & footer, however now I have to get these boxes to move together with the rest of the page when the page size is increased or decreased. Do I need to link these elements to a parent element like body to do this? See example below. If I link to #body though I loose all my other CSS (the square box with rounded corners disappear). Before I continue positioning the remainder I’d like to fix this…thanks again.
#main {
background-color: #F4F0E9;
border-radius: 20px 20px 20px 20px;
box-shadow: 5px 5px 10px gray;
[COLOR="#0000CD"]height: 480px;[/COLOR] // remove this line
margin-bottom: 10px;
[COLOR="#FF0000"]margin-top: -25px;[/COLOR] // remove this line
text-align: left;
z-index: 2;
}
to
#main {
background-color: #F4F0E9;
border-radius: 20px 20px 20px 20px;
box-shadow: 5px 5px 10px gray;
margin-bottom: 10px;
text-align: left;
z-index: 2;
}
And
#footer {
background-color: #645E57;
float: left;
height: 200px;
margin-bottom: 10px;
[COLOR="#0000CD"]margin-left: 165px;[/COLOR] // remove this line
margin-top: 10px;
}
They have their uses, but they are best kept for smaller, non-essentioal on-page elemtns. When an element has pos:abs it is taken out of the flow, meaning that other elements don’t see it, so you have to be very careful when content expands, as the ap element can start to get in the way etc. As you saw with pos:rel, using it to move things around causes problematic gaps etc.
One place where position: absolute may be of some use is with the image inside your #primary div. The <figure> around it is not needed, though. A better way to use pos: abs here is to give the container position: relative, so that you place that image in relation to its container rather than to the browser window.
Well thank you so much for your time! It has helped me out hugely and hopefully now I’ll be able to continue building it correctly, I understand a lot more now. My pile of site point books has served me well but it doesn’t replace getting help from a pro - and an Aussie at that! Have a great afternoon.