CSS externalExternal stylesThe true power of CSS is separating presentation from content. External stylesheets are the tool for doing exactly this. By putting all your CSS rules into a separate .css file (a simple text file) you can re-use them for all your pages without rewriting. All your styles are in a centralized place making it easy to maintain and change the look of your website. Linking external stylesheetsTo include one or more stylesheets into your HTML document you can use the External CSS:<head>
<title>External CSS styles</title> <link type="text/css" rel="stylesheet" media="all" href="style.css" /> </head>
Usage guidelines1. Use as much as possibleTry to put all your CSS styles into stylesheets and minimize your inline CSS and internal CSS. 2. Use a logical structureAs a CSS beginner you probably won't care much about the order in which you write your CSS rules because your stylesheets will be relatively small. As they get bigger, though, it can help having a logical structure in your stylesheet. For example you could group general selectors such as 3. Comment your CSSIt's good practice to comment your code so that you can remember and others can understand what it's doing. Don't go overboard with adding CSS comments though, as it will increase the file size unnecessarily. Just comment the main sections of your CSS file and any special rules that are not easily understood. 4. Naming your stylesheetIt's an unofficial naming convention that the main stylesheet is called style.css. It can't hurt adopting this for yourself. 5. Use F5 to display recent changesWhen you're making changes to your stylesheets you have to press the F5 key (sometimes even CTRL+F5 which causes a more thorough refresh in some browsers) to force the web browser to refresh the page and load the newest version instead of using the cached one. |