CMA Unit2 Solved
CMA Unit2 Solved
o HTML, CSS and JavaScript are used for web designing. It helps the web designers to apply
style on HTML tags. CSS saves a lot of work. It can control the layout of multiple web pages
all at once.External stylesheets are stored in CSS files
2. What are the uses of <div> and <span> tags when used with CSS.
<div> is a block-level element, which means that it starts a new line on the page and takes up the full
width of its container.
<span> is an inline element, which means that it does not start a new line and only takes up as much
space as its content
When used with CSS, <div> tags can be used to control the layout of a web page by creating
sections, columns, and other containers. For example, you could use a <div> tag to create a sidebar
on your website, or to group related content together in a single column.
<span> tags can be used to style specific parts of text or other elements on a web page. For
example, you could use a <span> tag to make a certain word or phrase bold, or to change its color.
<b> and <i> - These tags are used to bold and italicize text, respectively. However, they are not
semantically correct, meaning that they do not provide any information about the meaning of the
text. Instead, you should use the <strong> and <em> tags, which are semantically correct and provide
more information about the text, such as whether it is important or emphasized.
<font> tag:The <font> tag is used to specify the font face, size, and color of text within HTML
documents. However, it is considered outdated and not recommended for use. It is better to apply
styles using CSS, which provides more flexibility and separation of concerns between content and
presentation.
<marquee> tag:The <marquee> tag was used to create scrolling text or images. However, it is not
part of the official HTML specification and is not recommended for use. Animated or scrolling effects
are better achieved using CSS animations or JavaScript.
<frame>, <frameset>, and <noframes> tags:These tags were used in the past to create frames and
frame-based layouts. However, frames are now deprecated and are not recommended for use due to
accessibility issues, poor search engine optimization, and difficulty in maintaining and navigating
websites.
| CSS Selector |
+------------------------+
| Style |
+------------------------+
| Property-Value |
| Declarations |
| (CSS Properties) |
+------------------------+
5. What are the ways we can use style sheets in an HTML document? Mention the tags used to
work with them.
Inline style Within the HTML element that it is styling style attribute
Internal style Within the <style> element in the <head> section <style> element
6. What is the use of <link> tage? Mention its attributes with their purpose.
The <link> tag is used to link an HTML document to an external resource, such as a style sheet, a
favicon, or a script. The <link> tag is typically placed in the <head> section of an HTML document.
rel attribute: Specifies the relationship between the current document and the external
resource.
Id selector
Class selector
Universal selector
Grouping selector
Pseudo selector
The universal selector (*) selects all HTML elements on the page. The universal selector is used as a
wildcard character. The universal selector in CSS is represented by an asterisk (*)
The universal selector can be used to set styles for all elements on a web page, or to combine with
other selectors to create more specific selectors. For example, the following CSS selector would
select all h1 elements and set their color to red:
Eg: h1 * {
color: red;}
The :not() selector is a CSS pseudo-class that selects all elements that do not match a specified
selector. It is often used to negate the selection of a particular selector. For example, the following
CSS selector would select all elements that are not h1 elements:
:not(h1) {
color: red;}
The :not() selector can also be used to select elements that do not have a particular attribute
11. Write a note on the two CSS commands required to use web fonts.
@font-face: This command defines a new font face. It takes a number of arguments, including the
font family name, the font file location, and the font weight and style.
font-family: This command specifies the font family for an HTML element. It can be used to specify a
single font family or a list of font families.
Eg: @font-face {
font-family: 'CustomFont';
body {
}
12. Specify the properties required to make a font bold and italic.
font-weight:
The font-weight property is used to control the thickness or boldness of the text.
font-style:
The font-style property is used to specify the style of the font, such as italic or
normal.
1. Keyword:
CSS provides a set of predefined color keywords that can be used to specify the color
of text.
2. Hexadecimal Notation:
The code represents the levels of red, green, and blue (RGB) in the color.
Colors can be specified using the RGB color model by specifying the intensity of red,
green, and blue.
RGB values range from 0 to 255, representing the intensity of each color channel.
Colors can also be defined using the HSL (Hue, Saturation, Lightness) color model.
Hue represents the color itself, saturation represents the intensity of the color, and
lightness represents how light or dark the color appears.
Example: color: hsl(120, 100%, 50%); sets the text color to a fully saturated green.
Syntax: text-transform:capitalize;
The text-decoration-line property specifies the type of line to be added to the text. The possible
values for the text-decoration-line property are:
The text-shadow property in CSS is used to add shadows to text. It takes a comma-separated list of
shadows to be applied to the text. Each shadow is described by some combination of X and Y offsets
from the element, blur radius, and color.
h-shadow Required. The position of the horizontal shadow. Negative values are allowed Demo ❯
v-shadow Required. The position of the vertical shadow. Negative values are allowed Demo ❯
color Optional. The color of the shadow. Look at CSS Color Values for a complete list of possible color values
justify Stretches the lines so that each line has equal width (like in newspapers and magazines)
initial Sets this property to its default value. Read about initial
Eg: h1 {
text-align: center;
}
18. Write a note on margin and padding shorthand
An element's padding is the space between its content and its border.(padding)
padding-top
padding-right
padding-bottom
padding-left
The margin property sets the margins for an element, and is a shorthand
property for the following properties:
margin-top
margin-right
margin-bottom
margin-left
Line
Inline boxes do not break lines. Block boxes break lines.
break
Width Inline boxes do not have a fixed width. Block boxes have a fixed width.
o border-style
o border-color
o border-width: Specifies the width of the border, border-width: 1px;
o eg: h2 { border: 4px dotted blue;}
21. Write a note on providing background color in CSS with appropriate property.
In CSS, the background-color property is used to set the background color of an element. The
background color is the color that appears behind the element's content and border.
The background-color property can be set to a color name, a hexadecimal color code, or an RGB
color code.
Syntax: selector {
background-color: color;
}
1.Named Colors:
You can use named colors such as red, blue, green, or yellow to set the background
color.
2. Hexadecimal Colors:
Hexadecimal color codes are specified using a pound sign (#) followed by six
alphanumeric characters representing the red, green, and blue (RGB) values.
3. RGB Colors:
RGB colors allow you to define the intensity of red, green, and blue as integer values
between 0 and 255.
4. RGBA Colors:
RGBA colors are similar to RGB colors but include an additional alpha channel that
represents the color's transparency.
HSL (Hue, Saturation, Lightness) and HSLA (HSL with alpha) colors provide an
alternative way to specify colors based on hue, saturation, and lightness values.
Hue ranges from 0 to 360 degrees, saturation and lightness range from 0% to 100%,
and alpha ranges from 0 to 1.
inset: Normally, the shadow generates outside of the box, but by using inset, the shadow can be
created within the box.
initial: It is used to set the property of the box-shadow to its default value.
none: It is the default value that does not include any shadow property.
#col {
he CSS float property is a positioning property. It is used to push an element to the left or right,
allowing other element to wrap around it. It is generally used with images and layouts.
none It specifies that the element is not floated, and will be displayed just where it occurs in the text. this is a
default value.
The start state defines the initial state of the element before the animation begins. It specifies the
element's properties, such as position, size, opacity, color, or any other CSS property, as they are
before any animation effects are applied.
The end state, on the other hand, represents the desired appearance or behavior of the element at
the end of the animation. It defines the final configuration of the element, often different from the
start state, that will be achieved after the animation completes.
animation-direction: normal|reverse|alternate|alternate-
reverse|initial|inherit;
Value Description
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit
Eg: div {
animation-direction: alternate;
}
27. Write the syntax of animation property shorthand form
Value Description
transition-property Specifies the name of the CSS property the transition effect is for
transition-duration Specifies how many seconds or milliseconds the transition effect takes to complete
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit
This property allows a transition effect to change speed over its duration.
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit
4m:
Properties: CSS properties define the visual characteristics of the selected elements. They
specify attributes like color, size, position, and more. Properties are assigned values that
control the appearance of the elements.
Values: Values are assigned to CSS properties and determine the specific behavior or
appearance of the selected elements. For example, a color property can have values like
"red," "#FF0000," or "rgb(255, 0, 0)."
Declarations: Declarations consist of a property and its corresponding value, enclosed within
curly braces. Multiple declarations can be combined to form a CSS rule.
• Declaration Block. The code following the selector includes all the formatting options you want to
apply to the selector. The block begins with an opening brace ({) and ends with a closing brace (}).
Comments: Comments in CSS are used to add explanatory notes within the style sheet. They are
ignored by the browser and are intended for developers to provide information or disable certain
styles temporarily. CSS comments are denoted by /* comment text */.
Eg: h1 {
color: red;
an external style sheet, you can change the look of an entire website by
changing just one file!. Each HTML page must include a reference to the
external style sheet file inside the <link> element, inside the head section
mystyle.css
body {
background-color: blue;
}
h1 {
color: red;
margin-left: 20px;
}
internal style sheet may be used if one single HTML page has a unique
style. The internal style is defined inside the <style> element, inside the
head section.
An inline style may be used to apply a unique style for a single element.To
use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.
6. Explain the relationships between HTML tags with the help of a representative
diagram.
In HTML, elements are represented by tags, and their relationships
can be categorized into two main types: parent-child relationships
and sibling relationships.
1. Parent-child relationships:
- Parent element: A parent element is an HTML element that
contains one or more child elements. The parent element acts as a
container or wrapper for its child elements.
- Child element: A child element is an HTML element that is
nested inside a parent element. The child element inherits certain
properties and behaviors from its parent.
Example:
```html
<div> <!-- parent element -->
<h1>Heading</h1> <!-- child element -->
<p>Paragraph</p> <!-- child element -->
</div>
In this example, the `<div>` element is the parent element, and
both the `<h1>` and `<p>` elements are child elements of the `<div>`
element.
2. Sibling relationships:- Sibling elements: Sibling elements are
HTML elements that share the same parent. They are at the same
hierarchical level and appear next to each other.
Example:
<ul> <!-- parent element -->
<li>Item 1</li> <!-- sibling element -->
<li>Item 2</li> <!-- sibling element -->
<li>Item 3</li> <!-- sibling element -->
</ul>
```
In this example, the `<li>` elements are sibling elements because
they share the same parent `<ul>` element.
7. Explain the pseudo-classes used to style link
:link: This pseudo-class is used to style links that have not yet been visited.
:visited: This pseudo-class is used to style links that have been visited.
:hover: This pseudo-class is used to style links when the mouse pointer is
hovering over them.
:active: This pseudo-class is used to style links when they are being clicked.
:focus: This pseudo-class is used to style links when they have focus.
Syntax: selector:pseudo-class {
property: value;
}
Eg:
a:link {
color: blue;
}
a:visited {
color: purple;
}
a:hover {
color: red;
text-decoration: underline;
}
a:active {
color: green;
text-decoration: none;
}
8. Explain :focus, :before, :after ::selection pseudo-classes?
:focus: This pseudo-class is used to style elements when they have focus.
Focus is when an element has the input focus, such as when a user is typing
in a text field or clicking on a button.
:before: This pseudo-class is used to insert content before an element. The
content can be anything, such as text, images, or even other elements.
:after: This pseudo-class is used to insert content after an element. The
content can be anything, such as text, images, or even other elements.
::selection: This pseudo-element is used to style the selected text in an
element. The selected text is the text that is highlighted when a user selects it
with the mouse or keyboard.
Eg:
input:focus {
background-color: yellow;
outline: none;
}
p::before {
color: white;
}
9. Explain attribute selectors with example code.
[attribute]: This selector selects all elements that have the specified attribute.
[attribute=value]: This selector selects all elements that have the specified
attribute with the specified value.
[attribute~=value]: This selector selects all elements that have the specified
attribute with a value that contains the specified value.
[attribute^=value]: This selector selects all elements that have the specified
attribute with a value that starts with the specified value.
[attribute*=value]: This selector selects all elements that have the specified
attribute with a value that contains the specified value, even if the value is not
at the beginning or end of the attribute value.
Eg:
a[target] {
background-color: yellow;
}
a[target="_blank"] {
background-color: yellow;
}
[title~="flower"] {
border: 5px solid yellow;
}
[class^="top"] {
background: yellow;
}
[class*="te"] {
background: yellow;
}
10. Explain child selectors with code example.
child selectors are used to select elements that are children of other elements. They are very
useful for styling elements that are related to each other in the DOM tree.
Eg: p > span {
color: red;
}
:first-of-type
Works just like :first-child but applies to a child that has a particular tag. For
example, say you have a sidebar element with the class sidebar. To style the first
paragraph in that sidebar, use this selector eg:
.sidebar p:first-of-type
that’s peppered with photos. The <img> tag is an inline tag, so you can have a <p>
tag with a bunch of <image> tags inside it. And say you want to alternately float the
images left and right, You can do so with these two styles:
img:nth-of-type(odd) { float: left; }
img:nth-of-type(even) { float: right; }
1
The @font-face directive is a CSS at-rule that specifies a custom font with
which to display text. The font can be loaded from either a remote server or
a locally-installed font on the user's own computer.
@font-face {
font-family: font-name;
src: url(font-file);
font-weight: font-weight;
font-style: font-style;
}
The font-family property specifies the name of the font. The src property
specifies the URL of the font file. The font-weight property specifies the
weight of the font. The font-style property specifies the style of the font.
Code snippet
@font-face {
font-family: "MyFont";
src: url("myfont.ttf");
font-weight: bold;
font-style: italic;
}
h1 {
font-family: "MyFont";
}
13. Explain filters used in searching google web fonts
Font family: This filter allows you to search for fonts by their family name. For
example, you could search for "Roboto" or "Open Sans".
Font weight: This filter allows you to search for fonts by their weight. For example,
you could search for "bold" or "italic".
Font style: This filter allows you to search for fonts by their style. For example, you
could search for "sans-serif" or "serif".
Language: This filter allows you to search for fonts that support a specific language.
For example, you could search for fonts that support "English" or "Spanish".
License: This filter allows you to search for fonts that are available under a specific
license. For example, you could search for fonts that are available under the "SIL
Open Font License" or the "Apache License".
Popularity: This filter allows you to sort the results by popularity. The most popular
fonts will be displayed at the top of the results.
Newest: This filter allows you to sort the results by the date they were added to
Google Web Fonts. The newest fonts will be displayed at the top of the results.
14. Explain the different possible ways to set color property value with proper examples
When setting the color property in CSS, there are several ways to specify the color value.
Here are the different possible ways with examples:
1. Named Colors:- You can use predefined color names to set the color.
- Example:
p{
color: red; }
span {
color: rgb(0, 128, 0); /* Dark green */ }
4. RGBA Values:- RGBA (Red, Green, Blue, Alpha) values are similar to RGB, but with an
additional alpha channel specifying the transparency level (0.0 to 1.0).
- Example:
div {
color: rgba(255, 0, 0, 0.5); /* Semi-transparent red */ }
5. HSL Values: - HSL (Hue, Saturation, Lightness) values represent colors using the hue angle
(0 to 360), saturation (0% to 100%), and lightness (0% to 100%).
- Example:
a{
color: hsl(240, 100%, 50%); /* Blue */}
6. HSLA Values: - HSLA (Hue, Saturation, Lightness, Alpha) values are similar to HSL but
include an alpha channel for transparency.
- Example:
button {
color: hsla(60, 100%, 50%, 0.8); /* Semi-transparent yellow */ }
15. Explain different ways to set font-size property value.
When setting the `font-size` property in CSS, there are several ways to specify the font size
value. Here are the different possible ways with examples:
1. Absolute Units:- You can use absolute units to set an exact font size. Commonly used
absolute units are:
- `px` (pixels): The font size is specified in pixels.
3. Percentage Values: - Font sizes can be specified as a percentage relative to the parent
element's font size. A value of 100% is equivalent to the parent's font size.
- Example:
span {
font-size: 150%;
}
4. Keywords: - CSS also provides keywords to set common font sizes, such as `small`,
`medium`, `large`, `x-large`, `xx-large`, and more.
- Example:
h2 {
font-size: large;
}
5. Viewport-Percentage Lengths: - CSS3 introduced viewport-percentage lengths that allow
you to set font sizes relative to the viewport size. These units are similar to relative units but
are based on the viewport dimensions rather than the parent element.
- Example:
h3 {
font-size: 3vw; }
16. Explain the styling of lists using CSS.
CSS can be used to style lists in a variety of ways. Here are some of the most common
properties used to style lists:
list-style-type: This property specifies the type of list marker that will be used. The
possible values for this property are:
o disc (the default)
o circle
o square
o decimal
o decimal-leading-zero
o lower-roman
o upper-roman
o lower-alpha
o upper-alpha
o none
list-style-position: This property specifies the position of the list marker. The possible
values for this property are:
o outside (the default)
o inside
list-style-position: outside;
list-style-image: url("my-image.png");
list-style-padding: 5px;
list-style-margin: 0;
}
In CSS, the term "box model" is used when talking about design and
layout.The CSS box model is essentially a box that wraps around every HTML
element. It consists of: margins, borders, padding, and the actual content.
The image below illustrates the box model:
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is
transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is transparent
The CSS box model is used to control the size and layout of HTML elements.
The properties that make up the box model are:
border: This property specifies the style, color, and width of the
border.
Here is an example of how to use the box model to style an HTML element:
div {
width: 200px;
height: 100px;
padding: 10px;
margin: 10px;}
The CSS border properties allow you to specify the style, width, and color
of an element's border.
1. `border-width`: - Use the `border-width` property to set the width of
each border side.
- Example:
div {
- Example:
div {
- Example:
div {
- Example:
div {
You can also use the border-top, border-right, border-bottom, and border-
left properties to format individual borders.
Eg:div {
In CSS, there are several ways to create rounded corners for elements. Here
are different approaches with corresponding code examples:
Example:
div {
border-radius: 10px;}
This example sets a border radius of 10 pixels for all four corners.
Eg:div {
This example sets a border radius of 10 pixels for the top-left corner, 20
pixels for the top-right corner, 15 pixels for the bottom-right corner, and 5
pixels for the bottom-left corner.
Example:
div {
border-top-left-radius: 10px;
border-top-right-radius: 20px;
border-bottom-right-radius: 15px;
border-bottom-left-radius: 5px;
}
20. Explain different options for box-sizing property in CSS3.
the box-sizing property allows us to include the padding and border in an
element's total width and height.
content-box: This is the default value. The width and height of the element will only
include the content, and the padding and border will be added to the final rendered
width and height.
border-box: The width and height of the element will include the content, padding,
and border. This is the most common value for the box-sizing property.
padding-box: The width and height of the element will include the content and
padding. This is less common than the border-box value, but it can be useful for
some layouts.
Eg: div {
box-sizing: content-box;//borderbox//paddingbox
}
21. Explain overflow property of CSS3 with all of its options.
eg: div {
width: 200px;
height: 65px;
background-color: coral;
overflow: visible;
}
div {
overflow: hidden;//scroll//auto
}
div {
overflow-x: hidden; /* Hide horizontal scrollbar */
overflow-y: scroll; /* Add vertical scrollbar */
}
The clear property specifies what should happen with the element that is
next to a floating element.
clear: none|left|right|both|initial|inherit;
Value Description
none Default. The element is not pushed below left or right floated elements
both The element is pushed below both left and right floated elements
Eg: div {
clear: both;//left,right,none
CSS animations allow you to create simple animations on web pages using
CSS. They are a powerful tool that can be used to create a variety of effects,
such as sliding images, rotating text, and bouncing buttons.
When the animation is created in the @keyframe rule, it must be bound with selector;
otherwise the animation will have no effect.
The animation could be bound to the selector by specifying at least these two
properties:
.animated-div {
width: 200px;
height: 200px;
background-color: red;
animation-name: color-change;
animation-duration: 3s;
animation-timing-function: linear;
animation-iteration-count: infinite;
@keyframes color-change {
0% {
background-color: red;
}
100% {
background-color: red;
1. none:
The element's styles are not affected by the animation before or after it is executed.
2. forwards:
The element retains the styles applied to it by the last keyframe of the animation
after the animation ends.
3. backwards:
The element applies the styles defined in the first keyframe of the animation before
the animation starts, even if it hasn't started yet.
This allows the element to have the initial state of the animation applied to it.
4. both:
The element applies both the styles defined in the first keyframe (backwards) and
the styles defined in the last keyframe (forwards).
The element retains the styles applied by the last keyframe of the animation after
the animation ends.
The animation-fill-mode property is particularly useful when dealing with animations that have a
delay or iteration count. It allows you to control how the element is styled before the animation
starts and after it ends, ensuring smooth transitions and desired effects.