Archive for April, 2007

Easy Clearing Of Floats

Tuesday, April 24th, 2007

Web standards designers often need to make use of display:float to handle things like columns, navigation lists, and more. Usually these floats are followed by something like <div style="clear:both"></div>. It turns out there is an easier way.

I was reading 35 Designers x 5 Questions and saw a link for a way to clear floats without clear divs. The code that comes with the article is a bit confusing and sloppily written, but it works!

So, to make things easier to understand, I wrote my own example. The code below will do it for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Easy Floats</title>
  <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
  <style>
h1 {
	background-color:#FFCCCC;
	margin:auto;
	width:500px;
	text-align:center;
	margin-bottom:0px;
}
div#outer{
	width:500px;
	overflow:auto;
	padding-bottom:0px;
	background-color:#AAAAAA;
	margin:auto;
}
div#column1 {
	float:left;
	background-color:#CCFFCC;
	width:200px;
}
div#column2 {
	float:left;
	background-color:#CCCCFF;
	width:300px;
}
div#footer{
	width:500px;
	overflow:auto;
	padding-bottom:0px;
	background-color:#FFCCFF;
	margin:auto;
}
div p{
	padding:10px;
}
  </style>
 </head>
 <body>
  <h1>title</h1>
  <div id="outer">
   <div id="column1">
    <p>
     Left
     <br>
     Column
     <br>
     Floated
     <br>
     Left
    </p>
   </div>
   <div id="column2">
    <p>
     Right Column float with no clears below it...
    <br>
    </p>
   </div>
  </div>
  <div id="footer">
   <p>
    FOOTER not cleared...
   </p>
  </div>
 </body>
</html>

Internet Explorer 7 Heading Bug

Thursday, April 5th, 2007

I try to avoid Internet Explorer 7, or IE7 for short, but I can’t any more. Today was the first time I really had to debug in IE7 and I discovered a pretty irritating bug.

What I wanted to do was put a h2 inside of a div and adjust the margin-top so that it was hanging over the top edge of the div. Imagine a fieldset with a legend.

My code and style sheet were something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<style type="text/css">
div {
	border:1px dashed black;
	background-image:url(../images/sect_bg.png);
	padding:10px;
	margin-bottom:25px;
	clear:both;
}
h2 {
	display:block;
	width:100%;
	height:53px;
	background-repeat:no-repeat;
	background-position:center center;
	margin-top:-33px !important;
	text-align:center;
	background-image:url(../images/blog_title.png);
}
h2 span {
	position:absolute;
	margin-left:-9999px;
}
</style>
<div>
 <h2><span>Heading</span></h2>
 <p>Some Text</p>
</div>

In IE7, nothing happened. In every other browser, the heading moved up. I started playing with the style sheet, removing parts. It turns out that the height and width were the problem. This applied not only to my image replacement, but a plain-old div-with-a-heading-in-it. The fix for my problem was to create a separate IE7 style sheet with the following:

1
2
3
4
5
h2{
	width:auto;
	height:auto;
	padding-top:53px;
}

I was also informed today that my Internet Explorer 6 Virtual PC image had expired. As promised, Microsoft has released a new Virtual PC image. While it’s nice to be able to check against Internet Explorer 6, this refresh cycle isn’t very convenient.