Stylizer 5 Internals

This information is historical and applies only to Stylizer 5.
  1. Initialization
  2. Clearfix
  3. Shortcut Properties
  4. Placement Modes
  5. Image Replacement
  6. Media Types
  7. Browser Filters

Initialization vs. CSS Reset

The Initialization feature in Stylizer is loosely related to what is known as CSS reset in the industry. The feature is called Initialization instead because the two have a different goals. The goal of CSS reset is to totally eradicate all forms of default styling from the browser. Many designers question the practicality of this, as they are then required to go back and re-add much of what was removed. The goal of Initialization is to make the CSS development process more intuitive and predictable. The CSS generated by Initialization will be reviewed here.

How to use Initialization

To add Initialization to a style sheet, simply right-click on the style sheet and choose Add Initialization. Then, a new expandable row is added to the style sheet. Inside, there are 6 options. The first 4 options define the default text settings. The next two are more complicated.

Star Position Relative

Setting most of the elements on the page to position: relative fixes a variety of problems in non-modern browsers, and makes the left, right, top and bottom CSS properties more useful. All margins and paddings are zeroed out, and the font size of 1em is set on all elements. This will cause the font size of all elements to default to the font size defined on the body element.

Here is the first rule generated:

* {
    margin: 0;
    padding: 0;
    font-size: 1em;
    position: relative;
}

While positioning every element as relative has its benefits, there are a few kinds of elements that shouldn't use relative positioning, as handled by the next generated rule:

HTML, BODY, THEAD, TBODY, TFOOT, TR, TH, TD {
    position: static;
}

Note that the position: relative declaration isn't generated when the -everything-relative setting in Stylizer is off. The next rule contains the first 4 Initialization settings. These settings are applied to the page's Body element, which will then be inherited down through the entire page.

BODY {
    font-size: 11pt;
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    line-height: 1.5;
    letter-spacing: -1px;
}

Unfortunately not all elements on the page will inherit the settings above without additional CSS. For example, heading elements and the TH element render with a bold font by default. Simply setting these elements to font-weight: normal would break the inheritance model. Ideally, the element should acquire it's font weight from it's containing element. This is a trivial task in CSS, however, inheritance doesn't work as it should in Internet Explorer 6 and 7. Fortunately, Skybound has devised a work around. Examine the code below:

H1, H2, H3, H4, H5, H6, TH {
    font-weight: inherit;
    =font-weight: expression(
    this.__FW ? this.__FW : 
    (new Function("t",
    "return (t.__FW=t.parentNode.currentStyle.fontWeight)"))(this)
);
}

All headings and the TH element have been set to inherit their font weight from their containing element. Then, in Internet Explorer 6 and 7 only (via the equal hack), a Single Execution CSS Expression is used to collect the value from the parent element, cache it, and assign it to the font weight. Subsequent executions of the expression will return the cached value, for optimal performance.

The next rule does the same thing with the 4 elements that are browsers italicize by default:

ADDRESS, CITE, DFN, VAR {
    font-style: inherit;
    =font-style: expression(
    this.__FS ? this.__FS : 
    (new Function("t", "return (t.__FS=t.parentNode.currentStyle.fontStyle)"))(this)
    );
}

Finally, the next rule does the same thing with the 10 rules that render with a different font by default:

CAPTION, CODE, KBD, PRE, SAMP, TT, INPUT, TEXTAREA, SELECT, BUTTON {
    font-family: inherit;
    =font-family: expression(
    this.__FF ? this.__FF : 
    (new Function("t", "return (t.__FF=t.parentNode.currentStyle.fontFamily)"))(this));
}

The next rule avoids an issue with older versions of Firefox, where hidden input fields are displayed rendered as a box on the screen.

INPUT[type=hidden] {
    display: none !important;
}

Table heading elements center their content by default. The next rule causes these elements to inherit their content alignment setting from the containing element.

TH {
    text-align: inherit;
}

Fieldset elements as well as images placed inside anchors are rendered with unattractive and undesirable borders by default. The next rule eliminates that problem:

FIELDSET, A IMG {
    border: 0;
}

Things you need to know

  • Only include Initialization once per web site, not on every style sheet.
  • Initialization should be added at the beginning of the development process. In general, it should not be added to an already existing site, as it would likely create more problems than it would solve.
  • Setting -everything-relative to on may cause some third party widgets and interface libraries to render improperly. A quick fix for this problem would be to wrap the widget in a container (if possible), and create a rule in the style that looks like this: .container * { position: static; }
Back to top

Floating Children: The Problem

If an element is styled as float: left or float: right, it's container does not expand downward to include it in its size, as shown below.

Unfortunately this is seldom the desired goal. However, it is possible to change the rendering behavior of the containing element, to force it to expand downward, as shown below:

To change an element to exhibit the behavior featured above, simply click the Clearfix button on the Remote Control.

How Stylizer Handles Clearfix

Stylizer essentially automates the industry-standard solution to this problem (known as "clearfix"). When a CSS file is saved, the selectors of all clearfixed CSS rules are collected, and 3 rules are created at the top of the style sheet that adjust the float expansion behavior of all the necessary elements. Given the following information in Stylizer:

/*[clearfix]*/ .a {
}
/*[clearfix]*/ .b {
}
/*[clearfix]*/ .c {
}

The following CSS is generated:

.a:after, .b:after, .c:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
    font-size: 0;
}
.a, .b, .c {
    display: inline-block;
}
.a, .b, .c {
    /*\*/
    display: block;
    /**/
    _height: 1px;
}

With this method, it's possible to change the float expansion behavior quickly right from CSS. You don't need to follow the inconvenient practice of opening the underlying HTML, and appending a class=clearfix attribute to every element that needs to exhibit the expansion behavior.

Things you should know

While creating CSS, you should avoid the situation of elements spilling outside their containers, as it tends to introduce complications, especially when trying to make the design compatible with non-modern browsers. Liberal usage of the float-expansion property tends to cut down on browser compatibility complications.

Back to top

About Shortcut Properties in Stylizer

Oftentimes in CSS, there is a means to achieve a certain effect, but the implementation is unnecessarily complicated, or it varies between different browsers. In an attempt to further streamline the CSS development process, Stylizer uses Shortcut Properties to provide an entry point for these possibilities without having to handle these complications. Shortcut properties are special CSS properties unique to Stylizer that generate CSS in the underlying file. Stylizer has the following properties:

+border-radius

There are 4 different ways to specify a border-radius on an element. In Stylizer, if the following is defined:

.selector {
    +border-radius: 5px;
}

The following CSS is generated in the underlying CSS file:

.selector {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -khtml-border-radius: 5px;
    border-radius: 5px 5px 5px 5px;
}

+box-shadow

There are 4 different ways to specify a box-shadow on an element. In Stylizer, if the following is defined:

.selector {
    +box-shadow: 1px 2px 5px #222222;
}

The following CSS is generated in the underlying CSS file:

.selector {
    -moz-box-shadow: 1px 2px 5px #222222;
    -webkit-box-shadow: 1px 2px 5px #222222;
    -o-box-shadow: 1px 2px 5px #222222;
    box-shadow: 1px 2px 5px #222222;
}

+box-sizing

The box-sizing property allows designers to toggle between the W3C box model, and the intuitive box model. The property is handled differently between browsers. In Stylizer, if the following is defined:

.selector {
    +box-sizing: border-box;
}

The following CSS is generated in the underlying CSS file.

.selector {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    box-sizing: border-box;
}

+image-replace

The +image-replace shortcut property automates Image Replacement. Further details are discussed in the Image Replacement topic.

+min-height

Internet Explorer 6 and earlier treats height as though it were min-height. This shortcut property generates two declarations to handle both cases:

.selector {
    +min-height: 100px;
}

The following CSS is generated in the underlying CSS file.

.selector {
    -height: 100px;
    min-height: 100px;
}

+opacity

There are 4 different ways to specify opacity on an element, each browser requiring a different technique. In Stylizer, if the following is defined:

.selector {
    +opacity: 50%;
}

The following CSS is generated in the underlying CSS file:

.selector {
    -filter: alpha(opacity=50);
    -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
    -moz-opacity: 0.5;
    opacity: 0.5;
}

+placement

The +placement shortcut automates the various methods of positioning elements on the page. Further details are discussed in the Placement Modes topic;

Back to top

Placement Modes in Stylizer

You may be familiar with the three options available in the CSS position property: static, relative, and absolute. However, these three positioning options are not representative (in the practical sense) of the methods web designers use to position elements on a web page.

Placement modes are Stylizer's attempt to package the CSS positioning system into an intuitive model. There are 3 main options: Anchor, Shift and Displace. Although we feel the names we've chosen best describe the logic, some designers may use other names (or no name at all) for the same practice.

Placement modes require a mode setting (Anchor, Shift, Displace), as well as X and Y coordinates. Each mode interprets these coordinates differently.

Anchor

Anchoring means that the element is removed from the flow of the layout, and is drawn on it's own layer on top of the rest of the page. Then, it is positioning a fixed distance away from one of the corners of the containing element.

In technical terms, anchoring sets an element as position absolute. Then it's containing element as set to position relative. Finally, the top & left, top & right, bottom & left, or bottom & right CSS properties set the element a certain distance away from one of the four corners of the containing element.

When the web site uses Initialization, each element's default positioning option is relative. In this case, elements will always anchor to their containing elements, which is most often the desired result.

Shift

When an element is Shifted, it is not removed from the flow of the layout. It is only visually shifted away from it's original location.

In technical terms, Shifting sets an element to position relative. Then, the top and bottom properties are used to Shift the element away from it's original location.

Displace

Displace is similar to shift, except the element is removed from the flow of the layout.

In technical terms, Displace sets the element to position absolute. When an element is set to position absolute and none of the top/bottom/left/right are used, the element is remains in it's original location, but is removed from the flow of the layout. Then, negative and positive amounts of margin-top and margin-left properties are used to shift the element away from it's original location.

The Secondary Placement Modes

In addition to Anchor, Shift, and Displace, Stylizer also has support for 3 other placement modes: float:left, float:right, and margin:auto. These align an element to the left, to the right, or center it, respectively. Technically there is no difference between using these placement modes and simply adding a float: left declaration to the rule, except that it's possible to add the declaration with a few mouse clicks, as opposed to entering the information manually.

Also, when a secondary placement mode is used, the option is also available to shift the element up, down, left, or right.

What about Fixed positioning?

If you want to get technical, Fixed positioning at it's core is just a fancier way of Anchoring an element to the window, and then placing the entire contents of the web site in an DIV set to overflow:auto, whose dimensions match the window.

Back to top

Image Replacement: What is this and why do I need it?

Image Replacement is a technique which replaces ordinary text on a web site with a more visually appealing image. It is not yet possible to achieve certain visual text effects using CSS alone, so images can be used instead.

The most obvious solution is to simply place an <img> tag in the HTML that references the image. With this solution however, the physical text displayed in the image would not be located in the HTML source code, causing a variety of complications, such as:

  1. The text inside the image will not contribute to the overall keyword count, potentially harming search rankings.
  2. The web browser's find function will not locate the content inside the image.
  3. Unless it is high-resolution, the image will not look as crisp as other text on the page when printed.
  4. The text will not be read by a screen reader.
  5. If the user has images turned off, the user experience is degraded much more than it needs to be, especially in Internet Explorer.
  6. Implementing a proper CSS roll-over (adjusting the background position on mouse over) isn't feasible, as these require a background image, instead of an image tag.

There are a number of ways to achieve this, each introducing their own set of new complications. Skybound has devised a method that suffers essentially no adverse side effects. It is built into Stylizer.

How to use Image Replacement in Stylizer

To replace text with an image, simply use Stylizer's +image-replace shortcut property. Upon adding this property to your style sheet, Stylizer will check to see if the proper JavaScript snippet was added to your web site. If not, a dialog will appear that will walk you through the steps of adding the script to your page.

+image-replace accepts one value, which is the URL of the image to use as the replacement. Enter the URL of the image to use as the replacement, and Stylizer will handle the rest.

Behind the scenes, Image Replacement uses a CSS background image. Therefore, regular background-position properties can be used to change the horizontal and vertical offset of the background image. This makes it possible to use CSS roll overs and/or image sprites in conjunction with Image Replacement.

How Skybound's Image Replacement Works

Skybound's Image Replacement method uses a clever JavaScript technique to detect whether images are enabled in the browser. If images are enabled, the class name images-on is appended to the document element (the root <html> tag). Then, given the following +image-replace shortcut property:

.logo {
    +image-replace: url(logo.png);
}

The following CSS is generated in the underlying CSS file.

.logo {
    /*+image-replace:url(logo.png);*/
    display: block;
}
@media screen {
    .images-on .logo {
        background-image: url(logo.png);
        background-repeat: no-repeat !important;
        text-indent: -1000000px !important;
        overflow: hidden;
    }
}

The CSS above pushes the text of the left edge of the screen and applies the background image. It ensures that this will only happen on the screen, and only if images are enabled. In other instances, the regular text will be displayed. The technique will never cause the user to be presented with a blank space (no text and no image), as is the case with many other image replacement techniques.

Things you should know

  • When your web page is printed, the regular text will be printed instead of the images.
  • If the user has JavaScript disabled, the regular text will be displayed instead of images.
Back to top

Per-Property Media Types

CSS allows a designer to provide separate styles for different target media types. For example, a designer may provide a master style sheet, plus different style sheets for print, screen and handheld.

Satellite style sheets targeting a specific media type rarely restyle the entire document; instead, they override only specific styles defined in the master style sheet to correct the page’s appearance. For example, a page with a dark background and light-colored text might want to invert this color scheme when the page is printed.

Essentially, there are 3 ways to specify a target media type:

  1. By including a media attribute on the link tag which references style sheet
  2. By specifying a media type after the URL of an @import directive
  3. By creating a media block within the style sheet

The first two define the media type for an entire style sheet, while the third can be used for one or more individual rules. Stylizer takes the concept one step further by allowing a designer to tag an individual style declaration with a target media type. Of course, CSS does not support this directly: in the underlying CSS file, Stylizer moves the declarations into separate rules, using an @media block to enclose the declarations whic have a target media type sepcified. This all happens transparently—when using Stylizer, it is as if CSS had already provided this additional functionality.

To tag a declaration with a target media type, click on the flag button in the Context Bar. Then, choose the media type applicable to the style declaration. An icon will appear on the right side of the property value grid cell indicating the target media type. Each declaration may only have a single target media type.

Back to top

What Are Browser Filters?

Browser filters are a special way of writing CSS so that certain styles are only visible to a single set of browsers. Stylizer streamlines this process at a high level. In Stylizer, you specify the set of browsers that are able to see a given property, and Stylizer applies the appropriate browser filter in the underlying CSS file.

How to Define a Browser Filter in Stylizer

Click on the value of the property that should receive the browser filter, then click on the flags button in the context bar. Next, choose the desired browser filter. A descriptive icon will display in the value cell to indicate that the style is not visible to all browsers.

How Browser Filters look in the Underlying CSS

Below is a table of all the browser filters provided by Stylizer, and the format of the CSS that is generated:

Only IE 8 or less property: value\0/;
Only IE 7 or less =property: value;
Only IE 6 or less -property: value;
Hide in IE 6 property /**/: value;
Hide in IE 5.5 or less pr\operty: value;
Hide in IE 5 or less property/* */: value;

You should know:

If you're already familiar with the various available browser filters (such as the dash hack), Stylizer doesn't stop you from entering these styles directly into the grid.