Docsity

Basic Structure of an Html and Css, Cheat Sheet of Computer science

Partial preview of the text

Download Basic Structure of an Html and Css and more Cheat Sheet Computer science in PDF only on Docsity!

HTML – Building

the Skeleton of

a Website

The Language Used to Build Every Website Presented By: Mahanoor Sayyed

FOUNDATION

What is HTML?

Imagine you're building a house. A house needs bricks, doors, windows, and a roof. A website also needs something to build it — and that something is HTML.

🦴 HTML

The Skeleton — defines structure and content of every webpage.

🦴 CSS

The Clothes — adds beauty, color, and visual style. HTML tells the browser: "This is a heading." "This is a paragraph." "This is an image." "This is a button." HTML does not make websites beautiful on its own — but without it, there is no webpage.

META TAGS

Meta Tags: Information About Information

Meta means "information about information." Like a chocolate wrapper that tells you the expiry date, company, and ingredients — it is not the chocolate, it is data about the chocolate. Meta tags give the browser and search engines information about your webpage.

charset="UTF-8"

Tells the browser how to read text. UTF-8 supports all world languages — English, Hindi, Arabic, Marathi — and even Emoji 😊. Without it, you might see @#$%^&* instead of readable text.

viewport (Most Important)

Without viewport, a phone shows the desktop version — everything becomes tiny. With it, the phone adjusts everything to fit the screen. width=device-width uses the actual device width; initial-scale=1.0 opens at 100% zoom.

KEY TAGS

Title, Body & Base Tags

These three tags shape how your webpage is found, displayed, and how its resources are located. Tag Where It Appears Why It Matters Browser tab, Google Search, Bookmarks Very important for SEO — it's the first thing search engines and users read. <body> Everything visible on the page Contains headings, paragraphs, images, videos, buttons, tables, lists, and forms. <base> Inside the head — invisible to users Sets the main address for all relative links. Like telling a postman the house address — now you only need to write the room number. Useful for large websites. <author> meta Browser & search engines only Tells who created the webpage (e.g., John, Mahanoor, Ali). Pro Tip: Always write a clear, descriptive <title> tag — it is the single most important SEO element in your HTML head.

SEMANTIC TAGS Semantic Tags: Giving Meaning to Your HTML HTML5 brought clarity to webpage structure by introducing semantic tags. Instead of generic elements, these tags explicitly describe their purpose, making code more readable, accessible, and SEO-friendly. Tag Meaning & Purpose Represents introductory content, often containing navigation, logos, and headings for its section or the entire page. Defines a section that contains navigation links, making it easy for users to find their way around the site. Contains the dominant content unique to the document. A page should typically only have one element. A standalone section of content within a document, typically with a heading, like chapters or grouped content. Represents independent, self-contained content, such as a blog post, news story, or forum comment. Content that is tangentially related to the main content, like a sidebar, callout box, or advertisement. Contains information about its containing section, such as author, copyright data, or related links. Often at the bottom of the page.

Input Tags & Forms

Forms collect user information — from registration and login to feedback and contact. The tag is the workhorse of every form, with a type attribute that changes its behaviour entirely.

Text & Password Inputs

RESPONSIVE DESIGN

Responsive Design: One Website, Every Screen

Responsive means one website that works perfectly on 🦴 Mobile, 🦴 Laptop, and 🦴 Desktop — without building a separate version for each.

Viewport Meta Tag

The most critical piece. Without it, the phone shows a shrunken desktop version. With it, the browser automatically adjusts layout to fit the device's real width.

CSS Media Queries

CSS rules that apply only at certain screen widths. For example: "On screens smaller than 768px, stack columns vertically." Pairs with the viewport tag to create truly adaptive designs.

Flexible Layouts & Images

Use percentage-based widths instead of fixed pixels, and set images to max- width: 100% so they never overflow their container on smaller screens.

INTRODUCTION

What is CSS?

The Paint Analogy 🦴

Imagine you buy a new toy. The toy works, but it has no color. Now you paint it — it looks beautiful. The toy = HTML. The paint = CSS. Without CSS you get a plain website 😐. With CSS you get a beautiful website 😍. CSS stands for Cascading Style Sheets. It is the language that controls how HTML elements look on screen — colors, fonts, spacing, layout, and more. HTML builds the structure. CSS decorates it. JavaScript makes it interactive.

SETUP

CSS File Structure & Connecting CSS

Understanding the typical project structure helps keep your code organized. CSS files often live in a dedicated folder. project/ ├── index.html ├── style.css ├── images/ │ └── logo.png ├── js/ │ └── script.js └── fonts/

SETUP

There are three primary ways to link CSS to your HTML document, each with its own use cases and implications for

project management and performance.

Inline CSS

Hello

  • (^) CSS is written directly within the HTML tag's style attribute.
  • (^) Good for quick tests or very small, specific style overrides.
  • (^) Not recommended for large projects due to poor maintainability and reusability.

Internal CSS

  • (^) CSS is embedded within the BOX MODEL Margin, Padding & the Box Model

The Box Model — Every Element is a Box

In CSS, every HTML element lives inside a box. That box has four layers: Content → Padding → Border → Margin. Understanding this model is essential for controlling spacing and layout. 01

Content

The actual text or image inside the element. Width and height properties control this area directly. 02

Padding

Space inside the box, between content and border. Like a gift box — padding is the cushion around the gift. padding: 20px; 03

Border

The visible edge of the box. border: 2px solid black; draws a frame. Easy trick — Padding = Inside , Margin = Outside. 04

Margin

Space outside the box — like the empty space outside a notebook page. margin: 20px; pushes the box away from other boxes.

SELECTORS

Class & ID Selectors

Class Selector (.class)

Written as .blue { color: blue; } in CSS and class="blue" in HTML. A class can be applied to many elements — like a school uniform worn by many students. Reusable and flexible.

ID Selector (#id)

Written as #title { color: red; } in CSS and id="title" in HTML. An ID must be unique — like an Aadhaar number, only one person can have it. Use for single, specific elements.

Class vs. ID — Easy Rule

Class → Many elements. Use .class when multiple elements share the same style. ID → One element. Use #id for a single, unique element on the page.

FLEXBOX Flexbox — Arranging Items with Ease

align-items gap
justify-
content
display:flex

Flexbox solves most layout problems with just a few lines of CSS. It is the go-to tool for centering and spacing elements.

display: flex

Add display: flex; to a container. Its child elements automatically line up in one horizontal row. The container becomes a flex container.

justify-content & align-items

justify-content: center centers items horizontally. Options: start, end, space-between, space-around, space-evenly. align-items: center centers items vertically — perfect centering with both together.

gap

gap: 20px adds space between flex items automatically. No need to add margins to each individual child element — clean and simple.

BOOTSTRAP Bootstrap: Components in Action Bootstrap is a ready-made CSS library that provides pre-built components and a responsive grid system, making web development faster and more consistent across devices. It simplifies styling from hundreds of lines of CSS to concise class names. Grid System Bootstrap's 12-column grid allows for flexible and responsive layouts. Define rows and columns with classes like col-md- to control sizing across different screen widths.

Left Right

Buttons Easily create styled buttons with various appearances using utility classes. Consistency is built-in. Save Submit Cards Cards are versatile content containers for showcasing products, blog posts, or courses. They include an image, title, description, and action button.

Image Title Description Button

Navbar A responsive navigation bar that adapts to screen size, providing a seamless user experience across devices, including mobile hamburger menus.

  • (^) Brand/logo
  • (^) Navigation links
  • (^) Mobile menu