{"id":740,"date":"2020-01-04T16:34:18","date_gmt":"2020-01-04T21:34:18","guid":{"rendered":"http:\/\/newmediaproduction.mynmi.net\/?page_id=740"},"modified":"2020-01-04T16:34:18","modified_gmt":"2020-01-04T21:34:18","slug":"intro-css","status":"publish","type":"page","link":"https:\/\/nmi.cool\/webdev\/intro-css\/","title":{"rendered":"CSS"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"1500\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/14\/2020\/09\/css_doorway.jpg\" alt=\"\" class=\"wp-image-2357\" style=\"width:683px;height:1024px\" srcset=\"https:\/\/nmi.cool\/webdev\/wp-content\/uploads\/sites\/14\/2020\/09\/css_doorway.jpg 1000w, https:\/\/nmi.cool\/webdev\/wp-content\/uploads\/sites\/14\/2020\/09\/css_doorway-200x300.jpg 200w, https:\/\/nmi.cool\/webdev\/wp-content\/uploads\/sites\/14\/2020\/09\/css_doorway-683x1024.jpg 683w, https:\/\/nmi.cool\/webdev\/wp-content\/uploads\/sites\/14\/2020\/09\/css_doorway-768x1152.jpg 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">Photo by&nbsp;<a href=\"https:\/\/unsplash.com\/@efekurnaz?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Efe Kurnaz<\/a>&nbsp;on&nbsp;<a href=\"https:\/\/unsplash.com\/s\/photos\/style?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a>.<\/figcaption><\/figure>\n\n\n\n<p><strong>Cascading Style Sheets (CSS)<\/strong> controls the style of webpages. <\/p>\n\n\n\n<p>By creating CSS <strong>rules<\/strong>, you can add styles to certain elements in your HTML pages. For example, you can change your background color, set your font to Helvetica, or italicize a subheading\u2014you get the idea.<\/p>\n\n\n\n<p>First, it\u2019s important to identify two different types of HTML elements.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Block elements<\/strong> always start on a new line. These include tags such as &lt;h1&gt;, &lt;p&gt;, and &lt;div&gt;.<\/li>\n\n\n\n<li><strong>Inline elements <\/strong>flow within the text. They don\u2019t naturally start on a new line (think bolding text, such as &lt;b&gt;, adding images, &lt;img&gt;). <\/li>\n<\/ol>\n\n\n\n<p>When it comes to visualizing CSS, pretend that each HTML element has an invisible block around it. We will be applying rules to these invisible blocks\u2014rules that dictate the style of that particular element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Three ways to add style<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Inline CSS: <\/strong>the least elegant of all the ways to add CSS to your HTML. With inline styling, you add your CSS style to every element on the page. This is the least efficient way to add CSS because you had to modify every single HTML element, one by one. <\/li>\n\n\n\n<li><strong>Internal CSS: <\/strong>A slightly quicker way to add CSS is with <code>&lt;style&gt;&lt;\/style&gt;<\/code> tags within the <code>&lt;head&gt;<\/code> tag of your page. <strong>This is best when you are applying styles to only ONE webpage.<\/strong><\/li>\n\n\n\n<li><strong>External CSS: <\/strong>The third, and most professional way, is to create an external stylesheet. This is a separate <code>.css<\/code> file that is linked to each HTML file you\u2019d like to style.\u00a0This way, you can create one master stylesheet to rule them all. This is what we&#8217;ll use for every graded project you turn in for this class. <\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Inline CSS<\/h2>\n\n\n\n<p>Inline CSS is clunky and inefficient, and best if you&#8217;re only targeting one particular HTML element. To write inline CSS, you modify your already existing HTML element tag to include style.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h3 style=\"font-size: 36px\"&gt; This title is now 36 px. &lt;\/h3&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Internal stylesheets<\/h2>\n\n\n\n<p>To add an internal stylesheet, directly under your title tags, in the <code>&lt;head&gt;<\/code> section, you&#8217;d add style tags:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!doctype html&gt; \n&lt;html&gt; \n&lt;head&gt;     \n    &lt;title&gt;Hello world!&lt;\/title&gt; \n   <strong> &lt;style&gt; Add your CSS rules here. &lt;\/style&gt;<\/strong>\n&lt;\/head&gt; \n\n&lt;body&gt; \n\n&lt;\/body&gt; \n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>To start stylin&#8217;, all you need to do is write some CSS rules in between the style tags.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"externalcss\">External stylesheets<\/h2>\n\n\n\n<p>Within your <code>&lt;head&gt;<\/code> tag in your HTML files, you can link to an <strong>external stylesheet link:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;link href=\"css\/style.css\" rel=\"stylesheet\"&gt;<\/code><\/pre>\n\n\n\n<p>Please note there is <strong>no closing tag<\/strong>, meaning, this is an empty element. <\/p>\n\n\n\n<p>The <code>href<\/code> portion points to the CSS file, which is usually located in a folder appropriately named <code>css.<\/code> If your file is named something besides <code>style.css<\/code> or housed in a different folder, you&#8217;ll need to update the <code>href<\/code> value so that it matches your file name and location. <br><br><code>Rel<\/code> stands for relationship.<\/p>\n\n\n\n<p>Additionally, you can link multiple stylesheets to one HTML page.<\/p>\n\n\n\n<p><strong>Note:<\/strong> Older versions of HTML will have you also include <code>type=\"text\"<\/code> in the stylesheet link. If you see this, just know that it refers to the type of document being linked. It won&#8217;t hurt to include it, but you don&#8217;t technically need it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>CSS Rules<\/strong><\/h2>\n\n\n\n<p>This is the basic structure of a CSS rule:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {font-family: Georgia; \ncolor: blueviolet;}\n\np {font-size: 16px; \nfont-family: Verdana;}<\/code><\/pre>\n\n\n\n<p><strong>Selector: <\/strong>h1, p <br>The selector refers to the element you want the style applied to.<br><br><strong>Declaration: <\/strong>{font-family: Georgia; color: blueviolet;}<br>The declaration is the part in the curly brackets. The declaration includes information on how the elements should be styled, written in the form of properties and values. <br><br>In other words: <strong>selector {declaration}<\/strong><\/p>\n\n\n\n<p><strong>Properties and values:<\/strong> {property: value; property: value;}<br>Within the declaration, you have <strong>properties<\/strong> followed by <strong>values<\/strong>. Each property is separated by a semi-colon. <br><br>In the above example, font-family is a property, followed by the value of Georgia. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"colors\">Adding colors<\/h2>\n\n\n\n<p>The <strong>predefined color options<\/strong> (the ones that appear as simple names such as blueviolet) are ones recognized by many browsers.<\/p>\n\n\n\n<p><strong>Hex codes <\/strong>are another way to add color. Hex codes are six-digit codes that represent the amount of red, green, and blue in that particular shade. They always start with a hashtag, for example, <strong>#BA0C2F<\/strong> is UGA&#8217;s official Bulldog Red.<\/p>\n\n\n\n<p>To change the color of a paragraph, you add a &#8220;p&#8221; selector followed by the declaration: {color: green;}<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;  \n  &nbsp;&nbsp;&nbsp;&lt;title&gt;Hello World!&lt;\/title&gt; \n     &lt;style&gt;\n           <strong>p {color: green;}<\/strong>\n     &lt;\/style&gt;\n&lt;\/head&gt; \n&lt;body&gt; \n   &lt;p&gt; This text is now green. &lt;\/p&gt;\n&lt;\/body&gt; \n&lt;\/html&gt; <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Selecting colors<\/h2>\n\n\n\n<p>Colors must have <strong>high contrast<\/strong>\u2014meaning, you would never have light gray text on a medium gray page; or pink text against a purple background. <\/p>\n\n\n\n<p>Text is easiest to read when there is high contrast between colors, especially for accessibility purposes.<\/p>\n\n\n\n<p>Here are two of my favorite websites that generate color combinations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a aria-label=\"Coolers.co (opens in a new tab)\" href=\"https:\/\/coolors.co\/\" target=\"_blank\" rel=\"noreferrer noopener\">Coolers.co<\/a><\/li>\n\n\n\n<li><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/color.adobe.com\/create\" target=\"_blank\" rel=\"noreferrer noopener\">Adobe Color<\/a><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">The possibilities with CSS are endless. Check out this list of <a rel=\"noreferrer noopener\" aria-label=\"CSS properties (opens in a new tab)\" href=\"https:\/\/www.w3schools.com\/cssref\/default.asp\" target=\"_blank\">CSS properties<\/a>!<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>Cascading Style Sheets (CSS) controls the style of webpages. By creating CSS rules, you can add styles to certain elements in your HTML pages. For example, you can change your background color, set your font to Helvetica, or italicize a subheading\u2014you get the idea. First, it\u2019s important to identify two different types of HTML elements. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-740","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/pages\/740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/comments?post=740"}],"version-history":[{"count":0,"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/pages\/740\/revisions"}],"wp:attachment":[{"href":"https:\/\/nmi.cool\/webdev\/wp-json\/wp\/v2\/media?parent=740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}