Jump to content

[SOLVED] Unable to align link to top


BrandonE97

Recommended Posts

I have a link on my navigation I want to align to the top using divs. I just started working with divs and am trying to replace my current layout using tables. I've tried various bits of code to align my link but have been unsuccessful. Here is my code:

 

Navigation top:

<div id="navtop">
<a href="javascript:website()" class="navtop">BrandonE97</a>
    <div id="navbody" align="center">... navigation menu appears here

I have worked some putting the link in its own div but I'm still unsuccessful with that as well.

Here is some of my css code that the page uses:

 

CSS:

#navtop {
position:absolute;
left:9px;
top:7px;
width:115px;
line-height:75px;
text-align:center;
background-image:url(/theme/navmenutop.gif);
background-repeat:no-repeat;
}
a.navtop:link, a.navtop:visited {
color:#0099FF;
font-size:18px;
font-style:italic;
font-weight:bold;
text-decoration:none;
}
a.navtop:hover {
color:#0000FF;
}

Link to comment
Share on other sites

Why are you using position: absolute? Is really necessary. This usally creates more confusion and problems than it helps you.

 

- Another thing, you should not put classes within the <a >. Although this isn't "bad semantic html" it is harder to read and comprehend. Since < a href=".."> can be rather large, it is recommended to keep it as small and short as possible. I recommend using #navtop a { ... } instead. This is easier to read and style in the long run.

Link to comment
Share on other sites

I'm still new to using css and divs instead of tables. I noticed using relative instead of absolute the whole navigation menu moves over the pixels I specified in my code. Absolute moves it back to hug the browser window. The link uses javascript for a little alert message that just says stuff so the link will never get any bigger than that. Using it on the <a...> lets me change the color easy when moused over.

Link to comment
Share on other sites

If you are new to CSS, I would strongly recommend spending an hour or two going through the tutorials on this page:

 

http://css.maxdesign.com.au/floatutorial/

 

It will show you some ways to do things that often trick newbies into using absolute positioning to get around. Some of the techniques are a little outdated, but will still give you a good solid base of ideas to work and expand from.

Link to comment
Share on other sites

Well I'm not that new to a lot of css itself, just css using divs instead of tables.

 

DIV is one of the most used elements with CSS for layout, which is supposed to replace the old table layouts, gotta get used to it sooner or later. Here's another layout tutorial for a fixed layout http://www.subcide.com/tutorials/csslayout/. For your particular need, sounds like there is really no need to use relative or absolute positioning.

Link to comment
Share on other sites

I still have not been able to move the link up to the top and I've tried everything I know. Thanks for the links and stuff cause I learned a few things from them. I have looked through the help I have been given but maybe I'm missing something. Can someone please help me.

Link to comment
Share on other sites

You have a margin of 8 px on the body, which is pushing the whole body and all its contents down 8 px from the top. You also have top set to two px on the navdiv, which is pushing that element down another two px. Delete both of these, and your div will align with the top.

Link to comment
Share on other sites

The problem is line-height:75px; within #navtop, it's pushing the a element down about half that px value. Instead of using line-height to push the div navbody down, use margin-top within #navbody instead. Also, you odd to change most, if not all the position property to float instead, within that page, there is really no need to use position relative or absolute.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.