Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-05-2013, 06:51 PM   PM User | #1
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 283
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
problem floating divs

Hi there.

I'm trying to get the layout shown in the attached picture, but I can't work it out. I've tried playing around with the clearing of floats but I can only ever seem to get boxes 2 and 3 to sit next to each other. Any pointers (and a possible explanation!) would be very much appreciated.

Code:
<style type="text/css">
div {
	border: solid;
}
#container {
	padding: 30px;
	width: 800px;
	overflow: auto;
}
#div1{
	width: 300px;
	height: 200px;
	float: left;
}
#div2{
	width: 300px;
	height: 200px;
	margin-top: 20px;
	float: left;
	clear: both;
}
#div3 {
	float: right;
	width: 100px;
	height: 200px;
}
</style>
<div id="container">
	<div id="div1">
		1
	</div>
	<div id="div2">
		2
	</div>
	<div id="div3">
		3
	</div>
</div>
Many thanks
Attached Thumbnails
Click image for larger version

Name:	layout.jpg
Views:	14
Size:	39.0 KB
ID:	11914  
paddyfields is offline   Reply With Quote
Old 02-05-2013, 07:20 PM   PM User | #2
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello paddyfields,
Look what happens when you re-arrange your floats -
Code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
div { border: 1px solid #f00; }
#container {
	width: 800px;
	padding: 30px;
	overflow: auto;
}
#div1 {
	height: 200px;
	width: 300px;
	float: left;
}
#div2 {
	height: 200px;
	width: 300px;
	float: left;
	margin-top: 20px;
	clear: left;
}
#div3 {
	height: 400px;
	width: 100px;
	float: right;
}
</style>
</head>
<body>
<div id="container">
  <div id="div3"> 3 </div>
  <div id="div1"> 1 </div>
  <div id="div2"> 2 </div>
</div>
</body>
</html>
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Users who have thanked Excavator for this post:
paddyfields (02-05-2013)
Old 02-05-2013, 07:26 PM   PM User | #3
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 283
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
Ah man, nice.

Thank you!
paddyfields is offline   Reply With Quote
Old 02-05-2013, 07:36 PM   PM User | #4
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,077
Thanks: 13
Thanked 84 Times in 84 Posts
jerry62704 is on a distinguished road
It works for me. But div3 is moved to the top and the clear is removed from div 2.

Code:
<!DOCTYPE html>
<html>
<head>
<style>
<style type="text/css">
div {
	border: solid;
}
#container {
	padding: 30px;
	width: 800px;
	overflow: auto;
	background-color:yellow;
}
#div1{
	width: 300px;
	height: 200px;
	float: left;
	background-color:red;
}
#div2{
	width: 300px;
	height: 200px;
	margin-top: 20px;
	float: left;
	background-color:blue;
}
#div3 {
	float: right;
	width: 300px;
	height: 400px;
	background-color:green;
}
</style>
</head>
<body>
<div id="container">
	<div id="div3">
		3
	</div>
	<div id="div1">
		1
	</div>
	<div id="div2">
		2
	</div>
</div>
</body>
</html>
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 02-05-2013, 08:10 PM   PM User | #5
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Quote:
Originally Posted by jerry62704 View Post
It works for me. But div3 is moved to the top and the clear is removed from div 2.
Yes, when you increased the width of div3 there is no room for 1,2&3 to go beside each other anymore so no need for the clear.

Narrow that div3 to 100px and the clear is needed again.
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:00 PM.


Advertisement
Log in to turn off these ads.