Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Different browser behaviour for floating property

Posted on 2010-01-10
4
Medium Priority
?
261 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

564 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