?
Solved

Different browser behaviour for floating property

Posted on 2010-01-10
4
Medium Priority
?
252 Views
Last Modified: 2013-12-07
Hello,

see the code I attached. I do have a site with a header, a center and a footer. The background of the center is green. Within the center I do have two boxes: contentleft and contentright. The content of the center is flexibel, so I don't want to define a height in my stylesheet. If I view this site in IE7, I see that the height of the center part automatically is set defined by the text within the boxes contentleft and contentright: the text does have a green background. If I view my site in IE8 or Firefox, I see different behaviour. I do not see a green background. I know that the bahaviour in IE8 and firefox is the correct behaviour following the css specifications for floating. But how do I change my stylesheet to get a site with the behaviour of IE7 in IE8 and Firefox. Important restriction is that I do not know the amount of text placed in the center part. So I can not give the center box a height in my stylesheet.    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<style type="text/css">
.header{
	background-color:red;
	width:800px;
	height:40px;
	}
	
.footer{
	background-color:cyan;
	width:800px;
	height:40px;
	}
	
.center{width:800px;	
background-color:green;}

.contentleft{
width:200px;
float:left;}

.contentright{
width:200px;
float:left;}
	
</style>
 
<html xmlns="http://www.w3.org/1999/xhtml">
	<body>
	
	<div class="header"></div>
	<div class="center">
		<div class="contentleft">
		contentleft contentleft contentleft
		</div>
		<div class="contentright">
		contentright contentright contentright
		</div>
	</div>
	<div class="footer"></div>
	</body>
</html>

Open in new window

0
Comment
Question by:adiemeer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 26278322
The markup in your question is incorrect because the "style" tags should be enclosed somewhere within the html body. I have added a "head" section for this. I suspect that this may only be where you've written this question though.

I have added a wrapper tag with the class "container" which provides an area for your background.

I have also added "clear:both" to reset the floating layout to normal layout.

Let me know how you get on!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<style type="text/css">
			.header {
				background-color:red;
				width:800px;
				height:40px;
				/* Added */
				clear:both;
			}
			.footer {
				background-color:cyan;
				width:800px;
				height:40px;
				/* Added */
				clear:both;
			}
			.container {
				background-color:green;
				width:800px;
			}
			.center{
			}
			.contentleft {
				width:200px;
				float:left;
			}
			.contentright {
				width:200px;
				/* I changed this to right. */
				float:right;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="header"></div>
			<div class="center">
				<div class="contentleft">
				contentleft contentleft contentleft
				</div>
				<div class="contentright">
				contentright contentright contentright
				</div>
			</div>
			<div class="footer"></div>
		</div>
	</body>
</html>

Open in new window

0
 

Author Comment

by:adiemeer
ID: 26278525
Hi numberkruncher!

thank you very much for your solution. This helps me very good. But I still have another problem. In order to make a simplified example of my situation I defined a footer with a fixed height. Actually I do not have a footer with a fixed height. The height of the footer has to be the rest of the window. So the cyan colour in my example is not 40px but must have the height to fill the window with the cyan colour at the bottom. Do you know how to solve this?    
0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 2000 total points
ID: 26278739
To do that you could simply set the background colour of the window to cyan (or whatever you intend to use). The footer, therefore, doesn't need to be of any particular size.

I have also added a small bit of CSS which centers the main container area (because you are using a fixed width, this might make your layout a little neater for people who are viewing your website on a larger screen).

Additionally I have removed the default page margin/padding to avoid having cyan at the top of the screen, BUT on a larger screen the left and right will be cyan.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<style type="text/css">
			/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Added */
			body {
				background-color:cyan;
				/* Remove margin around page. */
				margin:0px;
				padding:0px;
			}
			.header {
				background-color:red;
				width:800px;
				height:40px;
				/* Added */
				clear:both;
			}
			.footer {
				background-color:cyan;
				width:800px;
				height:40px;
				/* Added */
				clear:both;
			}
			.container {
				background-color:green;
				width:800px;
				/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Added (Optional) */
				/* Center main container panel. */
				margin-left:auto;
				margin-right:auto;
			}
			.center{
			}
			.contentleft {
				width:200px;
				float:left;
			}
			.contentright {
				width:200px;
				/* I changed this to right. */
				float:right;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="header"></div>
			<div class="center">
				<div class="contentleft">
				contentleft contentleft contentleft
				</div>
				<div class="contentright">
				contentright contentright contentright
				</div>
			</div>
			<div class="footer"></div>
		</div>
	</body>
</html>

Open in new window

0
 

Author Closing Comment

by:adiemeer
ID: 31675191
Thank you very much!!!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question