0% found this document useful (0 votes)
47 views20 pages

HTML and CSS Fundamentals Guide

The document outlines an HTML and CSS course with 6 modules covering topics like creating HTML pages, adding styles, positioning elements, semantic HTML5, flexbox, media queries and more. Module 2 discusses adding styles like borders, backgrounds and fun shapes using border-radius. Module 3 covers box model concepts like paddings and margins and using them on individual sides. It also introduces CSS positioning and centering techniques.

Uploaded by

fuck you
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views20 pages

HTML and CSS Fundamentals Guide

The document outlines an HTML and CSS course with 6 modules covering topics like creating HTML pages, adding styles, positioning elements, semantic HTML5, flexbox, media queries and more. Module 2 discusses adding styles like borders, backgrounds and fun shapes using border-radius. Module 3 covers box model concepts like paddings and margins and using them on individual sides. It also introduces CSS positioning and centering techniques.

Uploaded by

fuck you
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NgNinja Academy | All Rights Reserved

HTML and CSS

Table Of Content

Module 1 - Getting Started


Create Your First HTML Page
Write the following boilerplate code in [Link] le
Run Your First HTML File
Run the application on the Internet for FREE
If I do not put <! DOCTYPE html> will HTML5 work?
DOM
When should you use section, div or article?
section
article
div
Headings
Paragraph
Links / Anchor elements
Images
Image Sizes
Image as links
Module 2 - Styling your Webpage
Create a CSS File
Then add your style in your [Link] le
Now let's create the body of your Valentine's Day card
Now let's add your rst style
Selectors
.class
child .class
#id
element tag
Mix n match

1 / 20
NgNinja Academy | All Rights Reserved

Id and Class
Element and Class
Advanced Selectors
adjacent selector
attributes selector
Backgrounds
Colors
Borders
Fun with Border Radius
Shapes
Shorthand
Circle and leaf
Circle
Leaf
Module 3 - Display and position your elements
Box model
Total width of an element should be calculated like this:
Total height of an element should be calculated like this:
Margins
Margin On Individual Sides
Margin Shorthands
Auto Margin
Paddings
Padding On Individual Sides
Padding Shorthands
Display
Block
Inline
Inline-block
None
Visibility Hidden
Flex
Positions
Static
Relative
Absolute
Fixed
Centering:
Centering Vertically
CSS Float
Clearing Floats
Methods to clear oat:
Module 4 - Semantic HTML5
Semantic HTML?
More about Semantic HTML
Di erence between HTML and HTML5?

2 / 20
NgNinja Academy | All Rights Reserved

HTML
HTML 5
Below are new semantic elements
What elements have disappeared in the latest HTML?
Di erence between <div> and <frame>?
What is HTML5 Web Storage?
localStorage:
sessionStorage:
Module 5 - Flexbox intro and media query
Flexbox
Flex box container properties
Flex box item properties
Flexbox Examples
Media queries
Always Design for Mobile First
Orientation: Portrait / Landscape
Let's talk about the sizes - px vs em vs rem
How to calculate PX from REM
More on rem vs em
CSS Grids
Flexbox
Grids
Example
Example #2 - Gaps
Example #3 - Fractions
Example #4 - Fractions Contd.
Nested grids
Start-End points of Grid
Module 6 - Quirks, tips, and tricks
FOUC
How to avoid it?
BEM naming convention
OOCSS - Object Oriented CSS
CSS User Agent Styles
Normalizing CSS
Reset CSS
Validate your CSS
Testing Strategies
Conditional CSS

3 / 20
NgNinja Academy | All Rights Reserved

Module 1 - Getting Started

Create Your First HTML Page

Create an app folder on your computer


Create le named [Link] inside app folder on your computer
Open that page in your favorite text editor
I personally use VSCode

Module 2 - Styling your


Webpage

Now let's add your rst style

Let's add styles for your valentine's day card


We are using .card - class selector to grab the card DIV and style it
Here we are just setting a nice red border: 10px solid #E53038;
height: 100vh; is done to match out body tag's height - which is the full view-port height.

4 / 20
NgNinja Academy | All Rights Reserved

display: flex; makes this card DIV a ex-box.


We are just making all our flex-children align in vertically and horizontally center
position in one column.
NOTE: We will learn about ex-box in the later section.

.card {
border: 10px solid #E53038;
height: 300px;
width: 300px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

5 / 20
NgNinja Academy | All Rights Reserved

Fun with Border Radius

Shapes

Borders also take another property called border-radius using which you can give di erent
shapes to your elements

In the above illustration we have a square on the left and circle on the right
If you provide border-radius of 50% it will turn your square into a circle

.square {
border-radius: none;
}

.circle {
border-radius: 50%;
}

6 / 20
NgNinja Academy | All Rights Reserved

Shorthand

If one value is set, this radius applies to all 4 corners.


If two values are set, the rst applies to top-left and bottom-right corner, the second
applies to top-right and bottom-left corner.
If three values are set - the second value applies to top-right and also bottom-left.
If four values apply to the top-left, top-right, bottom-right, bottom-left corner (in
that order).

7 / 20
NgNinja Academy | All Rights Reserved

<div class="card one">


<h1 class="">One</h1>
</div>
<div class="card two">
<h1 class="">Two</h1>
</div>
<div class="card three">
<h1 class="">Three</h1>
</div>
<div class="card four">
<h1 class="">Four</h1>
</div>

// all 4 corners
.one {
border-radius: 50%;
}

// 10% top-left and bottom-right, 20% top-right and bottom-left


.two {
border-radius: 10% 20%
}

// 10% top-left, 20% top-right and also bottom-left, 30% bottom-right


.three {
border-radius: 10% 20% 30%;
}

// top-left, top-right, bottom-right, bottom-left corner (in that order)


.four {
border-radius: 10% 20% 30% 40%;
}

.card {
border: 10px solid #E53038;
height: 100px;
width: 100px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}

8 / 20
NgNinja Academy | All Rights Reserved

Circle and leaf

Circle

.circle {
border-radius: 50%;
}

9 / 20
NgNinja Academy | All Rights Reserved

Leaf

.leaf {
border-radius: 5px 20px 5px;
}

10 / 20
NgNinja Academy | All Rights Reserved

Module 3 - Display and


position your elements

Paddings

Paddings are used to generate space around the given element's content - inside its border

<div class="myDiv">
<p>My Paragraph</p>
</div>

// styles

.myDiv {
padding: 20px;
}

padding: 20px; gives the div element padding of 20px


So, basically there will be 20px space between p and div on all the sides

11 / 20
NgNinja Academy | All Rights Reserved

Padding On Individual Sides

You can also give padding to the elements on any particular side if you'd want

padding-top
padding-right
padding-bottom
padding-left

Padding Shorthands

To give padding on all the sides

div {
padding: 20px;
}

The below example give padding 20px top and bottom


And give padding 40px left and right

div {
padding: 20px 40px;
}

12 / 20
NgNinja Academy | All Rights Reserved

The below example give padding 20px top


And give padding 40px left and right
And give padding 50px bottom

div {
padding: 20px 40px 50px;
}

13 / 20
NgNinja Academy | All Rights Reserved

Display

Block

This property stretches the element left to right as far as it can


Default is block for div, p, form, header, footer, section (and some more)
Such elements cannot be placed on the same horizontal line with any other display modes
Except when they are oated
Like shown in the illustration -> every item stretches and uses up the entire row

Inline

Inline element sits in line


Without disrupting the ow of other elements
Like shown in the illustration -> every item takes up only the space it needs
Item wraps to the next row if there is no enough space
span, em, b are examples of inline elements
They take only width needed for it
They do not honor vertical padding
No width
No height
They just ignores them
Horizontal margin and padding are honored
Vertical margin and padding are ignored

14 / 20
NgNinja Academy | All Rights Reserved

Inline-block

This is just like inline element


BUT they will respect the width and height
Basically, they combine the properties of both block elements and inline elements
The element can appear on the same horizontal line as other elements
So, like the illustration shows if you set width you can t all the items together in a single row

None

These elements will not appear on the page at all


But you can still interact with it through DOM
NO space allocated on the page

Visibility Hidden

Space is allocated for it on the page


Tag is rendered on the DOM
The element is just no visible

div {
visibility: hidden;
}

Flex

15 / 20
NgNinja Academy | All Rights Reserved

Flex property gives ability to alter its item's width/height to best ll the available space
It is used to accommodate all kind of display devices and screen sizes
Fills available space
Or shrink to prevent over ow

16 / 20
NgNinja Academy | All Rights Reserved

Module 4 - Semantic HTML5

What is HTML5 Web Storage?

With HTML5, browsers can store data locally


It is more secure and faster than cookies
You are able to store large information -> more than cookies
They are name/value pairs
2 objects
[Link] - stores data with no expiration date
[Link] - stores data for one session (data is lost when the tab is closed)

localStorage:

Stores the data with no expiration date


Data is NOT deleted when browser is closed
Available the next day, week, or year
It's not possible to specify expiration
You can manage its expiration in your app

// Store
[Link]("lastname", "Smith");

// Retrieve
[Link]("result").innerHTML =
[Link]("lastname");

17 / 20
NgNinja Academy | All Rights Reserved

sessionStorage:

Stores the data for only one session


Data deleted when browser is closed

if ([Link]) {
[Link] = Number([Link]) + 1;
} else {
[Link] = 1;
}

[Link]("result").innerHTML = "You have clicked the button


" +
[Link] + " time(s) in this session.";

18 / 20
NgNinja Academy | All Rights Reserved

Module 5 - Flexbox intro and


media query

Let's talk about the sizes - px vs em vs rem

Pixels are ignorant, avoid using them

If you’re setting all of your font-sizes, element sizes and spacing in pixels, you’re not treating the
end user with respect.

Users will have to zoom in and out with ctrl plus +/- depending on the device they are on

REMs are a way of setting font-sizes based on the font-size of the root HTML element

Allows you to quickly scale an entire project by changing the root font-size

em is relative to the font size of its direct or nearest parent

When you have nested styles it becomes di cult to track ems


This is what REMs solve - the size always refers back to the root

Both pixels and REMs for media queries fail in various browsers when using browser zoom, and
EMs are the best option we have.

How to calculate PX from REM

19 / 20
NgNinja Academy | All Rights Reserved

EX: HTML font-size is set to 10px, paragraph font-size is set to 1.6rem


Then size in pixels is - 1.6rem * 10px = 16px

Module 6 - Quirks, tips, and


tricks

Normalizing CSS

Small CSS le that provides cross-browser consistency


Provides default styles for HTML elements
Make sure that all HTML elements renders the same way in ALL browsers - same padding, margin,
border, etc..
In some cases this approach applies IE or EDGE styles to the rest of the browsers

Reset CSS

This approach says that we don’t need the browsers’ default styles at all
We’ll de ne in the project according to our needs
CSS Reset resets all of the styles that come with the browser’s user agent
Grab sample CSS reset here
The problem with CSS Resets is that they are ugly and hard to debug
Solution - use Normalize CSS with little bit of CSS Reset
Unlike an ordinary CSS reset, target speci c HTML tags’ styles rather than making a big list of tags.
Make it less aggressive and a lot more readable

20 / 20

Common questions

Powered by AI

Pixels provide fixed sizing, which doesn’t adapt to user preferences, making scalability and responsiveness difficult . Ems are relative to the font size of their direct or nearest parent and can be problematic in nested styles due to their cumulative effect, but they better adapt to user settings and scales with the current environment . Rems are based on the root HTML element’s font size, which solves the cascading issue of ems by offering a consistent base. However, ems are highlighted as the best option in media queries due to their adaptive nature, ensuring units respond to browser zoom changes more effectively than pixels or rems .

Modern CSS layout systems like flexbox and grid enhance design efficiency by providing more direct control over element alignments, spacing, and order within containers. Unlike older float-based methods, which often require additional clearing techniques to manage layouts, flexbox allows for flexible, responsive designs that adjust dynamically based on available space . Grid layout further extends these capabilities by offering two-dimensional control over rows and columns, simplifying complex layouts without excessive use of nested elements or hacks used in legacy systems . This shift reduces code complexity and improves maintainability and responsiveness .

The use of flexbox properties allows for enhanced layout flexibility of web elements by enabling automatic adjustment of item sizes within a container to fill available space or prevent overflow. Flexbox supports flexible sizing, alignment, and space distribution among items regardless of screen size or device, thus providing a responsive design . Furthermore, properties such as 'justify-content' and 'align-items' allow items to be centered both vertically and horizontally, optimizing the spatial distribution within flex containers .

Object-oriented CSS (OOCSS) differs from traditional CSS by promoting the separation of structure from skin and ensuring visual consistency through reusable, modular components. It enhances maintainability and scalability for large projects by structuring styles around objects that can be mixed and matched across various design contexts . This approach encourages a DRY (Don't Repeat Yourself) coding philosophy, reducing redundancy and making style updates more efficient, therefore improving collaboration among teams working on shared or large codebases .

The CSS box model is crucial as it defines the space an element occupies on a page, which includes its content, padding, border, and margin. Understanding this model helps control element size and spacing consistently, which is vital for designing layouts that are both visually appealing and consistent across different devices . By manipulating properties such as total width and height using padding, borders, and margins, developers can achieve desired layouts and ensure that elements are appropriately spaced and aligned .

Semantic HTML5 elements like <section>, <article>, and <header> provide meaningful context to the content, making it easier for browsers and search engines to understand the structure and purpose of web pages . They enhance accessibility by aiding assistive technologies, improving access to the content for visually impaired users. Semantics also facilitate better code maintainability and readability, allowing developers to convey more precise information about the webpage's layout and sections .

Media queries in CSS allow developers to apply styles based on different conditions such as screen size, resolution, or orientation. They are pivotal in mobile-first design, which prioritizes designing for smaller screens first and then adapting to larger displays . By utilizing media queries, designers can adjust layouts, font sizes, and other visual characteristics, ensuring the website is responsive and provides a seamless experience across different devices and screen sizes .

CSS resets and normalization are techniques employed to handle browser default styling discrepancies. CSS reset wipes out all default styles, providing a clean slate, but can create debugging complexities due to its aggressive nature . Normalizing CSS, on the other hand, aims to make elements render consistently across browsers by applying a minimal and targeted approach, ensuring cross-browser compatibility without stripping away essential styling. The use of both, strategically combined, ensures that developers have a reliable baseline while also catering to specificity requirements .

CSS border-radius properties enable the creation of various non-rectangular shapes by rounding the corners of box elements. When a uniform border-radius of 50% is applied, it transforms a square into a circle . By assigning different values to each of the four corners, such as ‘10% 20% 30% 40%’, unique asymmetric shapes can be crafted, allowing creative design applications to break away from traditional rectangular forms . By using shorthand properties, developers can efficiently control these shapes in a concise manner .

HTML5 web storage offers name/value pairs to store data as either localStorage or sessionStorage, providing a solution that is more secure and faster than traditional cookies . Unlike cookies, which are included in every server request increasing transmission size, web storage data isn't automatically transferred with each HTTP request. LocalStorage provides persistent data storage without an expiration date, while sessionStorage deletes data once the session ends. This approach allows more significant data storage capacity than cookies, thus enhancing performance and user experience in web applications .

You might also like