Web design creating cool web sites with html, xhtml, and css

Page 92

Chapter 4: Moving into the 21st Century with Cascading Style Sheets

65

If you’re starting to think, “Hey, this stuff is pretty darn powerful,” you’re right! CSS is a thou­ sand times more powerful than even the fanciest HTML formatting, and there’s no question that it’s the future of Web page design and layout. The price, as you can already see, is that it’s more complex. There is quite a bit of difference between <b>bold</b> and <span style=”font-weight: bold;”>bold</span>, but stick with me and you’ll get the hang of things. You may soon find that you are creating exceptional pages—and with darn little work!

Adding comments within CSS Here’s another little tip: You can add comments to your CSS in two different ways. For a singleline comment, use two slashes; anything after them is ignored through the end of the line, as in the following example: b { font-weight: normal; } // disabled bold for this page

If you need a multiline comment, wrap it in /* and */ pairs, as shown in the following example: <style type=”text/css”> b { font-weight: normal; } /* The head of layout suggested that we disable all bold text as an experiment, so we’ve done so. – DaveT, Oct 11 */ </style>

Compatible style blocks If you’re big on backwards compatibility, consider wrapping all your style blocks as I have in the following example: <style type=’text/css”> <!— b { font-weight: normal; } // —> </style>

If the Web browser understands style sheets, it ignores the comment characters, and if the browser doesn’t understand CSS, it assumes that all the stuff within the <!— and —> span is a comment and hides it from the final rendered page. In fact, even without CSS, you can always add comments to your HTML pages by surrounding them with <!— and —>. They show up in the source code but aren’t displayed in the actual Web page you see in a browser.

note

I have to admit that I typically do not use the comment sequence to hide my style blocks. CSS-compatible Web browsers first came out in 1997, so by this point, the vast majority of users should have browsers that can render CSS properly. You can make your own call, however, as there are definitely different opinions on this subject.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.