11 | To learn more about ASP.NET, visit http://asp.net. 12 | The page features videos, tutorials, and samples to help you get the most from ASP.NET. 13 | If you have any questions about ASP.NET visit 14 | our forums. 15 |
16 |21 | 22 | | 23 |
30 | Home | 31 | Web Design Tutorials | 32 | Free Graphics | 33 | Custom Graphics | 34 | Newsletter | 35 | Products | 36 | Specials | 37 | SEO | 38 | Sound Effects | 39 | Benefits | 40 | Login | 41 | View Cart 42 | | 43 |
49 |
50 |
51 | How to Use Inline, Embedded, and External CSS52 | 53 | As explained in the previous two parts of this tutorial series, there are three ways to implement CSS in your web design. The how-to of it is explained below. Any and all methods can be used on a web page, but there are "best use" practices that, if you follow them, will prove to be the most efficient for you. These best uses are as follows: 54 | 55 |
Inline Styles69 | 70 | Using inline CSS is very much like coding an attribute and value into an HTML tag. Here's an example of an inline style rule. 71 |72 | <pre style="color: red; margin-left: 17px;"> 73 |74 | The above style rule is the same style I used to show code examples, only I don't use it inline (so I don't have to repeat it each time I want to show a code example). It's a simple <pre> tag with a style rule added. To cancel that style rule, use the </pre> just as you know from standard HTML. 75 | 76 | Using inline CSS only affects the HTML element that it's coded into. If you wanted to repeat that style at another place on your page, you'd have to code that style into each use of the element, in this case, another <pre> tag. 77 | 78 | There are a multitude of different things you can do with CSS, it's just a matter of learning what the options are and how to code them. I have 31 different HTML and CSS reference charts in my members area and demonstrate dozens of different CSS uses there. It's the one place where it's all put together for you in plain English. 79 | 80 | 81 |Embedded Styles82 | 83 | Embedded styles are placed in the HEAD section of a web page, placed between style declaration opening and closing tags. Unlike inline style rules where you have to code a style into each HTML element, embedded rules affect every usage of an HTML element on the page where it's embedded. Here's a example: 84 |85 | <style type="text/css"> 86 | div {font-family: Arial; font-size: 14px; margin-left: 30px;} 87 | p {border-left: 1px dotted gray;} 88 | </style> 89 |90 | If the above style rules were placed in the HEAD section of a web page's source code, here's how it would affect the page display: 91 | 92 |
99 | As you know, HTML elements are enclosed between the < and > brackets. Confusion would abound for webmasters and browser programmers alike if CSS also used arrow brackets. Therefore, the opening <style type="text/css"> and closing </style> tags identify the code in between as CSS code. 100 | 101 | The selector (the HTML element you wish to create a rule for) is listed without any brackets since it's already enclosed between the opening and closing style declaration. The selector is then followed by curly braces { ... } that enclose the property and value, which is the rule for the chosen selector. 102 | 103 | The property and value are separated by a colon and space. Example: 104 | 105 | color: red; 106 |107 | 108 | The semi-colon signals the end of a rule. Because each selector can have more than one rule, the semi-colon also serves as a rules separator. Example: 109 | 110 | color: red; background-color: black; font-size: 18px; 111 |112 | 113 | You should always include the semi-colon after a rule, even if you're only creating one rule. Truth is, a single rule will work most of the time if you forget the semi-colon, but results can be unpredictable in some instances. It's also a good habit. If you always include the semi-colon for single rules, there's less of a chance you'll leave one out where it's needed as a rules separator when you create multiple rules for one selector. 114 | 115 | External Styles116 | 117 | An external style sheet contains the style rules you create, saved in a plain text file, but with a .css file extension instead of a .txt file extension. To save a file with a .css extention, in most text editors you can simply place quotation marks around your file name as you save it. Example: 118 |119 | "MyStyles.css" 120 |121 | The contents of your linked style sheet is the same as you would place in an embedded style, minus the opening <style type="text/css"> and closing </style> tags. These are not needed because the browser knows it's a style sheet from the link to the style sheet. 122 | 123 | To link to a style sheet, place the following line of code in the HEAD section of your page: 124 | 125 | <link rel="stylesheet" href="css/sitewide.css" type="text/css" /> 126 |127 | There is no closing tag for this link. To make the code XHTML compliant, I closed the tag with a space and forward slash just before the right arrow bracket. You needn't do that if you don't care if your pages are XHTML compliant. 128 | 129 | Where I have css/sitewide.css, you'd change that to reflect the path to and name of your own style sheet. To see a real example of a simple external style sheet, try this one saved as a text file. You could save that file with a .css extension and link to it, and it would control the HTML elements that have rules created for them on all the pages you link to it from. 130 | 131 | 132 |133 | This tutorial continues... 134 | 135 | 136 | 137 |
138 | Back |
139 | Web Design Tutorials Index
140 |
141 |
142 |
143 | |
144 |
145 |
146 |
147 |
148 |
160 |
161 |
149 |
150 | ![]() Almost a Newsletter162 | 163 |
164 |
167 |
168 |
169 | Did you know...170 | The member's site has about 100 standards compliant HTML and CSS tutorials, 31 handy reference charts, reprintable content, web graphics, exclusive fonts, free software, free ebooks and more? All this for less than 9 cents a day! [ Details ] 171 | 172 | |
173 |
176 |
177 | Home | Web Design Tutorials | Free Graphics | Newsletter | Products | Specials | SEO | Sound Effects | Press Room
178 | 179 | Sitemap | 180 | Member Perks | Member Login | 181 | About BoogieJack.com | Contact | Privacy Policy | Copyright Policy | Links 182 | 183 | 191 | 192 |
193 |
194 | |
199 |
34 | İndirim Oranı (%) 35 | | 36 |37 | 38 | 39 | | 40 |
43 | İndirimli Fiyat (TL/kwh) 44 | | 45 |46 | 47 | 48 | | 49 |
13 | |
16 | |
19 | |
A Visual Studio Extension that helps to extract inline styles into a separate css file.
4 | 5 | Available on Visual Studio Marketplace 6 | 7 | https://marketplace.visualstudio.com/items?itemName=SuatKOSE.InlineStyleParserforHtmlFiles 8 | 9 | Supporting .html, .aspx and .cshtml file formats. 10 | 11 | Just right click on a html file source code and extract all inline styles into a separate css file. See the attached screenshots below. 12 | 13 | Please let me know if you realize that something is wrong. 14 | 15 | Thank you. 16 | 17 |1-Sample Html
18 |19 |
20 |
2-After Extracting Inline Styles
22 |
24 |
3-Created .css File
26 |
27 |