YUI contains several general CSS files that are useful for normalizing browser default style variations, font-sizes, and grid-based layouts. Additionally, many components also include a component-specific CSS files. While each component can be used without including the base CSS, for best results you should include them or incorporate them into your own CSS. This recipe will explore the global CSS files and explain how component-based CSS will work in the future.
To normalize variations in the default element styles across browsers, include:
<link href="pathToBuild/reset/reset-min.css" rel="stylesheet" type="text/css"/>
To set the base font-size of the Body
element to 10 pixels, include:
<link href="pathToBuild/font/font-min.css" rel="stylesheet" type="text/css"/>
To set some intelligent default styles to various elements, include:
<link href="pathToBuild/base/base-min.css" rel="stylesheet" type="text/css"/>
To use YUI to manage your layout, include:
<link href="pathToBuild/grids/grids-min.css" rel="stylesheet" type="text/css"/>
To use grids create a Div
element inside the Body
element and add one of the "doc" IDs to it ("doc", "doc2", "doc3", "doc4"), use code similar to the following:
<div id="doc2"> <div class="hd">Put header here</div> <div class="bd">Put body here</div> <div class="ft">Put footer here</div> </div>
Later in this book, we will include components which have their own custom CSS, such as the Logger component:
<link href="pathToBuild/logger/assets/skins/sam/logger.css" rel="stylesheet" type="text/css"/>
Components like Logger, will namespace all their styles below the"yui-skin-sam"
class, and therefore require the"yui-skin-sam"
to be added to an ancestor element of the component markup. Most developers choose to simply apply it to the Body element:
<body class="yui-skin-sam"> ... </body>
The reset CSS file applies rules that remove styles, such as font-sizes, padding, margins, and borders that may be applied to various elements by the browser. This ensures that CSS rules will be the same across browsers, as all elements start being styled the same way. The rules in this file have been built by the web community and are found on many sites and in many CSS frameworks.
The fonts CSS file adjusts the font-size of the Body element so that 1em is exactly 10 pixels (or as approximately close to 10 as possible). This makes building sites that scale according to font-size much easier. There are also a few additional rules that correct rounding errors and style discrepancies on several elements.
The base CSS file applies some intelligent default styles, since all the defaults have been reset, such as header (H1, H2, etc.) tag font-sizes, bolding of the Strong element, and italicizing of the Em element.
The grids CSS file sets up rules that can be used to layout the page. The example in this recipe will be centered on the page with a 950 pixel width, and have simple textual content for the header, body, and footer. You can use grids to manage simple or nested columns, and even more complex document sections. To find out more about what you can do with grids, see: http://developer.yahoo.com/yui/grids/.
The CSS for components will be mentioned in their respective chapters, but it is important to remember that the files are generally located at "someComponent/assets/skins/sam/someComponent.css
" and that the"yui-skin-sam"
class needs to be applied to an ancestor of the component markup for the styles to be applied.
Additionally, there are two convenient files that combine the minified versions of reset, font, and grid for use in your production environment:
<link href="pathToBuild/reset-fonts/reset-fonts.css" rel="stylesheet" type="text/css"/> <link href="pathToBuild/reset-fonts-grids/reset-fonts-grids.css" rel="stylesheet" type="text/css"/>