Css Web Terms
Css Web Terms
design studio
When writing code, always make sure to use double tick marks " " rather than quotetation marks .
Visual Tech
design studio
CSS Rule targeting above HTML code p{ color: white; background-color: pink; }
Colors in CSS You can identify some colors in CSS using english but for more detailed control over your color values use hexadecimal values like #DCD78E.
Visual Tech
design studio
Getting Fancy with Selectors Lets say that we wanted to code the CSS for an error state for a contact form that wasnt filled out correctly. We might write the HTML like this.
Opps, you need to give us your email Address to sign up for our newsletter.
Opps, you need to give us your email Address to sign up for our email newsletter. </p> </div> </div> Hooking into CSS with class and id Attributes What we have targeted in our CSS example was every paragraph <p> tag. This is great for broad sweeping declarations, but youll find yourself wanting to target specific pieces of your web page. We can use class and id attributes from HTML as Hooks that let us write CSS to control our HTML in a much more specific way. #form-message{ padding-top: 10px; border-top: 2px solid black; } div.error{ background-color: red; padding-top: 10px; } div.error p{ color: white; font weight: bold; } You can mix up these combinations any way you want. you can connect any tag (<div>, <p>, <span>, etc.) to a class attribute or id attribute. You can choose to be more specific with CSS by writing a selector that includes the class attribute or id attribute in addition to the tag itself. Do this by typing the tag you want to target and then string it together with a class attribute or id attribute. We string these together by connecting the period or hash with the tag, making sure to leave our any space characters. So div.error as a selector in CSS targets only <div class="error"> in HTML. class attributes divide with a (.) period. id attributes divide with a # sign.
Visual Tech
design studio
Targeting Nested HTML Lets say you want to target a <p> tag that is nested inside of <div class="error">, you just have to build on this using what you already know. In CSS, you can target HTML by the way its nested, in addition to the tag name, class attribute and id attribute. The first part of the selector targets the parent tag, and each chunk of text that follows (with a space before it) is nested in the parent tag prior to it. You can get as fancy with this as you want.
<div class="container"> <div class="wrapper"> <div class="teaser"> <div class="thingy"> <a =class"download"> </a> </div> <div> </div> </div>
<div class="container"> <div class="wrapper"> <div class="teaser"> <div class="thingy"> <a href="report.pdf" class="download"> Download Now</a> <div> <div> <div> <div>
You could target the link in this example in several ways. The easiesy would be to target .download, which would find anything with the class of download. That code would look like this: .download{ font-weight: bold; color: red; } But if you want to target only links with a class attribute of download in side of a tag with a class attribute of teaser. Youd target div.teaser .download to do this. div.teaser .download{ font-weight: bold; color: red; } You could go a step further even like this. div.container div.wrapper div.teaser .download{ font-weight: bold; color: red; } Ordinarily this is a little extreme but occationally you may have to make something like this to target something specific that is nested deep, so you dont effect other parts of your website unintentionally.