03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

102 x CHAPTER 3 DESIGNING YOUR WEB PAGES<br />

10. If you haven’t already merged the two h1 selectors, open Styles.css <strong>and</strong> scroll down to the end<br />

of the file. Copy the two l<strong>in</strong>es for the padd<strong>in</strong>g <strong>and</strong> marg<strong>in</strong> properties to the clipboard <strong>and</strong> then<br />

delete the entire selector. Scroll up <strong>in</strong> the file <strong>and</strong> then paste the two CSS rules <strong>in</strong>side the other h1<br />

selector. You should end up with this code:<br />

h1<br />

{<br />

font-size: 20px;<br />

padd<strong>in</strong>g: 0;<br />

marg<strong>in</strong>: 0 0 10px 0;<br />

}<br />

11. Save any pend<strong>in</strong>g changes you may have <strong>and</strong> then open Default.aspx <strong>in</strong> your browser by press<strong>in</strong>g<br />

Ctrl+F5. Note that the paragraphs haven’t changed <strong>and</strong> still use the same blue <strong>and</strong> italic font.<br />

How It Works<br />

Unfortunately, VS doesn’t allow you to move <strong>in</strong>l<strong>in</strong>e styles to external style sheet files. However, by<br />

creat<strong>in</strong>g a copy of the exist<strong>in</strong>g style, <strong>and</strong> then delet<strong>in</strong>g the orig<strong>in</strong>al <strong>in</strong>l<strong>in</strong>e style, you can achieve the<br />

same effect. Mov<strong>in</strong>g embedded or external style sheets between files is a lot easier. You can simply<br />

drag a style from one file to another, <strong>and</strong> VS will automatically move the code for you. This makes it<br />

extremely easy to organize your CSS. Instead of leav<strong>in</strong>g all your embedded CSS <strong>in</strong> your page because<br />

you’re afraid to touch it, you can now simply drag <strong>and</strong> drop it <strong>in</strong>to an external file. This makes it a lot<br />

easier to reuse those styles <strong>in</strong> other pages, decreas<strong>in</strong>g page size <strong>and</strong> page bloat, <strong>and</strong> mak<strong>in</strong>g your site a<br />

lot easier to manage. Obviously, it’s important that the file you are mov<strong>in</strong>g your CSS to is attached to<br />

the pages you’re work<strong>in</strong>g with.<br />

PRACTICAL TIPS ON WORKING WITH CSS<br />

Follow these tips to make the most of CSS:<br />

‰ Take some time to familiarize yourself with the many properties that CSS supports. The<br />

best way to do this is to create a br<strong>and</strong>-new page <strong>in</strong> your Demos folder, create a few HTML<br />

elements like <strong>and</strong> tags, <strong>and</strong> then simply experiment with all the different properties.<br />

By try<strong>in</strong>g out many of the properties on the CSS Properties Grid, you get a feel for what<br />

options you have available. This makes it easier later if you want to apply a certa<strong>in</strong> effect to<br />

some piece of content.<br />

‰ When creat<strong>in</strong>g custom CSS classes, try to come up with names that describe the behavior of<br />

the rule, rather than the look <strong>and</strong> feel. For example, a class called .Introduction to style<br />

the first paragraph of a page is a good description. It enables you to change the underly<strong>in</strong>g<br />

values without affect<strong>in</strong>g the actual mean<strong>in</strong>g of the name. But classes with names like<br />

.BlueAndItalic are guaranteed to give you problems later. What if you decide to change<br />

the blue to black later? You either end up with a very odd class name not describ<strong>in</strong>g its own

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!