{"id":4369,"date":"2015-06-22T07:56:45","date_gmt":"2015-06-22T07:56:45","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4369"},"modified":"2015-06-22T07:56:45","modified_gmt":"2015-06-22T07:56:45","slug":"css-tutorial","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/css-tutorial\/","title":{"rendered":"CSS Tutorial"},"content":{"rendered":"<p>CSS stands for Cascading Style Sheets, and is a code that describes how to display HTML.<\/p>\n<p>In the previous <a href=\"http:\/\/www.codeconquest.com\/tutorials\/html\/\">HTML tutorial<\/a>, we told you that the HTML <code>&lt;strong&gt;<\/code> tag makes text bold, and the <code>&lt;em&gt;<\/code> tag makes text italic. Well, not really. HTML doesn\u2019t actually make text bold or italic \u2013 it only suggests that text should be bold or italic. It\u2019s actually CSS that delivers the instruction.<\/p>\n<p>CSS can deliver many different instructions for how to display HTML. Telling the browser to find all the <code>&lt;strong&gt;<\/code> elements and make them bold, or to find all the <code>&lt;em&gt;<\/code> elements and make them italic are just two examples.<\/p>\n<p>Here\u2019s what CSS code looks like.<\/p>\n<pre><code>strong {\r\n    font-weight: bold;\r\n}\r\nem {\r\n    font-style: italic;\r\n}\r\nh1 {\r\n    font-size: 32px;\r\n}<\/code><\/pre>\n<h2>CSS Rules<\/h2>\n<p>Looking at the above example, you can see that a CSS rule is made up of three parts: a selector, a property and a value.<\/p>\n<p>The text outside of the curly brackets is called the selector. It\u2019s simply the name of the HTML tag, without the &lt; and &gt;. The selector indicates which HTML element the below styles are to be applied to.<\/p>\n<p>The text on the left side of the colon is called the property. This the type of style being applied; for example, font weight, font style or font size.<\/p>\n<p>The text on the right side of the colon is called the value, and is the style that\u2019s being applied. Some values use certain units \u2013 for example, font sizes are written in terms of pixels (px).<\/p>\n<h2>Inline CSS<\/h2>\n<p>Web browsers have default CSS styles for displaying HTML \u2013 for example, instructing text inside <code>&lt;strong&gt;<\/code> tags to display as bold, or text inside <code>&lt;h1&gt;<\/code> tags to be 32 pixel font.<\/p>\n<p>However, each website adds its own custom CSS as well. One way websites do this is by embedding their CSS style right inside its corresponding HTML tag, using an HTML attribute. For example, to display a <code>&lt;strong&gt;<\/code> element in purple, here is the code that would be used:<\/p>\n<pre><code>&lt;strong style=\"color: purple;\"&gt;I am purple.&lt;\/strong&gt;<\/code><\/pre>\n<p>The result is:<\/p>\n<section class=\"short d\"><strong>I am purple.<\/strong><\/p>\n<\/section>\n<p>Notice that there\u2019s the word style (the attribute), followed by an equals sign, followed by a set of quotation marks that contain the CSS code. Also notice that there is no selector, because it\u2019s already clear which element is being targeted.<\/p>\n<h2>Internal CSS<\/h2>\n<p>Inline CSS is uncommon, because it slows down page loading time. A more common method is to gather all the CSS styles together and place them within <code>&lt;style&gt;<\/code> HTML tags. This is called an internal style sheet.<\/p>\n<pre><code>&lt;style&gt;\r\nh1 {\r\n    color: red;\r\n}\r\nh2 {\r\n    color: black;\r\n}\r\n&lt;\/style&gt;<\/code><\/pre>\n<p>The <code>&lt;style&gt;<\/code> element belongs in the <code>&lt;head&gt;<\/code> of a web page, along with the title, description and other informational elements. An internal style sheet can contain as many CSS rules as the page needs, for as many different HTML elements as the page has.<\/p>\n<h2>External CSS<\/h2>\n<p>There is a third way websites add CSS, and that is writing it in a separate file. The benefit of this is that they can link the same CSS file to multiple pages on their site. This is the method that the majority of websites use.<\/p>\n<p>When CSS is written in an external file, it needs to be linked up with the main HTML. To do this, websites use the following HTML tag:<\/p>\n<pre><code>&lt;link rel=\"stylesheet\" href=\"style.css\"&gt;<\/code><\/pre>\n<p>The <code>rel=\"stylesheet\"<\/code> attribute indicates that it\u2019s a style sheet that\u2019s being linked to. The href attribute specifies the file name of the style sheet \u2013 in this case style.css. Notice that there is no closing tag.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS stands for Cascading Style Sheets, and is a code that describes how to display HTML. In the previous HTML tutorial, we told you that the HTML &lt;strong&gt; tag makes text bold, and the &lt;em&gt; tag makes text italic. Well, not really. HTML doesn\u2019t actually make text bold or italic \u2013 it only suggests that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4370,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[5],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4369"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4369"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4369\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4370"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}