Trenton is crazy
Trenton Moss has written13 articles for SitePoint with an average reader rating of8.8.
By Trenton Moss
September 27th 2005
Reader Rating: 9
released, you may well find yourself struggling to keep up with the
latest tips and hacks. But those tips and hacks will save your sanity!
Here, I've put together the ten tips that I find most helpful, to save
you the hassle of scrounging around the Web for solutions when
time is tight.
Always begin on a new line
Height, line-height and top and bottom margins can be manipulated
Width defaults to 100% of their containing element, unless a width is specified
Begin on the same line
Height, line-height and top and bottom margins can't be changed
Width is as long as the text/image and can't be manipulated
To change an element's status, you can use display: inline or display: block. But what's the point of changing an element from being block to inline, or vice-versa? Well, at first it may seem like you might hardly ever use this trick, but in actual fact, this is a very powerful technique, which you can use whenever you want to:
Have an inline element start on a new line
Have a block element start on the same line
Control the width of an inline element (particularly useful for navigation links)
Manipulate the height of an inline element
Set a background colour as wide as the text for block elements, without having to specify a width
border: 1em solid green;
The first width command is read by all browsers; the second by all browsers exceptIE5 .x on PC. Because the second command comes second, it takes precedence over the first: any command that comes second will always override a preceding command. So, how does all this work?
By placing empty comment tags (/**/) before the colons, we instruct IE5.0 to ignore the command. Likewise, if we place empty comment tags after the colon, IE5.5 will ignore the command. Using these two rules in conjunction with each other, we can hide the command from all of IE5.x browsers.
Unfortunately, IE doesn't understand this command, so we'll need to come up with a new way of making this
functionality work in this browser. First, we'll insert a<div> under the<body> tag, as we can't assign a
minimum width to the<body>:
width:expression(document.body.clientWidth < 600? "600px" :
document.body.clientWidth > 1200? "1200px" : "auto");
}4. IE and Width and Height Issues
This can cause problems, because we may need boxes to be resizable should we need to fit more text into them, or
should the user resize the text. If we use only the width and height commands on a box, non-IE browsers won't
allow the box to resize. If we only use the min-width and min-height commands, though, we can't control the width
or height in IE!
This can be especially problematic when using background images. If you're using a background image that's 80px wide and 35px high, you'll want to make sure that the default size for a box using this image is exactly 80 x 35px. However, if users resize the text, the box size will need to expand gracefully.
This action might not be possible to undo. Are you sure you want to continue?