{"id":193,"date":"2017-09-27T03:55:57","date_gmt":"2017-09-27T03:55:57","guid":{"rendered":"http:\/\/miriamposner.com\/classes\/dh101f17\/?page_id=193"},"modified":"2017-09-27T03:55:57","modified_gmt":"2017-09-27T03:55:57","slug":"css-part-2-divs-classes-and-ids","status":"publish","type":"page","link":"http:\/\/miriamposner.com\/classes\/dh101f17\/tutorials-guides\/web-publishing\/html-css\/css-part-2-divs-classes-and-ids\/","title":{"rendered":"CSS part 2: Divs, classes, and IDs"},"content":{"rendered":"<div class=\"LessonSummary\">\n<p>We&#8217;ve learned how to use CSS styles to format content on our webpage, and the code we&#8217;ve used is great for when you want to format\u00a0<i>all<\/i>\u00a0paragraphs, headers, or images. But what happens if you want to, say, distinguish among paragraphs on your page? Or break your page up into sections? That&#8217;s where divs, classes, and IDs come in handy.<\/p>\n<\/div>\n<div class=\"LessonStep top\">\n<h3 class=\"StepTitle\">Use IDs to distinguish among elements<\/h3>\n<div class=\"StepImage\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445883439712.png\" alt=\"media_1445883439712.png\" width=\"540\" height=\"249\" \/><\/div>\n<div class=\"StepInstructions\">\n<p>I like the way my paragraphs look, but I want to create a special style for paragraphs I want to highlight. I can do this by adding an\u00a0<strong>ID tag<\/strong>\u00a0to those paragraphs. First, after the tag for the paragraph I want to highlight, I type\u00a0<code>id=\"highlight\"<\/code>. Then I create a style for that ID tag on my stylesheet by typing\u00a0<code>#highlight<\/code>\u00a0and entering styling information, just as I would for any element. The hashtag in front of &#8220;highlight&#8221; tells the browser that it refers to an ID tag.<\/p>\n<p>Notice that when I refresh the page, the first paragraph is treated as before, since I haven&#8217;t labeled it &#8220;highlight.&#8221; The second paragraph, because of its ID tag, looks different.<\/p>\n<\/div>\n<\/div>\n<div class=\"LessonStep top\">\n<h3 class=\"StepTitle\">Divide your page into sections with divs<\/h3>\n<div class=\"StepImage\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445883990276.png\" alt=\"media_1445883990276.png\" width=\"540\" height=\"243\" \/><\/div>\n<div class=\"StepInstructions\">\n<p>The last step works well when you want to style individual elements. But what if you want to create sections on your page?\u00a0<strong>Div<\/strong>\u00a0tags come in handy for that. A\u00a0<strong>div\u00a0<\/strong>creates a new, invisible box around whatever elements it encloses, allowing you to style these elements as one block.<\/p>\n<p>To label divs, use a\u00a0<strong>class<\/strong>, which is just a way of naming an element. It&#8217;s very similar to an ID tag, except classes refer to elements that appear multiple times per page, while ID tags can be used only once. (In practice, this distinction is pretty blurry, but that&#8217;s the idea.)<\/p>\n<p>Create a new\u00a0<strong>div<\/strong>\u00a0around part of your page and give it a\u00a0<strong>class<\/strong>. Then style it on your stylesheet just as you did with the ID tag. The only difference is that instead of placing the hashtag in front of the div&#8217;s class, you&#8217;ll place a period in front of it, to indicate that it&#8217;s a class.<\/p>\n<\/div>\n<\/div>\n<div class=\"LessonStep top\">\n<h3 class=\"StepTitle\">Get even crazier with floats<\/h3>\n<div class=\"StepImage\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445884244795.png\" alt=\"media_1445884244795.png\" width=\"540\" height=\"295\" \/><\/div>\n<div class=\"StepInstructions\">\n<p><strong>Floats<\/strong>\u00a0can be kind of confusing, but the idea is that if you apply a\u00a0<strong>float<\/strong>\u00a0to an element, it&#8217;ll attempt to move in that direction, pushing all of its neighbors to the side. Try it by floating one of your divs left or right.<\/p>\n<\/div>\n<\/div>\n<div class=\"LessonStep top\">\n<h3 class=\"StepTitle\">Taking precedence<\/h3>\n<div class=\"StepImage\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445884580146.png\" alt=\"media_1445884580146.png\" width=\"540\" height=\"256\" \/><\/div>\n<div class=\"StepInstructions\">\n<p>We&#8217;re almost done, but there&#8217;s one last thing it&#8217;s important for you to know. What happens if you have contradictory styling information on your stylesheet? For example, what if you style your\u00a0<strong>h1<\/strong>s one way at the top and another way toward the bottom? Try it.<\/p>\n<p>The later style takes precedence.<\/p>\n<\/div>\n<\/div>\n<div class=\"LessonStep top\">\n<h3 class=\"StepTitle\">Your browser can help you out<\/h3>\n<div class=\"StepImage\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/miriamposner.com\/dh101f15\/wp-content\/uploads\/2015\/10\/media_1445884827025.png\" alt=\"media_1445884827025.png\" width=\"540\" height=\"483\" \/><\/div>\n<div class=\"StepInstructions\">\n<p>Right-click (or hold down\u00a0<strong>control<\/strong>\u00a0and click)\u00a0somewhere on your webpage, and select\u00a0<strong>Inspect Element<\/strong>. You&#8217;ll see something like the image above, which gives you information about how that element is styled. (In this case, I&#8217;ve clicked on my dog image.) You can actually style elements directly on the page by clicking on the style information. It won&#8217;t stick, though; the page will &#8220;reset&#8221; as soon as you refresh it.<\/p>\n<p>Hey, you&#8217;re done! Nice work. If you have extra time, take a look at\u00a0<a href=\"http:\/\/www.htmldog.com\/guides\/css\/intermediate\/\">some of the more advanced ways<\/a>\u00a0you can use CSS (start with &#8220;Grouping and Nesting&#8221;).<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve learned how to use CSS styles to format content on our webpage, and the code we&#8217;ve used is great<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":43,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","footnotes":""},"class_list":["post-193","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/comments?post=193"}],"version-history":[{"count":0,"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/193\/revisions"}],"up":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/pages\/43"}],"wp:attachment":[{"href":"http:\/\/miriamposner.com\/classes\/dh101f17\/wp-json\/wp\/v2\/media?parent=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}