I am in an intro to coding bootcamp where I am learning HTML, CSS and JavaScript. So far I have learned HTML and CSS; CSS is my favorite part thus far. CSS to me feels like the flavor of the languages. It customizes and brings the webpage to life; it makes it look pretty. I recently learned how to use CSS ID's. ID's are used to customize specific tags. If you have multiple paragraph tags for example and you want to use CSS to target them, it will affect them all. So you need to use ID's in order to target whichever specific paragraph tags you would like to select. For example, you only want to make 2 out of 4 paragraphs green. To do this you would need to modify the HTML first to add the ID attributes to the tags you specifically want to select. The attributes should be unique and nothing on the page should have the same ID.Â
You would place the attribute in the opening tag only. For example, if we wanted to modify a paragraph tag it would look like:
ID attributes cannot have spaces in between words, so either you use a hyphen or keep the words together. I personally like to use a hyphen.Â
In CSS, you would create a rule and for IDs you need to use a hashtag (#). So:
You always have to use a hashtag and curly brackets to enclose your commands. So for this CSS rule, I want my specific paragraph to be green. You also have to ensure you use a colon after the property and a semi-colon after the value. Please note that IDs are case sensitive and need to be lower case only. Also, when you are typing in CSS, the ID does not need to be in the brackets.
Latest comments (0)