Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Floating divs

  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Floating divs

    I have three divs, two floating next to each other, then one plain. I can't seem to find out why the plain one is on top of the two floating ones though.
    Here's my code

    Code:
    .MainDiv {
    	width: 1024px;
    	padding: 4px;
    	margin: 2px;
    }
    
    
    .FeedBoxLeft {
    	float:left;
    	margin: 2px;
    	margin-right: 5px;
    	width: 475px;
    	border-style: solid;
    	border-width: 1px;
    	border-color: #7f97a9;
    	clear: left;
    }
    
    .FeedBoxRight {
    	float:right;
    	margin: 2px;
    	margin-left: 5px;
    	width: 475px;
    	border-style: solid;
    	border-width: 1px;
    	border-color: #7f97a9;
    	clear: right;
    }
    
    p {
    	font-size: 12px;
    }
    Code:
    <html>
    <head>
    	<link rel="stylesheet" type="text/css" href="main.css">
    </head>
    	
    <body>
    
    <div class="MainDiv">
    	<div class="FeedBoxLeft"> 
    		<p>
    		Feed will go here
    		</p>
    	</div>
    	<div class="FeedBoxRight"> 
    		<p>
    		Feed will go here 
    		</p>
    	</div>
    </div>
    	
    
    </body>
    </html>
    Thank you for your help,

    Joe

  • #2
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    I don't see the plain one.

    You have two divs, floated left and right, inside another div called MainDiv. They are doing what you have coded them to.

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    O, I'm sorry, I forgot to update it. Here is the new html with the extra div.

    Code:
    <html>
    <head>
    	<link rel="stylesheet" type="text/css" href="main.css">
    </head>
    	
    <body>
    
    <div class="MainDiv">
    	<div class="FeedBoxLeft"> 
    		<p>
    		Feed will go here
    		</p>
    	</div>
    
    	<div class="FeedBoxRight"> 
    		<p>
    		Feed will go here 
    		</p>
    	</div>
    	<div>
    	hello world
    	</div>
    </div>
    	
    
    </body>
    </html>
    I have even tried nesting the two feed divs inside of a div container of their own, but that gives no results either.
    Do I need to just increase my margin on the main div, or use some sort of absolute positioning?

    Sorry it's been a while since I used html/css.

    Thank you for your time and effort,

    Joe

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You need to clear the floats. You also need a doctype. I suggest you get yourself familiar again with the basics as well as read the sticky about doctypes.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    .MainDiv {
    width:1024px;
    padding: 4px;
    margin: 2px auto;
    }
    .FeedBoxLeft {
    float:left;
    margin: 2px 5px 2px 2px;
    width: 475px;
    border:1px solid #7F97A9;
    }
    .FeedBoxRight {
    float:right;
    margin: 2px 2px 2px 5px;
    width: 475px;
    border:1px solid #7F97A9;
    }
    p {
    font-size: 12px;
    }
    .clear {
    line-height:0;
    font-size:0;
    clear:both;
    }
    </style>
    </head>
    <body>
    <div class="MainDiv">
    	<div class="FeedBoxLeft">
    		<p> Feed will go here </p>
    	</div>
    	<div class="FeedBoxRight">
    		<p> Feed will go here </p>
    	</div>
    	<div class="clear"><!----></div>
    	<div> hello world </div>
    </div>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    awsomejoe23 (01-23-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •