Introduction to HTML CSS Javascript
Introduction to HTML CSS Javascript
technologies
HTML + CSS + Javascript
Hardware
Framework and OS
What you expect from your framework to Your Code
access the OS is usually three things:
- To store data
- To get system info like date, screen
resolution, etc.
● HTML
● CSS
● Javascript
Browsers as a renderer
Browser's act as a renderer that takes documents
and construct a visual representation of them.
You can try, drop any .txt file into your browser to
visualize it.
My name is <b>Javi</b>
HTML
HTML means Hyper Text Markup Language.
<html>
The HTML allow us to define the structure of a document or a <head>
website. </head>
<body>
<div>
HTML is NOT a programming language, it’s a markup language,
<p>Hi</p>
which means its purpose is to give structure to the content of the </div>
website, not to define an algorithm. </body>
</html>
It is a series of nested tags (it is a subset of XML) that contain all
the website information (like texts, images and videos). Here is an
example of tags:
<title>This is a title</title>
The HTML defines the page structure. A website can have several
HTMLs to different pages.
HTML: basic rules
Some rules about HTML:
● It uses XML syntax (tags with attributes, can contain other tags).
<tag_name attribute="value"> content </tag_name>
● It stores all the information that must be shown to the user.
● There are different HTML elements for different types of information and behaviour.
● The information is stored in a tree-like structure (nodes that contain nodes inside) called
DOM (Document Object Model).
● It gives the document some semantic structure (pe. this is a title, this is a section, this is
a form) which is helpful for computers to understand websites content.
● It must not contain information related to how it should be displayed (that information
belongs to the CSS), so no color information, font size, position, etc.
HTML: syntax example
<div id="main">
<!-- this is a comment -->
This is text without a tag.
<button class="mini">press me</button>
<img src="me.png" />
</div>
HTML: syntax example
Tag name
attributes
</div>
DOM is a tree
<div> <div>
Title <h1>Title</h1>
<p>Here is content.</p>
Here is some content <p>Here is more content</p>
Here is more content </div>
</div>
D O THIS
T
DON
HTML good use
It is good to have all the information properly wrapped in tags that give it some semantics.
We also can extend the code semantics by adding extra attributes to the tags:
● HTML
● CSS
● Javascript
CSS
CSS allows us to specify how to present
(render) the document info stored in the
HTML.
This will change all the tags in my web ( ‘*‘ means all) to look blue with font Tahoma with
14px, and leaving a margin of 10px around.
CSS fields
Here is a list of the most common CSS fields and an example:
● color: #FF0000; red; rgba(255,00,100,1.0); //different ways to specify colors
● background-color: red;
● background-image: url('file.png');
● font: 18px 'Tahoma';
● border: 2px solid black;
● border-top: 2px solid red;
● border-radius: 2px; //to remove corners and make them more round
● margin: 10px; //distance from the border to the outer elements
● padding: 2px; //distance from the border to the inner elements
● width: 100%; 300px; 1.3em; //many different ways to specify distances
● height: 200px;
● text-align: center;
● box-shadow: 3px 3px 5px black;
● cursor: pointer;
● display: inline-block;
● overflow: hidden;
CSS how to add it
There are four ways to add CSS rules to your website:
div {
background-color: red;
}
This CSS rule means that every tag DIV found in our website should have a red background
color. Remember that DIVs are used mostly to represent areas of our website.
We could also change the whole website background by affecting the tag body:
body {
background-color: red;
}
CSS selectors
What if we want to change one specific tag (not all the tags of the same type).
We can specify more precise selectors besides the name of the tag. For instance, by class
or id. To specify a tag with a given class name, we use the dot:
p.intro {
color: red;
}
This will affect only the tags p with class name intro:
<p class="intro">
CSS Selectors
There are several selectors we can use to narrow our rules to very specific tags of our website.
This will affect to the p tags of class intro that are inside the tag div of id main
<div id="main">
<p class="intro">....</p> ← Affects this one
</div>
div#main.intro:hover { ... }
will apply the CSS to the any tag div with id main and class intro if the mouse is over.
And you do not need to specify a tag, you can use the class or id selectors without tag, this
means it will affect to any node of id main
#main { ... }
CSS Selectors
If you want to select only elements that are direct child of one element (not that have an
ancestor with that rule), use the > character:
Finally, if you want to use the same CSS actions to several selectors, you can use the
comma , character:
.box {
Check the tutorial for more info. display: flex;
}
HTML
Grid system <div class="grid-container">
<div class="grid-item1">1</div>
Because most sites are structured in a grid, I <div class="grid-item2">2</div>
recommend to use the CSS Grid system. </div>
.grid-item1 {
background: blue;
border: black 5px solid;
grid-column-start: 1;
grid-column-end: 5;
grid-row-start: 1;
grid-row-end: 3;
}
CSS
Fullscreen divs html, body {
width: 100%;
height: 100%;
Sometimes we want to have a div that covers }
the whole screen (to make a webapp),
div {
instead of a scrolling website (more like margin: 0;
regular documents). padding: 0;
}
Understanding the Box Model: a good explanation of how to position the information on your
document.
● HTML
● CSS
● Javascript
Interactivity
Once the web was already being used
they realize people wanted to interact
with the websites in a more meaningful
way.
And the API keeps growing with every new update of the standard.
● Crawling the HTML tree (starting from the body, and traversing its children)
will return an array with all <p class="intro"> nodes in the web.
You can change an element CSS directly by accessing its property style.
<input type="text"/>
my_input_element.value = ""; //this will clear the text inside the input
Example of a website
HTML in index.html Javascript in code.js
<link href="style.css" rel="stylesheet"/> //fetch the button from the DOM
<h1>Welcome</h1> var button = document.querySelector("button");
<p>
<button>Click me</button> //attach and event when the user clicks it
</p> button.addEventListener("click", myfunction);
<script src="code.js"/>
//create the function that will be called when the
button is pressed
CSS in style.css
function myfunction()
{
h1 { color: #333; } //this shows a popup window
button { alert("button clicked!");
border: 2px solid #AAA; }
background-color: #555;
}
Execution flow
It is important to have a clear <script>
understanding of the execution flow of var main = document.querySelector("#main");
your code. //main here is null, as the element does
//exist yet
Scripts are executed when the html is </script>
being parsed. <div id="main"></div>
<script>
Be careful accessing the DOM as the
var main = document.querySelector("#main");
DOM won’t contain all until all the HTML
//main now is the right element
is parsed.
</script>
It is good practice to start your code with
an init function called at the end of your
HTML.
jQuery
jQuery is a library that makes working with the DOM much easier, using an unified
syntax and taking advantage of selectors:
Structured like:
● Main container
○ Messages area
■ message
○ Typing area area
■ input
Further info
API References: DevDocs.io
To learn Javascript.
http://codeacademy.com
To learn jQuery:
http://docs.jquery.com/Tutorials