{"id":276,"date":"2022-01-19T00:10:57","date_gmt":"2022-01-19T00:10:57","guid":{"rendered":"http:\/\/miriamposner.com\/classes\/is270s23\/?page_id=276"},"modified":"2022-01-20T17:34:16","modified_gmt":"2022-01-20T17:34:16","slug":"paint-that-page-with-css","status":"publish","type":"page","link":"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/web-design\/paint-that-page-with-css\/","title":{"rendered":"Paint that page with CSS"},"content":{"rendered":"\n<p><em>If you&#8217;d like, you can <a href=\"https:\/\/share.descript.com\/view\/VnWANUpSr4K\" target=\"_blank\" rel=\"noreferrer noopener\">watch a video<\/a> of me working through these steps.<\/em><\/p>\n\n\n\n<p>You\u2019ve used HTML to build your webpage, but it doesn\u2019t have a lot of style yet. Let\u2019s add some with&nbsp;<strong>CSS<\/strong>.<\/p>\n\n\n\n<p>CSS stands for&nbsp;<strong>cascading style sheet<\/strong>, a somewhat confusing name for a language that you use to format your page so that it looks just the way you want. CSS can get super-complicated, but the basic principles aren\u2019t hard to master.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Link your HTML document to a CSS document<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445645339389.png\" alt=\"media_1445645339389.png\"\/><\/figure>\n\n\n\n<p>You can add CSS styles to your HTML document in a few different ways, but I like to keep all of my CSS rules in a separate document. Open a new text document in Atom and save it in the same folder as your html document, with the name&nbsp;<strong>style.css<\/strong>.<\/p>\n\n\n\n<p>(You can call your stylesheet whatever you want, but&nbsp;<strong>style<\/strong>&nbsp;is customary.)<\/p>\n\n\n\n<p>Now we have to tell the HTML document to look for the CSS document in order to receive information about styles. Luckily, that\u2019s not too hard. Inside the<strong>&lt;head&gt;<\/strong>&nbsp;tags on your html document, type<\/p>\n\n\n\n<p><code>&lt;link rel=\"stylesheet\" href=\"style.css\"&gt;<\/code><\/p>\n\n\n\n<p>Now, after you save your HTML document, you should be linked! (You won\u2019t be able to tell that, though, until you\u2019ve completed the next step.)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How CSS styles work<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445645488785.png\" alt=\"media_1445645488785.png\"\/><\/figure>\n\n\n\n<p>The basic rule is that you specify the HTML tag you\u2019d like your rule to affect and then say what you want to do to the content inside the tag. Then all of the content inside of that tag will be affected.<\/p>\n\n\n\n<p>In the example above, I\u2019ve specified that all of the content inside&nbsp;<strong>&lt;h1&gt;&nbsp;<\/strong>tags should be made blue and transformed into the Helvetica font. Notice that the content inside (for example) the paragraph tags isn\u2019t affected. That\u2019s because the paragraphs are not inside the&nbsp;<strong>h1<\/strong>&nbsp;tags.<\/p>\n\n\n\n<p>As you can see, your rules go inside angle brackets, which look like this&nbsp;<strong>{ }<\/strong>&nbsp;and are separated by semicolons.<\/p>\n\n\n\n<p>After you\u2019ve edited&nbsp;<strong>style.css<\/strong>&nbsp;so that it looks as it does in the above image (or typed out below), save it and refresh your web browser. Your new style should be reflected on the page!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\ncolor:blue;\nfont-family:helvetica;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Make everything different colors!<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445645907625.png\" alt=\"media_1445645907625.png\"\/><\/figure>\n\n\n\n<p>Everybody know that the more color a webpage has on it, the better it is. Add some color by styling tags.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>h1 {\ncolor:blue;\nfont-family:helvetica;\n}\n\np {\ncolor:pink;\n}\n\nh3 {\ncolor:blue;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Change background colors<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445646064171.png\" alt=\"media_1445646064171.png\"\/><\/figure>\n\n\n\n<p>To CSS, every element on your webpage forms a box. You can change the background color of this box by using the background-color style rule.<\/p>\n\n\n\n<p>As you can see above, even the body tag forms a box that contains everything on the page. Who wants a boring background color? Make that page stylish!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">body {<br>background-color:yellow;<br>}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add some borders<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445646352089.png\" alt=\"media_1445646352089.png\"\/><\/figure>\n\n\n\n<p>Since everything on your page is a box, you can add borders around everything. Notice that I\u2019ve also put a border around my dog photo by using the&nbsp;<strong>img<\/strong>&nbsp;tag.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">img {<br>border: 5px solid fuchsia;<br>}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Do some resizing<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445646487538.png\" alt=\"media_1445646487538.png\"\/><\/figure>\n\n\n\n<p>You can change pretty much anything with CSS, including sizes. I want my dog picture to be smaller, so I\u2019m going to add some style rules for the&nbsp;<strong>img<\/strong>&nbsp;tag.<\/p>\n\n\n\n<p>I\u2019ve chosen to use percentages, but you can also use pixels (50px).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">img {<br>border: 5px solid fuchsia;<br>width:50%;<br>height:50%;<br>}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Move things around<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445882521016.png\" alt=\"media_1445882521016.png\"\/><\/figure>\n\n\n\n<p>You can use CSS to move things around on the page. The most direct way to do this is to change the&nbsp;<strong>margins<\/strong>&nbsp;(the space between the element and whatever\u2019s next to it). I\u2019m going to scooch my dog picture over to the right by increasing its left margin. (See what happens when you try&nbsp;<strong>margin-right<\/strong>,&nbsp;<strong>margin-top<\/strong>, and&nbsp;<strong>margin-bottom<\/strong>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>img {\nborder: 5px solid fuchsia;\nwidth:50%;\nheight:50%;\nmargin-left:100px;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add some padding<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445882630200.png\" alt=\"media_1445882630200.png\"\/><\/figure>\n\n\n\n<p>Margin is the space between an element and its neighboring elements.&nbsp;<strong>Padding&nbsp;<\/strong>is the space between a piece of content and its borders. Let\u2019s give the header some more padding to make it stand out. Looking good!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">h1 {<br>color:blue;<br>font-family:helvetica;<br>background-color:pink;<br>border:5px solid red;<br>padding:50px;<br> }<\/pre>\n\n\n\n<p>If you\u2019d like, you can&nbsp;<a href=\"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/web-design\/css-part-two-divs-classes-and-ids\/\" data-type=\"page\" data-id=\"278\">learn more CSS<\/a>, or, if we\u2019re short on time, you can skip to&nbsp;<a href=\"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/web-design\/publish-your-website-with-github-pages\/\" data-type=\"page\" data-id=\"280\">publishing your site to the web<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;d like, you can watch a video of me working through these steps. You\u2019ve used HTML to build your webpage, but it doesn\u2019t have a lot of style yet.&hellip; <a class=\"more-link\" href=\"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/web-design\/paint-that-page-with-css\/\">Continue reading <span class=\"screen-reader-text\">Paint that page with CSS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":272,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","footnotes":""},"class_list":["post-276","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":0,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/276\/revisions"}],"up":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/272"}],"wp:attachment":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/media?parent=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}