vnd.openxmlformats-officedocument.wordprocessingml.document&rendition=1-2
vnd.openxmlformats-officedocument.wordprocessingml.document&rendition=1-2
Selector forms
a) Write a program to apply different types of selector forms Simple selector (element, id, class,
group, universal) , Combinator selector (descendant, child, adjacent sibling, general sibling) , Pseudo-
class selector ,Pseudo-element selector ,Attribute selector
AIM: To Write a program to apply different types of selector forms Simple selector , Combinator
selector , Pseudo-class selector ,Pseudo-element selector, Attribute selector
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<header id="main-header">
<nav>
<ul>
</ul>
</nav>
</header>
<section class="content">
</section>
<footer>
</footer>
</body>
</html>
STYLES.CSS(FILE NAME)
/* Simple Selectors */
/* Element selector */
h1 {
color: blue;
/* ID selector */
#main-header {
background-color: #f2f2f2;
padding: 20px;
/* Class selector */
.nav-link {
color: green;
text-decoration: none;
/* Group selector */
h1, p {
}
/* Universal selector */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
/* Combinator Selectors */
.content p {
font-size: 16px;
.content > p {
color: red;
/* Adjacent sibling selector (selects the <p> that immediately follows an <h1>) */
h1 + p {
font-weight: bold;
h1 ~ p {
font-style: italic;
/* Pseudo-classes */
/* :hover pseudo-class */
.nav-link:hover {
color: orange;
/* :first-child pseudo-class */
.content p:first-child {
background-color: lightblue;
/* :last-child pseudo-class */
.content p:last-child {
color: purple;
/* :nth-child pseudo-class */
.content p:nth-child(2) {
color: darkred;
/* :not pseudo-class */
p:not(.intro) {
background-color: #e0e0e0;
/* Pseudo-elements */
/* ::before pseudo-element */
h1::before {
color: red;
}
/* ::after pseudo-element */
h1::after {
color: gray;
/* Attribute Selectors */
/* Select all anchor elements with href attribute starting with "https" */
a[href^="https"] {
font-weight: bold;
color: darkblue;
a[href*="example"] {
color: green;
/* Select all anchor elements with href attribute ending with ".com" */
a[href$=".com"] {
color: purple;
}
OUTPUT:
RESULT: The above program to apply different types of selector forms Simple selector ,Combinator
selector , Pseudo-class selector ,Pseudo-element selector, Attribute selector was successfully
Executed.
5)a) Write a program to demonstrate the various ways you can reference a color in CSS.
Aim: To Write a program to demonstrate the various ways you can reference a color in CSS.
Program:
<!DOCTYPE html>
<html>
<body>
<p>Same as color name "Tomato":</p>
<h1 style="background-color:rgb(255, 99, 71);">rgb(255, 99, 71)</h1>
<h1 style="background-color:#ff6347;">#ff6347</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">hsl(9, 100%, 64%)</h1>
<p>Same as color name "Tomato", but 50% transparent:</p>
<h1 style="background-color:rgba(255, 99, 71, 0.5);">rgba(255, 99, 71, 0.5)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">hsla(9, 100%, 64%, 0.5)</h1>
<p>In addition to the predefined color names, colors can be specified using RGB, HEX, HSL, or even
transparent colors using RGBA or HSLA color values.</p>
</body>
</html>
Output:
Same as color name "Tomato":
#ff6347
b) Write a CSS rule that places a background image halfway down the page, tilting it horizontally. The
image should remain in place when the user scrolls up or down.
Aim: To Write a CSS rule that places a background image halfway down the page, tilting it
horizontally. The image should remain in place when the user scrolls up or down.
Program:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h1 {
text-align: center;
}
#ex {
text-align: center;
background-image:
url("https://media.geeksforgeeks.org/wp-content/uploads/geeks-25.png");
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>
<body>
<h1>Example for fixed Background Image</h1>
<div id="ex">
<p>
Paragraphs are the building block of papers. Many students define paragraphs in terms of
length: a paragraph is a group of at least five sentences,
</p>
<br><br>
<p>
a paragraph is half a page long,etc. In reality, though, the unityand coherence of ideas among
sentences is what constitutes a paragraph.
</p>
<br><br>
<p> A paragraph is defined as “a group of sentences or a single sentence that forms a unit”
(Lunsford and Connors 116).
</p>
<br><br>
<p>
Length and appearance do not determine whether a section in a paper is a paragraph.
</p>
<br><br>
<p>
For instance, in some styles of writing, particularly journalistic styles, a paragraph can be just
one sentence long. Ultimately, a paragraph is a sentence or group of sentences that support
one main idea.
</p>
<br><br>
<p>
In this handout, we will refer to this as the “controlling idea,” because it controls what
happens in the rest of the paragraph.
</p>
</div>
</body>
</html>
Output:
5 c) Write a program using the following terms related to CSS font and text:
AIM: Write a program using the terms related to CSS font and text font-size, font-weight, font-style,
text-decoration,text-transformation,text-alignment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<header>
</header>
<section class="content">
<h2 class="font-example">Font-Size Example</h2>
<p class="font-weight-example">HTML stands for Hyper Text Markup Language and HTML is the
standard markup language for creating Web pages </p>
<p class="font-style-example">CSS stands for Cascading Style Sheets and describes how HTML
elements are to be displayed on screen, paper, or in other media</p>
<p class="text-decoration-example">CSS saves a lot of work. It can control the layout of multiple
web pages all at once</p>
</section>
</body>
</html>
OUTPUT
HTML stands for Hyper Text Markup Language and HTML is the standard markup
language for creating Web pages
Font-Style Example
CSS stands for Cascading Style Sheets and describes how HTML elements are to be
displayed on screen, paper, or in other media
Text-Decoration Example
CSS saves a lot of work. It can control the layout of multiple web pages all at once
Text-Transform Example
Text-Alignment Example
RESULT:The above program using the terms related to CSS font and text font-size, font-weight,
font-style, text-decoration,text-transformation,text-alignment was successfully Executed.
5d) Write a program, to explain the importance of CSS Box model using
AIM: To Write a program, to explain the importance of CSS Box model using Content, Border,
Margin,padding
Source code:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
<p>The CSS box model is essentially a box that wraps around every HTML element. It consists of:
borders, padding, margins, and the actual content.</p>
</body>
</html>
OUTPUT
Result: The above program, to explain the importance of CSS Box model using Content, Border,
Margin,padding was successfully Executed.