| Microsoft Typography | Web... | Specifying... | 5.5 Box properties | Negative margins | |||||||||||||||||||||||
|
The authors of the Cascading Style Sheet specification predicted that margins, especially negative margins, would be used to achieve interesting typographic effects. However, the use of margins in this way can be problematic. To see some of the problems, simply view the demonstration pages in our CSS gallery with style sheets disabled. The most interesting use of negative margins is in creating layered typographic effects and shadows.
To create the shadow effect shown in figure 1 the shadow layer is specified in the normal way. The second layer is drawn on top of the first by using a 'margin-top' property with a negative value. To move this layer a few pixels to the right 'margin-left' is applied. The code used to create the effect is shown below. <DIV STYLE="font-family: Arial Black;
font-size: 24px; color: black">
SpaceGun
</DIV>
<DIV STYLE="margin-top: -34px; margin-left: 3px;
font-family: Arial Black; font-size: 24px;
color: white">
SpaceGun
</DIV>
Figure 2 shows how this effect is presented in non CSS browsers. The W3C Style sheet solution to this problem is to propose a specific shadow property. This extendibility of the standard is one of its most important features. Unlike normal HTML, when designers demand a particular style sheet feature, there is no reason why it can't be discussed and added to the specification. Until the shadow property is finalized a possible work around is to use FONT attributes to make one of the text layers as small as possible and the same color as the background, an effectively invisible layer. The following code demonstrates the technique. <FONT COLOR=#BBBBDD SIZE=1> <DIV STYLE="font-family: Arial Black; font-size: 24px; color: black"> SpaceGun </DIV> </FONT> <FONT FACE="Arial Black" COLOR=#000000 SIZE=5> <DIV STYLE="margin-top: -34px; margin-left: 3px; font-family: Arial Black; font-size: 24px; color: white"> SpaceGun </DIV> </FONT>
As can be seen from theses screen captures, a CSS enabled browser will ignore any HTML FONT attributes such as FACE, COLOR or SIZE and use the STYLE attributes. However, in non CSS browsers, the converse is true. Here STYLE is ignored and the FONT attributes are used.
Working out the values required to achieve the desired layering effects can be difficult. You would have thought that to place a layer of text directly over the top of some other 20pt text you would specify a margin-top value of -20pt. Unfortunately this is not the case. The following code gives the results shown in figure 5. <DIV STYLE="font-family: Arial Black; color: red; font-size: 20pt;"> Layer One </DIV> <DIV STYLE="font-family: Arial Black; color: black; font-size: 20pt; margin-top: -20pt"> Layer 2 </DIV> The reason for this problem is that Microsoft® Internet Explorer automatically inserts space between lines of text. This needs to be taken into account when working the negative value required to produce the overlay. To make things more complicated the amount of space added between lines depends on the typeface specified.
<DIV STYLE="font-family: Arial Black; color: red; font-size: 20pt; line-height: 20pt"> Layer One </DIV> <DIV STYLE="font-family: Arial Black; color: black; font-size: 20pt; margin-top: -20pt; line-height: 20pt"> Layer 2 </DIV>
A word of warning is necessary. Using line-height with Internet Explorer 3 can result in unpredictable effects. For best results line-height needs to be specified for all the tags and classes used within the document.
The samples shown on this page are bitmap screen captures. The CSS and HTML code used to produce them has been commented out. Use View Source to access it.
|
|||||||||||||||||||||||
| Microsoft Typography | Web... | Specifying... | 5.5 Box properties | Negative margins | |||||||||||||||||||||||