Skip to main content

HTML BASICS : CLASS 109 part II

Hello and welcome back.
In part I, we learned the theory behind the html div tag and the form elements.
We have quiet some coding to do in this part, so let's get to it.

Create a new html file and name it sections.html. Open the file in your text editor (e.g. Sublime Text), type in the following code and save it. You can go ahead and view it on your browser afterwards, though it won't look quiet good just yet.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="sections.css">
</head>
<body>

    <div id="header">
        <h2>My Site</h2>
    </div>


    <div id="content">

        <div id="main">
            <p>Welcome to my website.<br>Please give me your feedback using the form on the side bar</p>
        </div>

        <div id="rightSideBar">
            <form>
                <input type="text" name="username_input" placeholder="Enter your username">
                <textarea placeholder="enter your feedback"></textarea>
                <button>SUBMIT FEEDBACK</button>
            </form>
        </div>

    </div>

    <div id="footer">
        <h4>Contact Us</h4>
        <ul>
            <li>+861 000 000 000</li>
            <li>myemail@mysite.com</li>
        </ul>
    </div>


</body>
</html>


Let's examine this code.
Right after the opening tag, we create a division (or section) using the div tags <div> and </div>.
We give this division the id 'header'.
Inside this header division, we add only one element, the heading 'my site'.

Then we create another division. This we id as content.
The content division itself is divided into 2 sections. The main div and the rightSideBar div.

Inside the main div, we have a single paragraph that welcomes our users.
The <br> tag is used to create a new line. To see the difference. go ahead and remove the <br>, save and open the file in your browser. Then go back, add the <br>, save and again view the file in your browser.

Inside the right side bar, we have a form. This shall be used to get information from the user/visitor of our site.
The form opens with a <form> tag and is closed by the </form> tag.
  • The first element inside the form is the input.
  • The input we specify is of type 'text'. This means the user will be able to type in visible letters, numbers and characters. 
  • This input also has a placeholder. A placeholder is used in form elements to guide the user on what to write. When the user starts typing inside the input (try this), the placeholder disappears.
  • Next a textarea is specified, also with a placeholder, explaining that the user should type their feedback here. 
  • Last in the form, we have a button. This shall be clicked when the user is done filling the information.
Finally, our body ends with another div we id as 'footer'.
The footer has some contact information displayed using a small heading and an unordered list.

Great!
The site does not look that good in a browser. Let's fix that quickly.
See the linked sectons.css file in the html head section below the title?
Go ahead and create a new file, name it sections.css and save it in the same folder location where you have saved this sections.html file.
Open it in Sublime Text and type in the following CSS code.

#header{
    background-color: grey;
    padding-top: 5px;
    padding-bottom: 5px;
    padding-left: 15px;
}

h2{
    margin: 0px;
    color: white;
}

#content{
    padding-left: 15px;
}

p{
    display: inline-block;
    float: left;
    margin-right: 50px;
}

form{
    display: inline-block;
    border-left: 2px solid grey;
    padding: 12px;
}

input{
    display: block;
    margin-bottom: 24px;
    width: 200px;
    padding: 8px;
}

textarea{
    display: block;
    margin-bottom: 24px;
    width: 214px;
    text-align: left;
}

button{
    width: 214px;
    padding: 8px;
}

#footer{
    background-color: grey;
    padding: 15px;
    color: white;
}

ul{
    list-style: none;
}



Save it. Open sections.htmk in your browser.
It should look similar (if not exact) to the following image:

 

That's better.
It's okay that you are not yet familiar with some of the css code you have just typed. We shall discuss those next.
For now, I hope you understood the concept of divisions and forms.
Oh, and nothing happens when you fill in the form and click the button. Just know that working on data provided through forms, is the task of back-end developers. You are a front end developer (Your concern is on what the user sees!).  
On that note, happy coding.
Try changing the <input>  element type from text to password and see (in your browser) what happens :)

Comments

Popular posts from this blog

CSS BASICS : CLASS 107

Hello and welcome back to this series of tutorials for beginners in web development. So far we have a simple html page and a css file linked to it. We begin this tutorial by creating new html and css files, in the same folder as where my_site.html is located. We shall call them index.html and index.css respectively. Done? Great! Link the two files together , by opening up index.html in your text editor (e.g. Sublime Text) and typing the following code below the closing title tag  </title>  and before the closing head tag </head> :               <link rel="stylesheet" type="text/css" href="index.css"> Inside the body of your html (i.e after <body> and before </body>),  type the following html code :              <p> This is a paragraph </p>              <p> This is a second paragraph </p>              <p> This is a third paragraph </p> Save your index.html file. Then open the

HTML BASICS : TEST YOURSELF

Hello and welcome back. Test your knowledge of the concepts we have learnt so far, by creating a website that looks as seen in images the below, before continuing with the next part.   Click on each image to zoom in (or better yet, save them in your pc). You can get the image used by clicking here . As always, if you have any questions / comments, leave them in the comment section below.

CSS BASICS : CLASS 109 part III

Hello and welcome back to this tutorial series  for beginners in web development with HTML & CSS. We have been discussing form and div elements in the previous sections of this class (see class 109 part I and II ). You should have 2 files, one sections.html file and another sections.css file linked to it. Next, we will discuss the css code we used in the sections.css, particularly 2 new attributes ' display ' and ' float ' .  This is the CSS code that we used to style our sections.html page. #header{     background-color: grey;     padding-top: 5px;     padding-bottom: 5px;     padding-left: 15px; } h2{     margin: 0px;     color: white; } #content{     padding-left: 15px; } p{     display: inline-block;     float: left;     margin-right: 50px; } form{     display: inline-block;     border-left: 2px solid grey;     padding: 12px; } input{     display: block;     margin-bottom: 24px;     width: 200px;     padding: 8px; } textarea{     display: block;     margi