Search This Blog

Friday, November 17, 2017

CSS Tutorial Part 1: How To Use Or Apply CSS

Hello guys, as promised, we're going to learn how to style our website using Cascading Style Sheet or CSS in this lesson. This lesson is for those who had been following my tutorial on HTML programming or those who already know the basic of HTML. If you're unsure of what I'm talking about, then you should probably go to HTML tutorial first. You can do so by clicking here.

CSS consist of 3 important parts which are selector, properties and value. Basically, selector is the target of our styling. Most off the time, we will be using HTML tags such as <p>, <a>, <h1> etc as our selector. Properties are the property we want to style such as font-size, color etc while value refer to the value of the Property (i.e. red, blue, 12px, etc)

There are 3 ways to apply CSS to our website which are the rarely used, inline, the normally used, internal and the most commonly used, external. Lets start with the inline method.

<p style="color:red">your text</p>

The inline method is where we put the style directly into a HTML tag. In this case we don't need to specify a selector as the style is in the styling target itself. The properties here is color which refer to font-color while the value here is green. When using CSS, always remember the format, properties followed by a colon ':' followed by value. Also notice that the style attribute is placed to tell the browser that we're using CSS.

The inline method is pretty useful in some case but we would normally avoid it as we want to keep out HTML file clean. The next method, internal is slightly better is than inline as it didn't mess our HTML file that much. To do this, we simply use style as tag like we would with HTML tag. However, as styling is not in the target itself, we need to specify the selector.

<style>
p{
   color:red;
   /* other style for our paragraph */
}

h1{
   /* some other style we want for our heading */
}
</style>

we can put as much style as we want and for anything we want this way, just remember the format. Basically anything within the curly braces are the style for the selector before the curly braces. Also make sure to put a semicolon ';' at the end of each style like this color:green;. The <style> can be placed anywhere in the HTML file but we normally put it in the <head> tag.

The last also the most popular method of using CSS is to create and external file for CSS and link it to our HTML file.

Your CSS file should looks something like this.

p{
   color:red;
   /* other style for our paragraph */
}

h1{
   /* some other style we want for our heading */
}

It is same as when we're using the internal method but without the <style> tag. We can put as many style as we want in here and save it as css file (i.e. main.css).

To link our CSS file to HTML file, just open the HTML file and write the following code in the <head> tag.

<head>
   <link rel="stylesheet" href="main.css" />
</head>

link tag is used to tell the browser to look through the content of an external file. the attribute rel="stylesheet" tells the browser that the file type is stylesheet which also means a CSS. The href="main.css" attribute specify the path to the file. If the file is in the same directory as the HTML file we're linking with, we just needs to put in the file name instead of a full path. Lastly, notice that there is a forward slash '/' at the end of our link tag. Basically it means that our tag are self-closing. Self-closing tag are tags that don't comes in pair of opening tag and closing tag like most of HTML tag.

Btw, the /*  */ is used to write a comment, your browser will ignore anything written is in. Though it might sound pretty useless right now, it is actually really useful when you're working with a huge website as you can label what each parts of the code do so that you won't need to read through the whole code when there is a bug. Just make sure you don't overuse it.

Now that we know how to apply style to our our web page, we'll start styling our web page in our next tutorial. See ya.

Wednesday, November 15, 2017

HTML Tutorial Part 3 : Creating A List In HTML


Hello again everyone, this is our third HTML tutorial for beginner web developer also our last (at least for the beginner parts). In the next post, we will be learning the basic of CSS instead.

In this lesson we will learn about list in HTML.There are 3 type of list that we can use in HTML but only 2 are relevant for our beginner tutorial. The 2 type of list are ordered list and unordered list which are basically a numbered list and a bullet list respectively. The tag <ol> and <ul> are used to create the list and as always, a closing tag is required to use the tag. These 2 tag are used in pair with <li> tag which is used to specify the list item. Modify your HTML file as below,

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <ul>
      <li>Home</li>
      <li>About</li>
      <li>Contact</li>
    </ul>
    <h1>I'm a beginner web developer</h1>
    <h2>This is my first website</h2>
    <p>I'm sooo excited</p>
    <p>I'm going to keeps on following the 
      <a href="https://amirruddin-razak.blogspot.com/">tutorial</a> 
         and make my own super cool website
    </p>
    <ol>
      <p>Follow the tutorial here</p>
      <li>On Blogger</li>
      <li>On Google+</li>
    </ol>
  </body>
</html>


What the <ul> tag do is simply tells the browser to create a bullet list for every single list item, <li> tag enclosed by it. The <ol> tag did pretty much the same thing but with a numbered list instead of a bullet list. Any texts or items enclosed by a <li> tag will be listed in your browser. Notice how I put a <p> tag in between the <ol> tag. What this gonna do is that the browser will display "Follow the tutorial here" normally without being numbered. This is because the text is not enclosed in <li> tag. Therefore the browser won't treat it as a list. But because the <p> tag is in between the <ol> tag, the displayed paragraph are indented as if it is a part of the list. Try to save the HTML file and you should see something like this,

Displaying results of using Ordered list and Unordered list HTML tag in browser
That's about everything on creating a list in HTML. Before we end this lessons, let's touch up our website a bit by making our list into a link by using the anchor tag we learnt before. Modify your code,


<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>
    <h1>I'm a beginner web developer</h1>
    <h2>This is my first website</h2>
    <p>I'm sooo excited</p>
    <p>I'm going to keeps on following the 
    <a href="https://amirruddin-razak.blogspot.com/">tutorial</a>
       and make my own super cool website
    </p>
    <ol>
      <p>Follow the tutorial here</p>
      <li>
        <a href="https://amirruddin-razak.blogspot.com">On Blogger</a>
      </li>
      <li>
        <a href="https://plus.google.com/105989137850183491401">On Google+</a>
      </li>
    </ol>
  </body>
</html>


Now save your file and all the link should be working now except for About and Contact since you don't have an About page and Contact page yet. But you should be able to create the 2 pages easily by using what we've learnt before. Just make sure the name of your HTML file match the name you put in your link else the link won't works. Also notice that I put a '#' instead of a url or a file name in the link to home. Basically the '#' is used to do nothing, you will stay on the same page even if you click the link. Since you're already on the home page anyway, its only natural that you won't be sent anywhere if you click the link to home.

your website now looks like this,

List item displayed as link

That's all for this lesson, in the next lesson we will be learning how to use CSS to make our website looks like a real and beautiful website.

If you have a question about HTML, feel free to ask me in the comment below. see ya