Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CSS DIV'S NOT ALIGNING?

Featured Replies

hi,

its my 1st time writing css and xhtml. (I built this within IE7)

ive made 2 divs that should be positiond left and right. both next to each other. but for some reason my right div appears to the right - but drops below the left div???

please help!

 

The div's are called: content_nav (left hand div) and content_textbody (right hand side)

 

Also, How do i align the sitemap (within the footer div) to 'center'?? css or in the xhtml??

 

Also, When viewed in IE7 its fine. But in FireFox 3 and Navigator it renders totally wrong?? Please help!

 

thanks

index.html

bhps.css

hi welshhuw

 

you seem to have got your divs a little messed up here!

 

you have placed the "content_textbody" body inside of "content_nav":

"content_nav" should be closed before starting "content_textbody" starts.

 

you have also done a similar thing with the content and footer divs

 

your code should look something like:

 

<div class="content">

<div class="content_nav">

nav menu here

</div>

<div class="content_textbody">

bodytext here

</div>

</div>

<div class="footer">

footer content here

</div>

 

Also you have have a div with a class name of "navmenu ul" you can't use classes like this I think what you are trying to do is have a div with the classname "navmenu" and giving the <ul> element some css attributes you do not need to add "ul" to the classname

 

I suggest you check out w3schools for reference with your css.

 

This should set you on your way at least and you should find floating the divs much easier now :D

 

Cheers

 

Ysuran

  • Author

So I should have used 'class' instead of 'id' ?? (For all of my DIV's.)

Is that right?

So I should have used 'class' instead of 'id' ?? (For all of my DIV's.)

Is that right?

 

You can use ethier it doesn't matter personal preference.

 

Edit:Better explained by Dizi

Ids are used if you are only using them once on a page, as they are unique identifiers. for example a wrapper, header, footer these would really only be used once on a page

 

if you have multiple instances of something, for example all your images are in image boxes, then you would use classes, as these are for use if you are using the same thing more that once on a page.

 

 

Here is a quick example:

 

<div id="header"> Header stuff here</div>

<div id="main">

<div class="styleone"></div>

<div class="styetwo"></div>

<div class="styleone"></div>

<div class="styletwo"></div>

</div>

<div id="footer">Fotter stuff here</div>

 

 

Hope that makes sense :)

Sorry that wasn't the point I was trying to make! It's just the way I code - using classes for css layouts and using ids when I intend to do some javascript wizardry!

 

What I was trying to say was the layout of the divs was actually incorrect you have divs such as "content_textbody" inside of "content_nav" and they should be side by side

  • Author

<div class="content">

<div class="content_nav">

nav menu here

</div>

</div> <----------------------------------i added this end /div tag here and it works!!

<div class="content_textbody">

bodytext here

</div>

</div>

<div class="footer">

footer content here

</div>

 

Not sure if it should work like that tho but it also works in FF and Netscape now.

<div class="content">

<div class="content_nav">

nav menu here

</div>

</div> <----------------------------------i added this end /div tag here and it works!!

<div class="content_textbody">

bodytext here

</div>

</div>

<div class="footer">

footer content here

</div>

 

Not sure if it should work like that tho but it also works in FF and Netscape now.

 

 

 

You should take one of the </div> out from under where it says bodytext here if that is the case as you are now closing more div's then you have open.

  • Author

dizi - spotted that when i validated it with W3C. Thanks for your help.

 

 

still cant get the sitemap: links to center tho?? how should i do this?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.