Web Development 04 - Styling Pt 2

Dec 22, 2015 07:51 PM
Dec 22, 2015 10:11 PM
635863790963493833.jpg

Welcome back Null-Byters! You finally have the pre-basics of CSS and we can begin with styling our web page. If you did not read our last adventure, I suggest you go and read it.

Heads Up: Attributes in HTML are the little additions to a tag. They go inside of the opening tag. Examples are: style, width, and height

Step 1: How to Compose a CSS 'Rule'

A rule in CSS are the styles applied to an element. To create a rule there is a basic syntax. Later in this series we will be going over more advanced CSS such as media queries. The basic syntax is as such:

635863790963493833.jpg

The selector is just the element we want to select. Let's go back to our first webpage. Say we want to do something with the h1 header. There are multiple ways to do it.

635863792621575431.jpg

Here, we are selecting it based on what it is. This is so vague that it will choose every h1 header we have. As long as it doesn't get overwritten. Here, we are creating a class attribute in our HTML element. We then can use the class selector to select the element in our web page. Here is an example.

635863793695498963.jpg
635863794071817878.jpg
635863793695498963.jpg
635863794071817878.jpg

Here, we added the class attribute to our h1 header. Now, in CSS using the '.' and the class we set, we can add styles through that. Another way to add styles is with the id. It is similar to the class notation but carries more weight.

635863795300397467.jpg
635863795412437405.jpg
635863795300397467.jpg
635863795412437405.jpg

There is one more way we can add styling to an element. This carries the most weight and over writes everything. Using the style attribute.

635863796313969188.jpg

Changing Fonts

Now I think the default font is pretty bland. I want to add a font from Google Fonts! Because I am doing this on a linux machine, I think I will use Ubuntu.

635863801046457776.jpg

Now click "Add to Collection". And you should see this popup. Hit use on the little bar in the top right.

635863801737167146.jpg

You can choose the types you want. I will just use the regular one. Scroll down and it will give you a link tag. Copy and paste that into your head section on your web page.

635863903025430746.jpg
635863803705036214.jpg
635863903025430746.jpg
635863803705036214.jpg

You may be asking yourself, "How do I use this?". First, create a folder named css and add a file named master.css. Now, add a class attribute and name it something in the h1 header.

635863805449835162.jpg

Now go into that master.css and setup a rule that will style through a class selector.

635863806117081646.jpg

To add a new font, we need to use something called the font family. In css you just put font-family: 'Name of font', 'Backup font if the other fails';

635863807417652266.jpg

Now you go over to your webpage and refresh to see your new font. Then you get disappointed because it didn't work. First, you have to link the css file over to your html. You just need to use the link tag. Now put this in your head tag:

  • rel means the relationship. In this case, the file is a stylesheet so we put that down
  • href mean hyper reference. This is the path to the file.
  • media is something you can ignore for now
  • title can also be ignored for now
  • charset is just the characters used. Just set it to this to be sure there are no errors.
635863810415238942.jpg

Now your new font works!

635863810794818882.jpg

Sorry this was longer than my other ones. Next couple tutorials will be on CSS and HTML then we will move onto JavaScript and jQuery.

-Smit

Comments

No Comments Exist

Be the first, drop a comment!