CSS
Looking for the most used/common attributes and what they are used for?
There are 3 ways to select an element
The element name is selected by simply using it's name in the css for example the following html code:
In the CSS you would begin to style them like the code below:
So you can see you just use the element name and then the curly brackets to start styling. We will go over what to put in those brackets shortly
When you have div elements or paragraphs you might not want them all to look the same so styling using the element name isn't ideal at this point so you would edit your html like so:
Here we have 2 div tags 1 with a class name and 1 with out and 3 p tags 2 with out a class name and 1 with. If we wanted to style this code we could do the following
So you can see that we gave the elements we called by name some styling which will apply to all elements with that name, but we also use the class name to change or add additional styling attributes to just those elements with those class names. And we call the class name with a . before it's name that was put in "" in the html.
** You can reuse the class names over as many times you want in the html and every element with that class name will have the same styling that you gave it.
This is the least recomended and can only be used once per document. This will also take priority over other styling so use sparingly. Typically id's in html are used for javascript functions or to point to a link that is internal to the same document…like further down the page. However you can use the id for a link and css like so:
Here we see we have 2 links. the 1st link location is #more which points to the id more in the last div. So when that link is clicked the users browser will drop down to that div. But say we also want to make sure that that div also has a uniqe look to it. Well we would do the following:
Here we added the #more to our css and it will take the attributes we tell it and apply them to that p tag that had the id of more.
So now you know how to call the element you want to style. Lets change colors
Both of the following will change the selected elements background color.
For the class of container we used the actual name of blue but for the element nav we used it's hex code
So now we can change the background color lets change the font color
Again like the background color you can use the name of the color or the hex code.