Introduction To HTML+CSS+Javascript& Debugging PDF
Introduction To HTML+CSS+Javascript& Debugging PDF
● HTML
● CSS
● Javascript
HTML
HTML means Hyper Text Markup Language.
It is a series of nested tags that contain all the website information </div>
</body>
(like texts, images and videos). Here is an example of tags: </html>
<h1>This is a title</h1>
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> <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>
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 {
display: flex;
}
Grid system HTML
<div class="grid-container">
Because most sites are structured in a grid, I
<div class="grid-item1">1</div>
recommend to use the CSS Grid system. <div class="grid-item2">2</div>
</div>
We just assign how many rows/columns a div
should use from the main grid and it will arrange CSS
automatically.
.grid-container {
Check this tutorial to create the site structure display: grid;
grid-template-rows: 100px 100px;
easily grid-template-columns: 100px 100px 100px;
grid-gap: 5px;
}
.grid-item1 {
background: blue;
border: black 5px solid;
grid-column-start: 1;
grid-column-end: 5;
grid-row-start: 1;
grid-row-end: 3;
}
Fullscreen divs CSS
html, body {
width: 100%;
Sometimes we want to have a div that covers height: 100%;
the whole screen (to make a webapp), }
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.
}// ES6
❖ Callback Functions
❖ Promises
❖ Async/Await
Javascript: Asynchronous
● CallBacks
● A callback is a function passed as an argument to another function
● This technique allows a function to call another function
● A callback function can run after another function has finished.
● Code Snippet:
function fetchData(callback) {
console.log("Fetching data...");
setTimeout(() => {
callback("Data fetched successfully!");
}, 2 0 0 0 ); /. Simulate a 2 -second delay
}
fetchData((message) => {
console.log (message);
});
Javascript: Asynchronous
● Promises
● A Promise is an object that represents the eventual completion (or
failure) of an asynchronous operation. It can be in one of three
states:
• Pending: The initial state, neither fulfilled nor rejected.
• Fulfilled: The operation completed successfully, and the promise
returns a result.
• Rejected: The operation failed, and the promise returns an error.
Javascript: Promise
● Code Snippet
And the API keeps growing with every new update of the standard.
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.
Event Object: When an event occurs, the browser passes an event object to the event handler. This
object contains information about the event, such as the type of event, the target element, and any
additional data like mouse position or the key press.
Javascript: Events Types
● Mouse Events:
● Keyboard Events
● Forms Events
● Windows Events
Javascript: Events Types
● Mouse Events:
● These events are triggered by mouse actions.
● click: Fired when an element is clicked
● dblclick: Fired when an element is double-clicked.
● mouseover: Triggered when the mouse pointer moves over an element.
● Mouseout: Triggered when the mouse pointer moves out of an element.
Javascript: Events Types
Keyboard Events
● These events are triggered by mouse actions.
● keydown: Fired when a key is pressed down
● keyup: Fired when a key is released.
● keypress: Triggered when a key is pressed (deprecated in some cases in favor of keydown and keyup)
Javascript: Events Types
Forms Events
● submit: Fired when a form is submitted
● change: Fired when the value of an input element (like a text field or select box) changes.
● focus: Triggered when an element (such as an input field) gains focus.
● blur: Fired when an element loses focus.
Javascript: Events Types
Windows Events:
● load: Fired when the entire page (including its assets like images) has been loaded
● resize: Triggered when the browser window is resized.
● scroll: Fired when the user scrolls the page.
Example of a website
HTML in index.html
Javascript in code.js
<link href="style.css" rel="stylesheet"/>
<h1>Welcome</h1> //fetch the button from the DOM
<p> var button =
<button>Click me</button> document.querySelector("button");
</p>
<script src="code.js"/> //attach and event when the user clicks it
button.addEventListener("click", myfunction);
Chrome.
○ Messages area
■ message
■ input
Exercise
● Create the layout and code for Traverse
● Structured like:
● Main container
○ Messages area
■ message
■ input
Console.log(“Thank
You”);
Alert(“any
queries”);