Unit 2 CSS
Unit 2 CSS
Chaithra N Page 1
BSC Solved QB UNIT 2
There are many XML parsers that checks the document and its DTD. XML
elements XML documents are composed of three things i.e., elements, control
information, and entities. Most of the markup in an XML document is element
markup. Elements are surrounded by tags much as they are in HTML. Each
document has a single root element which contains all of the other markup.
Nesting tags: Even the simplest XML document has nested tags. Unlike HTML
these must be properly nested and closed in the reverse of the order in which
they were opened. Each XML tag has to have a closing tag, again unlike
HTML.
Case Sensitive: XML is case sensitive and you must use lower case for your
markup.
Empty tags: Some tags are empty, they don’t have content. Where the content
of the tag is missing, it appears as <content/>
Attributes: Sometimes it is important that elements have information associated
with them without that information becoming a separate element.
Control Information:
There are three types of control information
Comments
processing instructions
document type declaration.
Comments: XML comments are exactly same as HTML. They take the form as
<!- -comment text - ->
Processing Instructions: Processing Instructions are used to control applications.
One
of the processing instructions is <?xml version=”1.0”>
Document Type Declarations: Each XML document has an associated DTD.
The DTD is usually present in separate file, so that it can be used by many files.
The statement that includes DTD in XML file is <?DOCTYPEcust SYSTEM
“customer.dtd”>.
Entities
Entities are used to create small pieces of data which you want to use repeatedly
throughout your schema
Example:
<?xml version="l.0"?>
<recipes>
<category type="loaf">
<name>Basic Farmhouse</name>
<ingredient></ingredient >
<cooking>
<time></time>
<setting></setting>
</cooking>
<serves></serves>
<instructions>
Chaithra N Page 2
BSC Solved QB UNIT 2
<item></item>
</instructions>
</category>
</recipes>
<?xml version="l.0"?> This is a Processing Instruction which tells
applications how to handle the XML. In this case it also serves as a
version declaration and says that the file is XML which should adhere to
the rules for XML version 1.0.
The rules state that the parser must halt when it finds an error and that it
may return a message back to the calling application.
If we change <serves></serves>
into
<serves></servs>
and run the file through the browser once more. It gives an error
Chaithra N Page 3
BSC Solved QB UNIT 2
b) Attributes: Attributes are important and useful when you are handling
complexity. Some XML elements need to hold more than one piece of
Chaithra N Page 4
BSC Solved QB UNIT 2
Chaithra N Page 5
BSC Solved QB UNIT 2
<body>
<h1> Student Database </h1>
<xsl:for-each select = “college”>
<xsl:for-each select = “studetail”>
<xsl:value-of select = “regno”/>
<xsl:for-each select = “name”>
<xsl:value-of select = “firstname”/>
<xsl:value-of select = “lastname”/>
</xsl:for-each>
<xsl:value-of select=”country/@name” />
<xsl:value-of select = “branch”/>
</xsl:for-each>
</xsl:for-each>
</body>
</xsl:template>
</xsl:stylesheet>
Internal DTD
A DTD is referred to as an internal DTD if elements are declared within the
XML files. To reference it as internal DTD, standalone attribute in XML
declaration must be set to yes. This means the declaration works independent of
external source.
Syntax
The syntax of internal DTD is as shown −
<!DOCTYPE root-element [element-declarations]>
where root-element is the name of root element and element-declarations is
where you declare the elements.
Example:
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<!DOCTYPE address [
<!ELEMENT address (name,company,phone)>
Chaithra N Page 7
BSC Solved QB UNIT 2
Chaithra N Page 8
BSC Solved QB UNIT 2
type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="item"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
This schema defines a namespace for its elements. Elements and some
attributes, those which define data types, all exist in that namespace. XML
elements are defined within XML Schema as being either simple types or
complex types. A complex type contains other elements or has attributes.
A simple type defines an element which is a container for data. Within a
complex type
the individual components form a sequence which must be defined in the
schema document.
Chaithra N Page 10
BSC Solved QB UNIT 2
Microsoft Windows where all developers use a standard set of libraries which
contain the Windows code. Anyone can write an XML parser in any language.
HTML documents can also be viewed as XML documents and accessed through
a DOM structure. Languages such as JavaScript can easily be used within Web
clients to manipulate the components of a Webpage.
8. What are the four values used in the CSS3 text-shadow property?
The CSS3 text-shadow property makes it easy to add a text shadow effect to any
text. First we add a text-shadow property to our styles (line 12). The property
has four values: -4px, 4px, 6px and DimGrey, which represent:
• Horizontal offset of the shadow—the number of pixels that the text-shadow
will appear to the left or the right of the text. In this example, the horizontal
offset of the shadow is -4px. A negative value moves the text-shadow to the
left; a positive value moves it to the right.
• Vertical offset of the shadow—the number of pixels that the text-shadow will
be shifted up or down from the text. In this example, the vertical offset of the
shadow is 4px. A negative value moves the shadow up, whereas a positive value
moves it down.
• blur radius—the blur (in pixels) of the shadow. A blur-radius of 0px would
result in a shadow with a sharp edge (no blur). The greater the value, the greater
the blurring of the edges. We used a blur radius of 6px.
• color—determines the color of the text-shadow. We used dimgrey.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px 8px #FF0000;
}
</style>
Chaithra N Page 11
BSC Solved QB UNIT 2
</head>
<body>
<h1>Text-shadow with blur effect</h1>
</body>
</html>
Chaithra N Page 12
BSC Solved QB UNIT 2
h2
{
text-align: center;
}
</style>
</head>
<body>
<div><h2>Box Shadow Bottom and Right</h2></div>
<div id = "box2"><h2>Box Shadow Top and Left</h2></div>
</body>
</html>
we create a style that’s applied only to the second div, which changes the box-
shadow’s horizontal offset to -25px and vertical offset to -25px (line 25) to
show the effects of using negative values. A negative horizontal offset value
moves the box shadow to the left. A negative vertical offset value moves the
shadow up.
10.What are linear gradients in CSS, and how are they created?
Linear gradients are a type of image that gradually transitions from one color to
the next horizontally, vertically or diagonally. To create a linear gradient you
must define at least two color stops. Color stops are the colors you want to
render smooth transitions among.
we create three linear gradients—vertical, horizontal and diagonal—in separate
rectangles.
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 200px;
background-color: red; /* For browsers that do not support gradients */
background-image: linear-gradient(red, yellow);
}
</style>
</head>
<body>
<div id="grad1"></div>
</body>
</html>
The background property for each of the three linear gradient styles (vertical,
horizontal and diagonal) is defined multiple times in each style—once for
WebKit-based browsers, once for Mozilla Firefox and once using the standard
CSS3 syntax for linear gradients.
Example:
div
{
width: 200px;
height: 200px;
border: 3px solid navy;
padding: 5px 20px;
text-align: center;
background: -webkit-gradient(
linear, center top, center bottom,color-stop(15%, white), color-stop(50%,
lightsteelblue),color-stop(75%, navy) );
background: -moz-linear-gradient(
top center, white 15%, lightsteelblue 50%, navy 75% );
background: linear-gradient(
to bottom, white 15%, lightsteelblue 50%, navy 75% );
float: left;
margin-right: 15px;
}
11.What is the purpose of radial gradients in CSS, and how do they differ from
linear gradients?
Radial gradients are similar to linear gradients, but the color changes gradually
from an inner point (the start) to an outer circle (the end). CSS gradients are
often used to simulate a light source, which we know isn't always straight.
Radial gradient property has three values. The first is the position of the start of
the radial gradient—in this case, the center of the rectangle. Other possible
values for the position include top, bottom, left and right. The second value is
the start color (yellow), and the third is the end color (red). The resulting effect
is a box with a yellow center that gradually changes to red in a circle around the
starting position.
<!DOCTYPE html>
Chaithra N Page 14
BSC Solved QB UNIT 2
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
background-color: red; /* For browsers that do not support gradients */
background-image: radial-gradient(red 5%, yellow 15%, green 60%);
}
</style>
</head>
<body>
<h1>Radial Gradient - Differently Spaced Color Stops</h1>
<div id="grad1"></div>
</body>
</html>
Other than the vendor prefixes, the syntax of the gradient is identical for
WebKit browsers, Mozilla and the standard CSS3 radial-gradient.
div
{
width: 200px;
height: 200px;
padding: 5px;
text-align: center;
background: -webkit-radial-gradient(center, yellow, red);
background: -moz-radial-gradient(center, yellow, red);
background: radial-gradient(center, yellow, red);
}
Chaithra N Page 15
BSC Solved QB UNIT 2
image into nineregions: four corners, four sides and a middle, which is
transparent unless otherwise specified.
border-image-repeat: specifies how the regions of the border image are
scaledand tiled (repeated). By indicating stretch just once, we create a border
that willstretch the top, right, bottom and left regions to fit the area.
Repeating an Image Border
border-image-source—the URL of the image to use in the border (once
again,url(border.png)).
border-image-slice—in this case, we provided two values expressed in
percentages(34% 34%) for the top/bottom and left/right, respectively.
border-image-repeat—the value repeat specifies that the tiles are repeated
tofit the area, using partial tiles to fill the excess space.
Chaithra N Page 16
BSC Solved QB UNIT 2
run. The default is 1. You may use the value infinite to repeat the animation
continuously.
animation-direction—specifies the direction in which the animation will run.
The value alternate used here specifies that the animation will run in
alternating directions—in this case, counterclockwise (as we define with our
keyframes), then clockwise. The default value, normal, would run the
animation in the same direction for each cycle.
The shorthand animation property cannot be used with the animation-play-state
property—it must be specified separately. If you do not include the animation-
playstate, which specifies whether the animation is paused or running, it
defaults to running.
@keyframes Rule and Selectors
For the element being animated, the @keyframes rule defines the element’s
properties that will change during the animation, the values to which those
animation-name: movingImage;
animation-timing-function: linear;
animation-duration: 10s;
animation-delay: 1s;
animation-iteration-count: 2;
animation-direction: alternate;
14.What are CSS3 transitions and transformations, and how do they differ from
animations? Explain.
Transformations in CSS3 allow elements to be manipulated in terms of their
size, position, and rotation. This is done using the transform property.
Transformations can be 2D or 3D. Common transformation functions
include:
translate(): Moves an element from its current position.
scale(): Changes the size of an element.
rotate(): Rotates an element around a fixed point.
skew(): Skews an element along the X or Y axis.
Chaithra N Page 17
BSC Solved QB UNIT 2
Transitions need a trigger to The animation just start. They don’t need
run like mouse hover. any kind of external trigger source.
Chaithra N Page 18
BSC Solved QB UNIT 2
16.How does the Flexible Box Layout Module (FBLM) facilitate the creation of
flexible divs in CSS?
Flexible Box Layout Module (FBLM) makes it easy to align the contents of
boxes, change their size, change their order dynamically, and lay out the
contents in any direction.
There are 2 main components of the Flexbox:
Flex Container: The parent “div” which contains various divisions is called a
flex container.
Flex Items: The items inside the container “div” are flex items.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Flexbox Tutorial</title>
<style>
.flex-container {
display: flex;
background-color: #32a852;
}
.flex-container div {
background-color: #c9d1cb;
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<h2>GeeksforGeeks</h2>
<h4> Flexbox</h4>
<div class="flex-container">
<div>Item1</div>
<div>Item2</div>
<div>Item3</div>
</div>
</body>
Chaithra N Page 19
BSC Solved QB UNIT 2
</html>
Here, rule applies to all <h1> elements and indicates that they should appear
in the Arial typeface.
The declaration is also split into two parts, separated by a colon:
❑ A property, which is the property of the selected element(s) that you want
to affect, in this case it is the font-family property.
❑ A value, which is a specification for this property; in this case it is the
Arial typeface.
Here is an example of a CSS rule that applies to several elements (in this
example the <h1>, <h2>, and <h3> elements): a comma separates the name
of each element that this rule will apply to. The rule also specifies several
properties for these elements with each rule separated by a semicolon.
h1, h2, h3 {
color:#000000;
background-color:#FFFFFF;
font-family:arial, verdana, sans-serif;
font-weight:bold;}
Chaithra N Page 20
BSC Solved QB UNIT 2
18. Explain the basic syntax of CSS and how it is applied to HTML documents.
A CSS rule consists of a selector and a declaration block.
When the style sheet rules are held inside a <style> element in the head of
the document, they are referred to as an internal style sheet.
<head>
<title>Internal Style sheet</title>
<style type="text/css">
body {
color:#000000;
background-color:#ffffff;
}
h1 {font-size:18pt;}
p {font-size:12pt;}
</style>
</head>
When style attributes are used, they are known as inline style rules. For
example:
<td style="font-family:courier; padding:5px; border-style:solid;
border-width:1px; border-color:#000000;">
Here you can see that the properties are added within the style attribute. There is
no need for a selector here and there are no curly braces. But still need to
separate each property from its value using a colon and each of the property-
value pairs from each other using a semicolon.
19. What are the key attributes required for the <link> element when used to link
CSS style sheets to HTML documents?
Chaithra N Page 21
BSC Solved QB UNIT 2
The <link /> element can be used to create a link to CSS style sheets. The
<link/> element is always an empty element that describes the relationship
between two documents. It can be used in several ways, but when used with
style sheets the relationship indicates that the CSS document contains rules for
the presentation of the document containing the <link /> element.
The <link /> element is most commonly used for linking CSS style sheets to
documents. When used with style sheets, the <link /> element must carry three
attributes: type, rel, and href.
<link rel="stylesheet" type="text/css" href="../style sheets/interface.css" />
The rel attribute is required and specifies the relationship between the
document containing the link and the document being linked to.
The key value for working with style sheets is stylesheet.
rel="stylesheet"
The type Attribute
The type attribute specifies the MIME type of the document being linked to:
type="text/css"
The href Attribute
The href attribute specifies the URL for the document being linked to.
href="../stylesheets/interface.css"
The hreflang Attribute
The hreflang attribute specifies the language that the resource specified is
written in. Its value should be one of the language codes specified in Appendix
G.
hreflang="en-US"
The media Attribute
The media attribute specifies the output device that is intended for use with the
document:
media="screen"
Chaithra N Page 22
BSC Solved QB UNIT 2
5. font-style Specifies whether the font should be normal, italic, or oblique (an
oblique font is the normal font on a slant rather than a separate italic
6. version of the font)
7. font-stretch Allows you to control the width of the actual letters in a font
(not spaces between them)
8. font-variant Specifies whether the font should be normal or smallcaps
9. font-size-adjust Allows you to alter the aspect ratio of the size of characters
of the font
The font-family Property
The font-family property allows us to specify the typeface that should be used.
There is a big restriction with this property; the person viewing the page must
have this font on his or her computer, otherwise they will not see the page in
that font. We can, however, specify more than one font so that, if the user does
not have your first choice of font, the browser looks for the next font in the list
p.one {font-family:arial, verdana, sans-serif;}
Chaithra N Page 23
BSC Solved QB UNIT 2
Chaithra N Page 24
BSC Solved QB UNIT 2
The text-indent property allows you to specify how much the content of a
block-level element should be indented from the left side of the browser
window or the left side of its containing element.
Example:
<p>This paragraph should be aligned with the left-hand side of the browser.
</p>
<p class="indent">The content of this paragraph should be indented by 3 em.
</p>
Now, here is the rule that indents the second paragraph
.indent {text-indent:3em;}
Chaithra N Page 25
BSC Solved QB UNIT 2
you had a <p> element with a class attribute whose value was BackgroundNote,
like so:
<p class="BackgroundNote">This paragraph contains an aside.</p>
The ID Selector
The id selector works just like a class selector, but works on the value of id
attributes. But rather than using a period or full stop before the value of the id
attribute, you use a hash or pound sign (#). So, a <p> element with an id
attribute whose value is abstract could be identified with this selector.
p.#abstract
The Child Selector
The child selector matches an element that is a direct child of another. In this
case it matches any <b> elements that are direct children of <td> elements:
td > b {}
The Descendent Selector
The descendent selector matches an element type that is a descendent of another
specified element, at any level of nesting not just a direct child. In this case the
selector matches any <b> element that is a child of the <table> element, which
means it would apply to <b> elements both in <td> and <th> elements.
table b {}
Chaithra N Page 26
BSC Solved QB UNIT 2
Chaithra N Page 27
BSC Solved QB UNIT 2
In CSS, there are several properties related to color, each serving a specific
purpose in styling elements on a webpage. Here are the main color-related
properties:
color: This property sets the color of the text content. It accepts
color values in various formats such as keyword, hexadecimal,
RGB, RGBA, HSL, or HSLA.
color: blue;
background-color: This property sets the background color of an
element. It works similarly to the color property, accepting various
color value formats.
background-color: #f0f0f0;
border-color: This property sets the color of an element's border.
Like background-color, it accepts various color value formats.
border-color: red;
outline-color: This property sets the color of an element's outline,
which is a line drawn around the outside of an element. It behaves
similarly to border-color.
outline-color: green;
box-shadow: While not directly a color property, box-shadow
allows you to create a shadow effect around an element. It includes
a parameter for specifying the color of the shadow.
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.5);
text-shadow: Similar to box-shadow, text-shadow creates a
shadow effect around text. It also includes a parameter for
specifying the color of the shadow.
text-shadow: 2px 2px 2px #888888;
Chaithra N Page 29
BSC Solved QB UNIT 2
Chaithra N Page 30
BSC Solved QB UNIT 2
wraps underneath the bullet point or in line with the position of the
first line of text. There are two values for this property, as you can see
in the table that follows.
2. width : Sets the width of the table. By setting it to `100%`, the table spans
the entire width of its containing element.
2. border: This property sets the border of elements. In this case, it's applied
to table headers (`th`) and table data cells (`td`). It includes the border
width, style, and color.
4. padding: Adds space between the content of an element and its border. It's
particularly useful for improving readability and aesthetics.
Chaithra N Page 31
BSC Solved QB UNIT 2
8. height: Sets the height of table headers (`th`) and data cells (`td`). In this
example, it's set to a fixed value, but it can also be set to `auto` or a
percentage value.
9. border-bottom: This property specifies the style, width, and color of the
bottom border of table headers (`th`). It's a way to differentiate header cells
visually.
10. :hover: This is a pseudo-class that applies styles to an element when it's
being hovered over by the cursor. Here, it's used to change the background
color of table rows (`tr`) when hovered, enhancing interactivity and visual
feedback for users.
These CSS properties, when used together, allow for comprehensive styling
of tables, enabling designers to create visually appealing and user-friendly
table layouts.
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
tr:hover {
background-color: #f5f5f5;
}
</style>
Chaithra N Page 32
BSC Solved QB UNIT 2
Chaithra N Page 33
BSC Solved QB UNIT 2
- Useful for elements like navigation bars or banners that you want to
remain visible at all times.
<style>
/* Common styles */
.box {
width: 100px;
height: 100px;
background-color: #3498db;
color: white;
text-align: center;
line-height: 100px;
margin: 10px;
}
/* Static */
.static {
position: static;
}
/* Relative */
.relative {
position: relative;
left: 20px;
top: 20px;
}
/* Absolute */
.absolute {
position: absolute;
right: 20px;
bottom: 20px;
}
/* Fixed */
.fixed {
position: fixed;
right: 20px;
bottom: 20px;
}
<style>
5. The z-index Property
Absolutely positioned elements have a tendency to overlap other
elements. When this happens the default behavior is to have the first
elements underneath later ones. This is known as stacking context. If you
Chaithra N Page 34
BSC Solved QB UNIT 2
have boxes that are absolutely positioned, you can control which of the
absolutely positioned boxes appears on top using the z-index property to
alter the stacking context.
/* Floating boxes */
.float-left {
float: left;
}
.float-right {
float: right;
}
/* Z-index */
.z-index-1 {
position: relative;
z-index: 1;
}
.z-index-2 {
position: relative;
z-index: 2;
}
</style>
***********************************************************
Chaithra N Page 35