SOW - Session #3 - CSS & JS
SOW - Session #3 - CSS & JS
Session #3
CSS - JS
04/11/2023
Merhba
Outline
I. CSS - Continuation
II. DOM
III. JS - Intro
01. CSS
CSS
- CSS allows you to create rules that specify how the content of an element should appear.
CSS - Syntax
CSS Syntax
Link
CSS - Selectors
CSS Selectors
Element Selector
<p>Hello World</p>
<section>Hello from the other side </section>
<p>Hello It’s me</p>
p {
text-align: center;
<p>Hello World</p> color: red;
<section>Hello from the other side </section> }
<p>Hello It’s me</p>
CSS Selectors
Id Selector
- Select the HTML element that has the specified Id
- Id is unique within the page
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
.centered {
text-align: center;
<p>Hello World</p> color: red;
<section class=”centered”>Hello from the other side
</section> }
<p class=”centered”>Hello, It’s me</p>
CSS Selectors
Tag.Class Selector
- Select specific HTML elements with a specific class.
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
section.centered {
text-align: center;
<p>Hello World</p> color: red;
<section class=”centered”>Hello from the other side
</section> }
<p class=”centered”>Hello, It’s me</p>
CSS Selectors
Universal Selector
- Select All HTML elements within a page.
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
* {
text-align: center;
<p>Hello World</p> color: red;
<section class=”centered”>Hello from the other side
</section> }
<p class=”centered”>Hello, It’s me</p>
CSS Selectors
Grouping Selector
- Select All HTML elements within a page with specific tag names.
<p>Hello World</p>
<section class=”centered”>Hello from the other side
</section>
<p class=”centered”>Hello, It’s me</p>
<h6>Hello, How are you ?</h6>
p, h6 {
<p>Hello World</p>
text-align: center;
<section class=”centered”>Hello from the other side color: red;
</section> }
<p class=”centered”>Hello, It’s me</p>
<h6>Hello, How are you ?</h6>
Previous Selectors are
named Simple Selectors
CSS Selectors
Descendant
- Select specific HTML elements inside a specified parent
<div>
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section>
<h6>Inside div, but not p tag</h6>
</div>
<p>I’m outside div</p>
div p{
<div> text-align: center;
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section> color: red;
<h6>Inside div, but not p tag</h6> }
</div>
<p>I’m outside div</p>
CSS Selectors
Child Selectors
- Selects all elements that are the children of a specified element.
- First Level Descendant
<div>
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section>
<h6>Inside div, but not p tag</h6>
</div>
<p>I’m outside div</p>
div > p{
<div> text-align: center;
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section> color: red;
<h6>Inside div, but not p tag</h6> }
</div>
<p>I’m outside div</p>
CSS Selectors
Sibling Selectors
- Selects all elements that are the Siblings of a specified element.
<div>
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section>
<h6>Inside div, but not p tag</h6>
</div>
<p>I’m outside div</p>
div ~ p{
<div> text-align: center;
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section> color: red;
<h6>Inside div, but not p tag</h6> }
</div>
<p>I’m outside div</p>
CSS - Where To
CSS Where To
- You can apply CSS in 3 ways :
- Inline style
<div>
<p>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section>
<h6>Inside div, but not p tag</h6>
</div>
<p>I’m outside div</p>
<div>
<p style='text-align:center;color:red'>I’m inside div</p>
<section><p>I’m inside section, inside div.</p></section>
<h6>Inside div, but not p tag</h6>
</div>
<p>I’m outside div</p>
CSS Where To
- Inside <style> </style> Tag
<p>Hello World</p>
<section>Hello from the other side </section>
<p>Hello It’s me</p>
<head>
<style>
p {
text-align: center;
color: red;
}
</style>
</head>
CSS Where To
- Using separate css file
<p>Hello World</p>
<section>Hello from the other side </section>
<p>Hello It’s me</p>
<head>
<link src='./style.css' />
</head>
//style.css
p {
text-align: center;
color: red;
}
02. DOM
DOM
- When an HTML document is loaded into a web browser, it becomes a document object.
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>A heading</h1>
<a href='#'>Link text</a>
</body>
</html>
DOM
- Before making changes on an element programmatically, we need to find it first
- It enables you to create dynamically updating content, control multimedia, animate images.
<html>
<head> <html>
<title>My title</title> <head>
</head> <title>My title</title>
<body> </head>
<h1 id="head1" onclick='myfunction()'>A <body>
heading</h1> <h1 id="head1"
... onclick='myfunction()'>A
<script> heading</h1>
function myFunction() { <a class=’cls1’ href='#'>Link
document.getElementById("head1").innerHTML = "A text</a>
changes Heading 1";}
<p>Hakuna Matata</p>
</script>
</body>
</body>
</html> </html>
JS Where To
- Using the attribute src of the script tag
<head>
<script src="./script.js" /> <html>
</head> <head>
<body> <title>My title</title>
... </head>
<body>
<script src="./script.js" />
<h1 id="head1"
</body>
onclick='myfunction()'>A
heading</h1>
// script.js <a class=’cls1’ href='#'>Link
function myFunction() { text</a>
document.getElementById("head1").innerHTML = "A <p>Hakuna Matata</p>
changes Heading 1"; </body>
} </html>
JS - Events
JS Events
- HTML events are actions that happen to HTML elements. ( Firing, Triggering )
<body>
<h1 onclick='myfunction()'>A heading</h1>
<a class=’cls1’ href='#'>Link text</a>
<p>Hakuna Matata</p>
</body>
Event : is the click event Handler : myfunction()
// script.js
function myFunction() {
document.getElementById("head1").innerHTML = "A
changed Heading 1";
}
JS Events
NEXT
- CSS - Flex
- Js in Depth
- Assignment #1 Try to send it before 18/11
- Assignment #2 (JS) - 18/11
Thanks