Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 06-01-2012, 05:44 AM
Contributing Member
Latest Blog:
None

 
Join Date: 01-22-12
Posts: 110
iTrader: 0 / 0%
Need some help with floats issue

hello gurus,

im just startin out with xhtml/css and im learning through blog reading and forum topics.

right now im having trouble with float property. i want to create a 2 column layout page but my sidebar won't float to the right correctly.

please take a look at my codes

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,600" rel="stylesheet" type="text/css"/> <link rel="stylesheet" type="text/css" href=""/> <title>Floats</title> <style type="text/css"> body { font-family: 'Open Sans', Tahoma, Helvetica, sans; } #main-wrapper { width: 960px; margin: 0 auto; background-color: yellow; border: 1px solid #ccc; } #main-content { float: left; width: 70%; margin: 10px; background-color: pink; border: 1px solid #ccc; } #sidebar { float: right; width: 30%; margin: 10px; background-color: pink; border: 1px solid #ccc; } p { padding: 10px; } </style> </head> <body> <div id="main-wrapper"> <div id="main-content"> <p>Lorem ipsum dolor sit amet consectetuer morbi sed adipiscing id Curabitur. Ornare Vestibulum ac turpis Vestibulum at tempor condimentum Nam ridiculus feugiat. Purus egestas massa elit In ut Nunc a Nulla fermentum eu. At Ut lacus ut et ligula urna tellus iaculis dignissim vel. Ipsum id Nunc pellentesque ut Pellentesque Lorem consequat tempor lorem vel. Quis fermentum massa facilisi mauris.</p> </div> <div id="sidebar"> <p>Lorem ipsum dolor sit amet consectetuer morbi sed adipiscing id Curabitur. Ornare Vestibulum ac turpis Vestibulum at tempor condimentum Nam ridiculus feugiat. Purus egestas massa elit In ut Nunc a Nulla fermentum eu. At Ut lacus ut et ligula urna tellus iaculis dignissim vel. Ipsum id Nunc pellentesque ut Pellentesque Lorem consequat tempor lorem vel. Quis fermentum massa facilisi mauris.</p> </div> </div> </body> </html>
 
Reply With Quote
  #2 (permalink)  
Old 06-01-2012, 06:22 AM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 1,763
iTrader: 0 / 0%
Margin left and right plus border left and right will be added to the 30% and 70% width containers, so the container get widther than the specified percents.

I will recommend in this case to use normal pixel values, then it's easier to minus the margins and borders to get the correct width.

Like this code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,600" rel="stylesheet" type="text/css"/> <link rel="stylesheet" type="text/css" href=""/> <title>Floats</title> <style type="text/css"> body { font-family: 'Open Sans', Tahoma, Helvetica, sans; } #main-wrapper { width: 960px; margin: 0 auto; background-color: yellow; border: 1px solid #ccc; } #main-content { float: left; width: 650px;/* 70% of 960px = 672px > 672px - (20px(margin) + 2px(border)) = 650px*/ margin: 10px; background-color: pink; border: 1px solid #ccc; } #sidebar { float: right; width: 266px;/* 30% of 960px = 288px > 288px - (20px(margin) + 2px(border)) = 266px*/ margin: 10px; background-color: pink; border: 1px solid #ccc; } p { padding: 10px; } </style> </head> <body> <div id="main-wrapper"> <div id="main-content"> <p>Lorem ipsum dolor sit amet consectetuer morbi sed adipiscing id Curabitur. Ornare Vestibulum ac turpis Vestibulum at tempor condimentum Nam ridiculus feugiat. Purus egestas massa elit In ut Nunc a Nulla fermentum eu. At Ut lacus ut et ligula urna tellus iaculis dignissim vel. Ipsum id Nunc pellentesque ut Pellentesque Lorem consequat tempor lorem vel. Quis fermentum massa facilisi mauris.</p> </div> <div id="sidebar"> <p>Lorem ipsum dolor sit amet consectetuer morbi sed adipiscing id Curabitur. Ornare Vestibulum ac turpis Vestibulum at tempor condimentum Nam ridiculus feugiat. Purus egestas massa elit In ut Nunc a Nulla fermentum eu. At Ut lacus ut et ligula urna tellus iaculis dignissim vel. Ipsum id Nunc pellentesque ut Pellentesque Lorem consequat tempor lorem vel. Quis fermentum massa facilisi mauris.</p> </div> </div> </body> </html>
__________________
Need a break? EnterCave more than 40000 online games in 15 categories.
Search or browse through EnterCave Online Games Directory
 
Reply With Quote
  #3 (permalink)  
Old 06-01-2012, 09:26 AM
HTMLBasicTutor's Avatar
Super Moderator
 
Join Date: 10-29-07
Location: British Columbia, Canada
Posts: 18,102
iTrader: 5 / 100%
Try changing your horizontal margins to percentage instead of pixels and adjust the container width accordingly. Each browser and operating system interprets width differently so the fixed pixel width still might not work for some.
__________________

HTML Basic Tutor - Learn how to code for better SEO
Basic Computer Information - Computer & internet basics for website owners

SEO troubleshooting and review services available. - Pm me.
 
Reply With Quote
  #4 (permalink)  
Old 06-01-2012, 09:23 PM
Contributing Member
Latest Blog:
None

 
Join Date: 01-22-12
Posts: 110
iTrader: 0 / 0%
@HTMLBasicTutor

thanks,i have further question. it's about the css property display.

how do we use display: none; ?

when and where do we have to use it?
 
Reply With Quote
  #5 (permalink)  
Old 06-01-2012, 10:13 PM
HTMLBasicTutor's Avatar
Super Moderator
 
Join Date: 10-29-07
Location: British Columbia, Canada
Posts: 18,102
iTrader: 5 / 100%
display: none would do just what it says, does not show the element.

CSS menus use display: none until the user does something to activate the dropdown/pop out menu for example.

Quote:
Hiding an Element - display:none or visibility:hidden

Hiding an element can be done by setting the display property to "none" or the visibility property to "hidden". However, notice that these two methods produce different results:

visibility:hidden hides an element, but it will still take up the same space as before. The element will be hidden, but still affect the layout.

display:none hides an element, and it will not take up any space. The element will be hidden, and the page will be displayed as if the element is not there
CSS Display and Visibility

CSS display Property
__________________

HTML Basic Tutor - Learn how to code for better SEO
Basic Computer Information - Computer & internet basics for website owners

SEO troubleshooting and review services available. - Pm me.
 
Reply With Quote
  #6 (permalink)  
Old 06-03-2012, 02:46 AM
Contributing Member
Latest Blog:
None

 
Join Date: 01-22-12
Posts: 110
iTrader: 0 / 0%
@HTMLBasicTutor

thank you once again, i've seen display: none, when creating a nav menu.

can you then teach me on how to create a 3 level submenu?
 
Reply With Quote
  #7 (permalink)  
Old 06-03-2012, 09:44 PM
HTMLBasicTutor's Avatar
Super Moderator
 
Join Date: 10-29-07
Location: British Columbia, Canada
Posts: 18,102
iTrader: 5 / 100%
CSSPlay has a number of CSS driven dynamic menus you could study and learn from.

If you decide to use one of his menus, most require a donation for commercial use.
__________________

HTML Basic Tutor - Learn how to code for better SEO
Basic Computer Information - Computer & internet basics for website owners

SEO troubleshooting and review services available. - Pm me.
 
Reply With Quote
  #8 (permalink)  
Old 06-04-2012, 01:10 AM
Contributing Member
Latest Blog:
None

 
Join Date: 01-22-12
Posts: 110
iTrader: 0 / 0%
thankyou for the link.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply

Tags
css, float


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
U.S. steps up sanctions as Iran floats nuclear talks Brave7 Controversial Social Issues 5 01-24-2012 04:26 AM
Coding Issue (Wordpress) Error message Stylesheet issue maybe snakeair Coding Forum 4 02-14-2010 12:44 PM
6-year-old Colorado boy floats away in balloon Brave7 Forum Lobby 23 10-19-2009 04:45 AM
WOMD - Issue or Non-issue John Scott Controversial Social Issues 1 08-02-2007 08:30 AM
Why is it when a DIV is empty content floats over it? noob_0001 Web Design Lobby 4 08-22-2005 02:38 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 10:11 PM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.