Forum Moderators: not2easy

Message Too Old, No Replies

Opera, IE6, CSS Box and floated image

Correct rendering?

         

phil_uk

9:32 am on May 5, 2005 (gmt 0)

10+ Year Member



Hi All,

I have put together a demo to illustrate my problem:

if you view this page in IE6 you will see: <edited>

and in opera you will get: <edited>

The effect that I actually want to acheive is the IE6 version where the heading occupies 100% of the available width (which is less if there is an image).

Two questions then: Which of the browsers in rendering the content correctly and What do I have to do to please both of them?

All code is below, hope you can help.

Thanks

Phil

CSS


#container {
width: 750px;
border: 1px gray solid;
margin: 10px;
padding: 10px;
}
.contentHead {
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
background-color: #A1B7C5;
width: 100%;
padding: 2px;
border: 1px dashed #999999;
}
#testimage {
float: right;
}

HTML:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Mousesoft: ¦ CSS Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
<div id='container'>
<img src='../picture/mousesoft.jpg' id='testimage'>
<div class='contentHead'>This is a test heading</div>
</div>
</body>
</html>

[edited by: tedster at 6:04 am (utc) on May 6, 2005]

Stormfx

3:09 pm on May 5, 2005 (gmt 0)

10+ Year Member



Well, first of all, neither browser is displaying it correctly. Firefox shows the heading as only high enough for the text and full width of the page with the image floating above it, as your CSS dictates. What I mean is that the #contentHead div is not floating and set to 100% width whereas the #testimage div is set to float.

If the effect you're trying to achieve is that of the IE version, where the heading's right edge stops at the image, then you can do one of two things:

1. Set the #contentHead to float:left as well, forcing it to respect the #testimage div.

2. Eliminate the two divs altogther and float the image inline. e.g:

Change:


<div id='container'>
<img src='../picture/mousesoft.jpg' id='testimage'>
<div class='contentHead'>This is a test heading</div>

To:


<div id='container'>
<p class='contentHead'>This is a test heading</p>
<img src='../picture/mousesoft.jpg' id='testimage'>

You could, of course use an <h1> tag instead of <p>, which would be logical.

One other thing is that the single quotes in your html source should be double quotes. Otherwise you'll choke some browsers.

HTH

phil_uk

3:34 pm on May 5, 2005 (gmt 0)

10+ Year Member



Thanks - I'll give that a try and let you know if it works.

Phil

Stormfx

6:02 pm on May 5, 2005 (gmt 0)

10+ Year Member



Actually, after I look at it again (when I'm not half asleep :) ) the <img> tag goes before the closing </p> tag. I'd also recommend you use an <h1> type tag, instead.