CSS Basics

 CSS -> Cascading Style Sheet

inline styling

<!DOCTYPE html>
<html>
<head>
<title> HTML with CSS </title>
</head>
<body>
<p style="color:blue;"> This is a paragraph </p>
<p style="color:blue;"> This is also a paragraph </p>
</body>
</html>

Adding CSS in head section of html

<!DOCTYPE html>
<html>
<head>
<title> HTML with CSS </title>
<style>
p {
color: blue;
}
</style>
</head>
<body>
<p> This is a paragraph </p>
<p> This is also a paragraph </p>
</body>
</html>

Here
p {
color: blue;
}

selector {
    property: value;
}


Calling CSS from a file

HTML -> index.html

<!DOCTYPE html>
<html>
<head>
<title> HTML with CSS </title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<p> This is a paragraph </p>
<p> This is also a paragraph </p>
</body>
</html>

CSS -> style.css

p {
color: blue;
}

In CSS -> cascading is done. There are a set rules for this. Example we can define property define twice, the second one will be effective.

Type of selectors:

HTML -> index.html
<!DOCTYPE html>
<html>
<head>
<title> HTML with CSS </title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<p> This is a paragraph </p>
<p class="normal-paragraph"> This is also a paragraph </p>

<h1> This is my heading </h1>

<h2 id="myid"> This is sub heading </h2>
</body>
</html>

CSS -> style.css
/* type selector */

h1 {
font-size: 3em;
}

/* class selector */

.normal-paragraph {
color:aquamarine;
}

/* id selector */
#myid {
color:brown;
}

Multiple elements CSS
/* multiple elements */

h1, p {
border: 1px, solid, black;
}

Multiple Classes
/* multple classes */

.ingredientsList, .instructionsList {
font-size: 1.2em;
}

Selecting multiple types of elements

/* Using multiple kind of selector */

h2, .red, #redElement {
color: red;
}

distance between lines
.paragraph {
line-height: 1.6;
}

Aligning text to the centre in a box
.centered {
text-align: center;
}

No underline on the text
.no-underline {
text-decoration: none;
}

Spacing between letters
.spaced {
letter-spacing: 2px;
}

Make an element block type
.block-element {
display: block;
}

Make an element inline type
.inline-element {
display: inline;
}

Make an element inline-block

.inline-block {
display: inline-block;
}

Hide an element
.hidden {
display: none;
}


Positioning elements

relative positioning
.relative {
position: relative;
top: 10px;
}

absolute positioning
.absolute {
position: absolute;
}

z-index positioning
.front {
z-index: 10;
}


Flexbox
.container {
display: flex;
}

Change the axis to column
.column {
display: flex;
flex-direction: column;
}

Justify-content to move the elements
.centered {
display: flex;
justify-content: center;
}

align vertical direction
align-items: center;

flex-wrap - need to understand
.wrap {
display: flex;
flex-wrap: wrap;
}


spacing between elements
.spaced {
display: flex;
gap: 20px;
}

.grow {
flex-grow: 1;
}

.center-both {
display: flex;
justify-content: center;
align-items: center;
}


Grid:
columns
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

rows
.grid {
display: grid;
grid-template-rows: 100px 100px;
}

Span-2
.span-2 {
display: grid;
grid-column: span 2;
}


Gradient image:

.bg {
background-image: linear-gradient(rgb(0 0 255 / 0.5), rgb(255 255 0 / 0.5));
}

.rounded {
border-radius: 10px;
}




// Decoration

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1> CSS properties </h1>
</header>
<main>
<!-- box shadow -->
<div class="shadow"> shadow </div>

<!-- text shadow -->
<h1 class="text-shadow"> Text with Shadow </h1>

<!-- gradient -->
<div class="gradient">
Gradient
</div>

<!-- background size -->
<div class="title-background"></div>

<!-- transparent -->
<div class="transparent"> 50% Transparent </div>

<!-- mutliple shadow -->
<div class="multi-shadow">
Layered Shadows
</div>

</main>

</body>
</html>

Decoration

.shadow{
display: inline;
padding: 10px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 24px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 1);
}

.text-shadow {
text-shadow: 2px 2px 2px gray;
}

.gradient {
padding: 10px;
/* text-align: center; */
color: white;
width: 300px;
height: 50px;
background-image: linear-gradient(to bottom, blue, yellow);
}

.title-background {
background-image: url("https://www.mozilla.org/media/img/logos/firefox/logo-quantum.9c5e96634f92.png");
background-size: 150px;
width: 300px;
height: 300px;
border: 2px solid;
color: pink;
}

.transparent {
/* border: 2px solid red; */
font-size: 16px;
width: 300px;
padding: 10px;
background-color: blue;
color: white;
opacity: 50%;
}

.multi-shadow {
/* border: 2px solid red; */
padding: 10px;
width: 100px;
height: 50px;
box-shadow: 5px 5px blue, 10px 10px red, 15px 15px green;
}

// ANIMATION

media query

keyframe

positioning

grid

flex

Comments

Popular posts from this blog

Git Basics

Linux Basics

Internet basics