Async Await in JavaScript
Understand how to use async/await in JavaScript to handle asynchronous calls more effectively and improve code readability.
September 6th, 2024
By: Ismail M. BOUSSEKINE
Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language such as HTML. CSS is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.
CSS can be used to define colors, fonts, layout, and many other things on your website. It allows you to separate the content of your website from its design, making it easier to maintain and update. It can be
<!DOCTYPE html>
<html>
<head> </head>
<body>
<h1 style="color: red">Hello World</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
}
</style>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
/* styles.css */
h1 {
color: red;
}
CSS is a powerful tool that allows you to create beautiful and responsive websites. In this workshop, we will cover the basics of CSS and show you how to style your web pages, It will be the continuation of the HTML workshop.
CSS supports various units of measurement for specifying lengths, including:
px
(pixels), cm
(centimeters), mm
(millimeters), in
(inches), pt
(points), pc
(picas)em
(relative to the font-size of the element usually 1em
=16px
), rem
(relative to the font-size of the root element), %
(percentage), vw
(viewport width) and vh
(viewport height).Example:
selector {
width: 50%; /* 50% of the parent element's width */
height: 100vh; /* 100% of the viewport height */
}
CSS allows you to specify colors using different formats:
red
, blue
, green
, etc.#RRGGBB
or #RGB
or #ffffff
(white) Try itrgb(255, 0, 0)
Try itrgba(255, 0, 0, 0.5)
(includes alpha for transparency)hsl(0, 100%, 50%)
(the first value is the hue in degrees, the second is the saturation as a percentage, and the third is the lightness as a percentage) Try ithsla(0, 100%, 50%, 0.5)
(includes alpha for transparency)Example:
selector {
color: #ff0000; /* Red color */
background-color: rgba(0, 0, 255, 0.3); /* Semi-transparent blue background */
}
CSS selectors are used to select the HTML elements you want to style. Common selectors include:
element
.class
#id
[attribute=value]
:pseudo-class
::pseudo-element
element element
element > element
Selectors have different levels of specificity, which determines which styles are applied when multiple rules match the same element. Specificity is calculated based on the number of each type of selector in the rule:
>
and ~
combinators: doesnt affect specificity*:not()
_ _:nth-child()_
, _:nth-of-type()\*
: doesnt affect specificityExample:
/* Element selector */
p {
color: blue;
}
/* Class selector */
.example {
font-size: 20px;
}
/* ID selector */
#unique {
margin: 10px;
}
/* Attribute selector */
input[type='text'] {
border: 1px solid black;
}
/* Pseudo-class selector */
a:hover {
color: red;
}
/* Pseudo-element selector */
p::first-line {
font-weight: bold;
}
/* Descendant selector */
div p {
color: blue;
}
/* Child selector */
div > p {
color: green;
}
padding is the space between the content and the border of an element. You can set the padding of an element using the padding
property in CSS. The padding property can have one, two, three, or four values.
/* One value */
selector {
padding: 10px; /* This will make padding from top, bottom, left and right 10px*/
}
/* Two values */
selector {
padding: 10px 20px; /* This will make padding from top and bottom 10px, left and right 20px*/
}
/* Three values */
selector {
padding: 10px 20px 30px;
}
/* Four values */
selector {
padding: 10px 20px 30px 40px;
}
/* Specifying the direction */
selector {
padding-top: 10px;
padding-right: 20px;
padding-bottom: 30px;
padding-left: 40px;
}
value can be in px, em, rem, %, or auto.
Margin is the space outside the border of an element. You can set the margin of an element using the margin
property in CSS. The margin property can have one, two, three, or four values.
/* One value */
selector {
margin: 10px; /* This will make margin from top, bottom, left and right 10px*/
}
/* Two values */
selector {
margin: 10px 20px; /* This will make margin from top and bottom 10px, left and right 20px*/
}
/* Three values */
selector {
margin: 10px 20px 30px;
}
/* Four values */
selector {
margin: 10px 20px 30px 40px;
}
/* Specifying the direction */
selector {
margin-top: 10px;
margin-right: 20px;
margin-bottom: 30px;
margin-left: 40px;
}
Border is the line that surrounds the content and padding of an element. You can set the border of an element using the border
property in CSS. The border property can have three values: width, style, and color.
/* border-color */
selector {
border-color: red; /* This will create a red border */
}
/* border-width */
selector {
border-width: 1px; /* This will create a 1px border */
}
/* border-style */
selector {
border-style: solid; /* This will create a solid border */
}
/* Combining all three */
selector {
border: 1px solid red; /* This will create a 1px solid red border */
}
Possible values for border-style are: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
Possible values for border-width are: thin | medium | thick | value(px, em, rem, %)
Outline is similar to border but it is outside the border. You can set the outline of an element using the outline
property in CSS. The outline property can have three values: width, style, and color.
/* outline-color */
selector {
outline-color: red; /* This will create a red outline */
}
/* outline-width */
selector {
outline-width: 1px; /* This will create a 1px outline */
}
/* outline-style */
selector {
outline-style: solid; /* This will create a solid outline */
}
/* Combining all three */
selector {
outline: 1px solid red; /* This will create a 1px solid red outline */
}
Please bare in mind:
An inline element does not start on a new line and only takes up as much width as necessary. You can set an element to be inline using the display
property in CSS.
selector {
display: inline;
}
Tags that are inline
by default :
<span>
, <a>
, <strong>
,<em>
, <img>
, <input>
, <label>
, <code>
...
A block element starts on a new line and takes up the full width available. You can set an element to be block using the display
property in CSS.
selector {
display: block;
}
The diffrence between inline and block is that inline elements do not start on a new line and only take up as much width as necessary, while block elements start on a new line and take up the full width available.
Tags that are block
by default: <div>
, <p>
, <h1>
to <h6>
, <ul>
, <ol>
, <li>
, <table>
...
An inline-block element is placed as an inline element on the same line as adjacent content but it can have a width and height. You can set an element to be inline-block using the display
property in CSS.
selector {
display: inline-block;
}
the diffrence between inline and inline-block is that inline-block elements are placed as inline elements on the same line as adjacent content but they can have a width and height.
background is the area behind the content and padding of an element. You can set the background of an element using the background
property in CSS.
selector {
background-color: red; /* This will set the background color to red */
}
You can also set the background image, repeat, position, and size using the background-image
, background-repeat
, background-position
, and background-size
properties.
selector {
background-image: url('image.jpg'); /* This will set the background image */
background-repeat: no-repeat; /* This will prevent the background image from repeating, there is also repeat, repeat-y and repeat-x */
background-position: center; /* This will center the background image */
background-size: cover; /* or contain, auto, or specific dimensions */
background-attachment: fixed; /* or scroll */
background-clip: border-box; /* or padding-box, content-box */
}
You can use shorthand to set all the background properties at once.
selector {
background: red url('image.jpg') no-repeat center/cover fixed border-box;
}
Text is the content of an element. You can set the text of an element using the color
, font-family
, font-size
, font-weight
, text-align
, and text-decoration
properties in CSS.
selector {
color: red; /* This will set the text color to red */
font-family: Arial, sans-serif; /* This will set the font family */
font-size: 16px; /* This will set the font size */
font-weight: bold; /* This will set the font weight */
text-align: center; /* This will center the text */
text-decoration: underline; /* This will underline the text */
}
You can use shorthand to set all the text (only font-*) properties at once.
selector {
font:
bold 16px Arial,
sans-serif;
}
CSS allows you to add shadow effects to elements using the box-shadow
and text-shadow
properties.
selector {
box-shadow: [h-offset] [v-offset] [blur-radius] [spread-radius] [color]
[inset];
}
h-offset
: Horizontal offset of the shadow.v-offset
: Vertical offset of the shadow.blur-radius
: The blur radius of the shadow.spread-radius
: The spread radius of the shadow.color
: The color of the shadow.selector {
box-shadow: 10px 10px 5px #888888; /* horizontal offset, vertical offset, blur radius, shadow color */
}
selector {
text-shadow: 2px 2px 4px #000000; /* horizontal offset, vertical offset, blur radius, shadow color */
}
CSS transitions allow you to change property values smoothly (over a given duration).
selector {
transition: property duration timing-function delay;
}
background-color
, color
, width
, height
, opacity
, transform
, etc.ease
, linear
, ease-in
, ease-out
, ease-in-out
, cubic-bezier(n,n,n,n)
.Example:
selector {
transition: all 0.3s ease-in-out;
}
selector:hover {
background-color: blue; /* This will transition smoothly to blue when hovered */
}
You can specify multiple transitions using commas:
selector {
transition:
background-color 0.3s ease,
transform 0.3s ease;
}
Positioning and layout are crucial aspects of CSS that allow you to control the placement and arrangement of elements on a web page. There are several positioning methods available in CSS, including static, relative, absolute, fixed, and sticky positioning.
A fixed position element is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. You can set an element to be fixed using the position
property in CSS.
selector {
position: fixed;
top: 10px; /* Position from the top */
right: 10px; /* Position from the right */
}
A sticky position element toggles between relative and fixed, depending on the user's scroll position. It is positioned relative until a given offset position is met in the viewport, then it "sticks" in place (like position:fixed).
selector {
position: sticky;
top: 0; /* Sticks to the top of the viewport */
}
An absolute position element is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). If an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
selector {
position: absolute;
top: 50px; /* Position from the top */
left: 50px; /* Position from the left */
}
A relative position element is positioned relative to its normal position. Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position.
selector {
position: relative;
top: 10px; /* Move 10px down from its normal position */
left: 10px; /* Move 10px right from its normal position */
}
Relative and absolute positioning can be used together to create complex layouts.
.container {
position: relative;
}
.item {
position: absolute;
top: 0;
left: 0;
}
This will position the .item
element at the top-left corner of the .container
element.
The z-index property specifies the stack order of an element. An element with a higher z-index value will be displayed on top of an element with a lower z-index value.
selector {
z-index: 1; /* Higher z-index value */
}
So if you have two elements that overlap, you can use the z-index property to control which one is displayed on top.
Flexbox is a layout model that allows you to design complex layouts with ease. It provides a more efficient way to lay out, align, and distribute space among items in a container, even when their size is unknown or dynamic.
.container {
display: flex;
justify-content: center; /* Aligns items horizontally */
align-items: center; /* Aligns items vertically */
align-content: center; /* Aligns items when there is extra space */
gap: 10px; /* Space between items */
flex-wrap: wrap; /* Wraps items to the next line */
}
Flexbox properties include flex-direction
, flex-wrap
, justify-content
, align-items
, and more, which provide a powerful set of tools for creating responsive layouts.
justify-content
: Aligns items horizontally.align-items
: Aligns items vertically.align-content
: Aligns items when there is extra space.gap
: Space between items.flex-wrap
: Wraps items to the next line.Congratulations! You have completed the CSS workshop. You now have a solid understanding of CSS and how to style your web pages. Keep practicing and experimenting with different designs to improve your skills. Thank you for joining us, and we hope to see you in future workshops. Happy coding!.
Understand how to use async/await in JavaScript to handle asynchronous calls more effectively and improve code readability.
September 6th, 2024
This article will guide you on how to choose your linux distribution based on your needs and use case, It will also provide a list of the best linux distributions out there.
September 13th, 2024
GDSC ENSTA Workshop on HTML for beginners. Learn the basics of HTML and how to create a simple webpage.
November 10th, 2024