Lo1 Web Page Creations Using Css and HTML
Lo1 Web Page Creations Using Css and HTML
CSS Introduction
Style elements of a web page
Page layout creation with CSS
Positioning document elements with CSS
Style sheets application on multiple pages on a website
Web pages creation for varied screen resolutions
Application layering for the Desired Design
This unit will also assist you to attain the learning outcomes stated in the cover page.
Specifically, upon completion of this learning guide, you will be able to:
Understand the fundamentals of CSS and essential design principles
Understand how to gather user preferences and requirements for effective styling
Apply learned principles to develop CSS that aligns with user preferences
follow principles of layout design using CSS
apply methods of positioning and arrange document elements
explain concept of style sheets and their application across multiple pages
solve challenges of designing for different screen sizes
Explore techniques for handling browser-specific styling challenges
Emphasize the importance of adhering to industry standards in CSS
Address browser-specific differences to enhance website accessibility
Page | 1
CSS Introduction
CSS is the language we use to style a Web page.
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
Page | 2
The declaration block contains one or more declarations separated by semicolons.
Each declaration includes a CSS property name and a value, separated by a colon.
Property − A property is a type of attribute of HTML tag.
Put simply, all the HTML attributes are converted into CSS properties.
For example, color property can have value either red or #F1F1F1 etc.
<html>
<head>
Page | 3
</head>
<body>
</h1>
</body>
</html>
<html>
<head>
</style>
</head>
<body>
</body>
</html>
Page | 4
C) External CSS - The <link> Element
An external style sheet is a separate text file with .css extension. You define all the Style rules
within this text file and then you can include this file in any HTML document using <link>
element.
<head>
</head>
<head>
@import "URL";
@import url("URL");
</head>
So, it will override any rule defined in <style>...</style> tags or rules defined in any external
Page | 5
Any rule defined in <style>...</style> tags will override rules defined in any external style sheet
file.
Any rule defined in external style sheet file takes lowest priority, and rules defined in this file
will be applied only when above two rules are not applicable.
CSS Comments
Many times, you may need to put additional comments in your stylesheet blocks. So, it is very
You can simple put your comments inside /*.....this is a comment in style sheet.....*/.
/* This is a
multi-line
comment */
Page | 6
The Type Selectors
The Element Selectors
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text
color:
p {
text-align: center;
color: red;
}
The ID Selectors
You can define style rules based on the id attribute of the elements. All the elements having
All the elements having that class will be formatted according to the defined rule.
Grouping Selectors
The grouping selector selects all the HTML elements with the same style definitions.
Example
In this example we have grouped the selectors from the code above:
Page | 7
h1, h2, p {
text-align: center;
color: red;
}
The Universal Selectors
Is used to select and apply styles to all elements on a web page.
* { color: #000000; }
particular element.
ul em {color: #000000;}
element.
Page | 8
CSS – Colors
CSS uses color values to specify a color. Typically, these are used to set a color either for the
foreground of an element (i.e. its text) or else for the background of the element. They can also
Named Colors
A CSS named color is the name of a color, such as red, blue, black, or light-green.
value, the next two are a green value (GG), and the last are the blue value (BB).
Each hexadecimal code will be preceded by a pound or hash sign '#'. Following are the examples
of hexadecimal notation.
RGB Values
This color value is specified using the rgb( ) property.
It takes three values, one each for red, green, and blue.
Color:RGB(20,50,255)
Page | 9
HSL Values
This color value is specified using the HSL() function.
Color:hsl(0,0%,50%)
CSS – Backgrounds
This section teaches you how to set backgrounds of various HTML elements. You can set the
background.
background.
background.
properties.
Page | 10
CSS – Fonts
The font-family property is used to change the face of a font.
The font-weight property is used to increase or decrease how bold or light a font appears.
The font property is used as shorthand to specify a number of other font properties.
HTML Forms
An HTML form is used to collect user input. The user input is most often sent to a server for
processingThe
<form> Element
The HTML <form> element is used to create an HTML form for user input:
<form>
/*
form elements
*/
</form>
The <form> element is a container for different types of input elements, such as: text fields,
An <input> element can be displayed in many ways, depending on the type attribute.
Page | 11
examples:
Type Description
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for selecting zero or more of many choices)
Text Fields
The <input type="text"> defines a single-line input field for text input.
Example
<html>
<body>
<form>
</form>
</body>
</html>
Page | 12
The <label> Element
Notice the use of the <label> element in the example above.
The <label> element is useful for screen-reader users, because the screen-reader will read out
loud the label when the user focuses on the input element.
Radio Buttons
The <input type="radio"> defines a radio button.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Radio Buttons</h2>
<form>
<label for="html">HTML</label><br>
<label for="css">CSS</label><br>
Page | 13
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
Checkboxes
The <input type="checkbox"> defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Checkboxes</h2>
<form action="/action_page.php">
Page | 14
</form>
</body>
</html>
Submit Button
The <input type="submit"> defines a button for submitting the form data to a form-
handler.
The form-handler is typically a file on the server with a script for processing input data.
Example
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
Page | 15
</body>
</html>
CSS – Units
Values and units, in CSS, are significant as they determine the size, proportions, and positioning
Example:
viewport.
2rem;
Page | 16
1% or 1/100 of the height of the viewport. 4vh;
smaller dimension.
The <div> element is by default a block element, meaning that it takes all available
Example
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<p>The yellow background is added to demonstrate the footprint of the DIV element.</p>
</body>
Page | 17
</html>
Example2
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<div>
<h2>London</h2>
</div>
<p>The yellow background is added to demonstrate the footprint of the DIV element.</p>
</body>
</html>
<style>
</style>
Page | 18
Multiple <div> elements
You can have many <div> containers on the same page.
There are different methods for aligning elements side by side, all include some CSS
Float: The CSS float property is used for positioning and formatting content and allow
Inline-block: If you change the <div> element's display property from block to inline-
block, the <div> elements will no longer add a line break before and after, and will be
Flex: The CSS Flexbox Layout Module was introduced to make it easier to design
To make the CSS flex method work, surround the <div> elements with
Grid: The CSS Grid Layout Module offers a grid-based layout system, with rows and
columns, making it easier to design web pages without having to use floats and
positioning.
Sounds almost the same as flex, but has the ability to define more than one row and
Page | 19
The CSS grid method requires that you surround the <div> elements with
another <div> element and give the status as a grid container, and you must specify the
Example
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<form action="/action_page.php">
<fieldset>
<legend>Personal-info:</legend>
Page | 20
<input type="text" id="fname" name="fname"><br><br>
<label for="email">Email:</label>
<label for="birthday">Birthday:</label>
</fieldset>
</form>
</body>
</html>
Output:
Page | 21
CSS – Text
A text refers to a piece of written or printed information in the form of words or characters that
can be read and understood. Texts can include content such as books, articles, emails, messages,
Text Color
Altering the color of the text can add visual interest or align with a specific design scheme.
The CSS color property is used to set the color of the text. The possible values for this property
are as follows:
Text Alignment
The position or placement of text on a page is called its alignment. The text is aligned based on
Text Direction
Page | 22
Text direction refers to the orientation of text characters within a document or element. It
determines whether text should be displayed from left to right (LTR) or right to left (RTL) based
Text Decoration
The CSS text-decoration property helps in adding extra decoration to the text, such as, adding a
line (underline, strikethrough, overline) and color, style and thickness to the line.
overline).
Text-decoration-style: Sets the style to the text decoration (dotted, dashed, solid,
Text Emphasis
CSS provides a property to apply emphasis marks on a block of text using the property text-
emphasis.
These marks are typically used to highlight specific content or to indicate pronunciation or stress
in certain languages.
It allows the designer to apply emphasis to individual characters or phrase within a block of text.
Page | 23
Text Indentation
Indentation is the space between the margin and the first line of text. Proper indentation enhances
CSS also provides a property to set the text indentation and that is text-indent. The following
Length: Any specific length {pixels (px), points (pt), ems (em), etc}. Default value is 0.
Percentage (%): The value passed is in relation to the percentage of the width of the
parent element.
Each-line: Affects the first line of a block of text along with each line after a forced line
break.
Inherit: Allows to inherit the text-indent value from its parent element.
Following are the possible values that this property can have:
Normal: Default value and represents the normal amount of space between letters.
Length: Any specific length {pixels (px), points (pt), ems (em), or percentages (%)}.
Inherit: Allows to inherit the letter-spacing value from its parent element.
Page | 24
Text Word Spacing
CSS provides property to adjust the spacing between the words in a piece of text, just like letter
Normal: Default value and represents the normal amount of space between words.
Length: Any specific length {pixels (px), points (pt), ems (em), or percentages (%)}.
Inherit: Allows to inherit the word-spacing value from its parent element.
Text Shadow
The text-shadow property is used to add a shadow effect to text. It allows you to specify the
color, offset, blur-radius, and spread-radius of the shadow. Following is the syntax of text-
shadow:
text.
Page | 25
Images
Images play an important role in any webpage. Though it is not recommended to include a lot of
CSS plays a good role to control image display. You can set the following image properties
using CSS.
Links
In web development, a "link" generally refers to an HTML element that allows the user to
navigate from one web page to another or to another resource, such as a style sheet, an image, or
a script. The HTML <a> (anchor) element is the most common way to create links.
The :hover signifies an element that currently has the user's mouse pointer hovering over it.
Usually, all these properties are kept in the header part of the HTML document.
Remember a:hover MUST come after a:link and a:visited in the CSS definition in order to be
Tables
Page | 26
A table is an HTML element used to display data in a structured format with rows and columns.
It is created using the <table> tag in HTML and can be styled using CSS properties.
Following is a simple HTML table which has been styled using CSS :
<html>
<head>
<style>
100%;}
tr:nth-child(even){background-color: #f2f2f2;}
</style>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Address</th>
Page | 27
<th>Country</th>
</tr>
<tr>
<td>Nuha Ali</td>
<td>India</td>
</tr>
<tr>
<td>Zara Ali</td>
<td>Students Roosters</td>
<td>England</td>
</tr>
</table>
</body>
</html>
Properties of a Table
You can set the following CSS properties of a table
The border-collapse specifies whether the browser should control the appearance of the
adjacent borders that touch each other or whether each cell should maintain its style.
The border-spacing specifies the width that should appear between table cells.
The caption-side specifies where the table caption should be displayed (top or bottom).
Page | 28
The empty-cells specifies whether the border should be shown if a cell is empty.
The table-layout allows browsers to speed up layout of a table by using the first width
properties it comes across for the rest of a column rather than having to load the whole table
The width and height properties set the height and width of a table.
The text-align property sets the horizontal alignment of the text content within table cells.
The border property can be used to set border to table and its cells.
The background-color property can be applied to the table itself, the table cells, or table
rows.
The font-size, font-family, font-weight, font-color etc style the table font.
The property border-collapse ensures that borders between table cells collapse into a single
border, creating a cleaner look. Property border-collapse can have values collapse or separate
(default).
Borders
The border of an HTML element is simply one or more lines that surround the content and
padding of an element. Every border has three aspects: its width, or thickness; its style, or
The CSS border properties allow you to specify how the border of the box representing an
border-style - Specifies whether a border should be solid, dashed line, double line, or one of the
Page | 29
border-color - Specifies the color of a border. The default value is the foreground color of the
Example:
<p style="border-style: none;">No border.</p>
Rounded Borders
We can use border-radius property to add rounded borders to an element.
Syntax
Margins
The margin property is used to set the margin space around an element. Margins are the space
outside the border of an element. The margin property can be set for individual sides (top, right,
element.
Following example demonstrates how we can set different margins around h1 elements:
color: #eee;}
Page | 30
Margins - Set Three Values
We can set margin at three values as margin: 20px 40px 10px, in this case top margin will be
20px, right and left margins will be 40px and bottom margin will be 10px. Following is the
example. You should try to compare the output with previous example:
We have seen that setting a single value for margin, applies margin equally to all the sides - top,
right, bottom and left. You can check very first example to understand this case.
shorthand property.
Margins - Percentages
It is very much possible to set percentage values for the margins of an element. Percentage
margins values are computed in relation to the width of the parent element’s content area, so they
Page | 31
Margins - Inline Elements
Margins can also be applied to inline elements but top and bottom margins do not have
any effect on the line height of these nonreplaced elements and these margins are always
transparent.
example:
<style>
h1 {margin:0 auto;}
</style>
Lists
Lists are useful as they present the information in a structured and organized manner. Lists
improve the readability and comprehension of content on a web page. So, if the content is listed,
it is easy to follow.
Lists are commonly used to display items, steps, options, or any other type of related information
Ordered List
Ordered lists are used when the items need to be presented in a specific order marked with
<ol>
Page | 32
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>
Unordered List
Unordered lists are used when the items need to be presented in a specific order marked with
simple bullets.
The list-style-type allows you to control the shape or appearance of the list markers (bullet
points).
The list-style-image specifies an image for the marker rather than a bullet point or number.
The following example shows how CSS property list-style-type sets different markers for the
The same property can be used for both ordered and unordered lists.
You can check CSS property list-style-type detail to check all the possible marker's types for the
lists.
Page | 33
CSS Lists - Image Marker
You might prefer to use an image as an item list marker. The CSS list-style-image property can
You can use your own bullet style. If no image is found, then default bullets are printed.
ul {list-style-image: url('/images/icon-bullet.png');}
outside of the box containing the bullet points. It can have one of the following values −
none- No marker is displayed, and the list items are without any bullet points or numbers.
Inside- The marker is positioned inside the content flow, meaning it appears within the content
Outside- The default value. The marker is positioned outside the content flow, appearing to the
Inherit- is used to inherit the list-style-position value from its parent element.
<style>
</style>
Page | 34
Some time we might want to count differently on an ordered list — e.g., starting from a number
There are following three CSS attributes which helps in controlling the list numbering.
<start> - allows you to start the list counting from a number other than 1.
Example:
<html>
<body>
<h3>start attribute</h3>
<ol start="4">
<li>Java.</li>
<li>HTML.</li>
<li>CSS.</li>
<li>React.</li>
</ol>
<h3>reverse attribute</h3>
<ol reversed>
<li>Java.</li>
<li>HTML.</li>
<li>CSS.</li>
Page | 35
<li>React.</li>
</ol>
</body>
</html>
Lists - Colors
We can make lists look more stylish and colorful using CSS styling as demonstrated in the
following example. As we see any styling added to the <ul> or <ol> tag will affect the entire list,
whereas the addition to the individual <li> tag will affect only the items of the corresponding list.
Example:
Paddings
The CSS padding property is used to specify the space between the content of an element and its
borders. This article will teach you CSS padding property and its constituent properties.
The value of CSS padding should be either a length, a percentage, or the word inherit. A padding
property does not allow negative values. If the value is inherit, it will have the same padding as
Page | 36
Following example shows how different padding properties can be set around an h2 element.
background-color: #eee;
Cursor
The CSS cursor property determines the appearance of the mouse cursor when hovering over an
element to which this property is applied. This property is only applicable in environments with
mouse and cursor functionality. It's main purpose is to improve usability by visually representing
certain functions.
<url>: (optional) You have the flexibility to use a series of url() values separated by commas,
<x> <y>: (optional) You have the option to specify x and y coordinates that define the hotspot of
the cursor and specify the exact position within the cursor image that the cursor points to.
<Keyword>:A keyword value is required that specifies either the cursor type to use or the
Page | 37
default The default cursor, which varies depending on the
Outlines
CSS defines a special sort of element decoration called an outline which is drawn outside the
element's border. CSS outlines are very similar to borders, but there are few major differences as
well
Example: Following is rectangle having a black border of 5px and green outline of 30px.
This tutorial will teach us how to set different properties associated with outlines. CSS alows us
Outline Color
The outline-color property is used to specify the color of the outline. Its value should either be a
color name, a hex color, or an RGB value, as with the color and border-color properties.
Page | 38
RGB - Example rgb(255,0,0)
Example:
Outline Offset
The outline-offset property is used to specify the space between an outline and the border edge
of an element. The space between the outline and the element is transparent.
The following example show an outline 20px outside the border of the element:
The above example shows that the space between an element's border and its outline is
transparent.
Example:
Outline Vs Border
The two obvious differences are that outlines cannot have a hidden style where as a borders can
be hidden second an outline can have auto style whereas border can't have it. Following table
Outline Border
Page | 39
Outline is a non-rectangular shape Border is a rectangular shape that is drawn
that surrounds an element, usually around the content of an element, can be solid,
with a solid color. dashed, or dotted, and can have different colors
and sizes.
It does not take up any space in the It affects the size and position of the element,
layout and does not affect the size or as it adds width to the element.
The CSS box model is essentially a box that wraps around every HTML element. It consists of:
Page | 40
Height & Width (Dimension)
The dimensions of HTML elements is often specified with CSS width and height properties and
CSS also provides properties like max-width, min-width, max-height and min-height to set the
The height and width properties allow you to set the height and width of an element. These
length: The height and width of an element can be of any unit of length (px, pt, em, in, etc.)
percentage (%): The value can be passed as a percentage value, which is in percent of the
containing block.
auto: Browser calculates the height and width of the element. It is the default value.
initial: Sets the value of height and width to its default value.
inherit: The value of height and width is inherited from its parent value.
The height and width properties do not add anything to the layout of the element i.e they do not
include padding, margin or borders. They set the height and width of the area inside the padding,
Max-Height
CSS can limit the maximum height of an element using max-height property. This property
allows to specify maximum height of an element. The value of the max-height property can be:
length: Sets the maximum height in terms of length units (px, pt, em, in, etc.)
Page | 41
initial: Sets the value of height and width to its default value.
Min-height
CSS can limit the minimum height of an element using min-height property. This property
allows to specify minimum height of an element. It specifies the smallest height that an element
can have, ensuring that it will never shrink below that value. The value of the min-
length: Sets the minimum height in terms of length units (px, pt, em, in, etc.)
initial: Sets the value of height and width to its default value.
The minimum height will be applied, when the content is smaller than the minimum height. And
when the content is larger than the minimum height, the value of min-height has no effect on the
element.
Max-width
CSS can limit the maximum width of an element using max-width property. This property
allows to specify maximum width of an element. The value of the max-width property can be:
length: Sets the maximum width in terms of length units (px, pt, em, in, etc.)
initial: Sets the value of height and width to its default value.
Page | 42
The max-width value overrides the value of width property. If the content within the element is
larger than the specified max-width, it will automatically adjust the height of the element to
accommodate the content within the element. If the content within the element is smaller than the
Min-width
CSS can limit the minimum width of an element using min-width property. This property allows
to specify minimum width of an element. It specifies the smallest width that an element can
have, ensuring that it will never shrink below that value. The value of the min-width property can
be:
Length: Sets the minimum width in terms of length units (px, pt, em, in, etc.)
Initial: Sets the value of height and width to its default value.
If the content with the element is larger than the min-width, the min-width property has no effect
but if the content with the element is smaller than the specified min-width, the minimum width
will be applied.
Scrollbars
There may be a case when an element's content might be larger than the amount of space
allocated to it. For example, given width and height properties do not allow enough room to
Page | 43
Table: 2.3. Scrol1bar values
2 Hidden:The content of the nested element is simply cut off at the border of the
3 Scroll: The size of the containing element does not change, but the scrollbars
Display
Display:Inline
An element with a display property set to inline will not start on a new line and it will take up
the remaining/available screen width. It just takes up the space such an element would
normally take.Because of this, you can't set the width and height of an element that has a
display of inline, becuase it does not take up the whole screen width.
Some elements are inline by default, like <span>, <a>, <i>, and <img>.
Display: block
An element that has the display property set to block starts on a new line and takes up the
You can specify the width and height properties for such elements. Examples of elements
that are at block-level by default are <div>, <section>, <p>, and lots more.
It does not take up the full It takes up the full width It does not take up the full
It does not have a margin or It has a margin and It has a margin and padding
Following diagram shows the different layout behavior of inline, block, and inline-
block elements:
navigation item is displayed as a block-level element, but remains inline with other items.
Visibility
The CSS visibility property allows you to show or hide an element without changing the layout
Hidden − The element is hidden, but it still takes up space on the page.
Collapse − Remove table rows, columns, column groups, and row groups from a
table. collapse has the same meaning as hidden if it is used on non-table elements.
Overflow
The overflow property determines how content which overflows its element's content area
should be handled.
Possible Values
Scroll − Overflowing content should not be displayed, but the user agent should provide
Page | 46
Auto − The behavior caused by this value is dependent on the browser.
Resize Elements
CSS resize is a property that allows users to adjust the size of an element, either vertically,
Resize property adds a handle at the bottom-right corner of an element on a webpage. This
handle allows users to click and drag to change the size of an elements, making it larger or
value.
Block − User can resize an element in the block direction (either horizontally or vertically,
Inline − User can resize an element in the inline direction (either horizontally or vertically,
Quotes
The CSS quotes property sets how the browser should render quotation marks that are
Page | 47
Hover
The CSS: hover pseudo-class is used to target an element when the user hovers over it with the
mouse cursor.
CSS Syntax
:hover{…}
over it.
it:
CSS - Opacity
The CSS opacity property controls the transparency of an element. Opacity determines how
Value Description
Navigation bar
A navigation bar is a section of a graphical user interface (GUI) that helps users navigate through
a website, app, or other software. It is essential for users to quickly and easily navigate to the
The navigation bar can be horizontal or vertical, that contains links to important pages or
features. Navbars can also contain other elements, such as the logo of the website or app, search
bar, or social media icons. Navbars can be styled using CSS to change their appearance.
navigation bar displayed across the top of a web page as shown below
<html>
<head>
<style>
Page | 49
ul {
background-color: #28bf17;
overflow: hidden;
list-style-type: none;
margin: 0;
padding: 0;
li {
float: left;
li a {
none;font-size: 17px;}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
Page | 50
<li><a href="#">Articles</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">eBook</a></li>
</ul>
<h1>Welcome to TutorialsPoint</h1>
</body>
</html>
Example
<html>
<head>
<style>
200px;}
li {text-align: center;}
none;font-size: 17px;}
Page | 51
li a:hover {background-color: #dd9ede;color: black;}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Articles</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">eBook</a></li>
</ul>
</body>
</html>
over a link. Dropdown menus are a way to show a list of related items in a small space.
Example
<html>
Page | 52
<head>
<style>
#28bf17;}
min-width: 120px;}
text-align: left;}
</style>
</head>
<body>
<nav class="navbar">
Page | 53
<a href="#">Home</a>
<div class="dropdown">
<button class="dropbtn">Articles</button>
<div class="dropdown-content">
<a href="#">HTML</a>
<a href="#">CSS</a>
<a href="#">Bootstrap</a>
</div>
</div>
<a href="#">Courses</a>
<a href="#">eBook</a>
</nav>
<h1>Welcome to TutorialsPoint</h1>
</body>
</html>
the page. To make a navbar fixed, you can use the position: fixed property.
Page | 54
The following example demonstrates how the position: fixed property can be used to create a
fixed vertical navbar, which ensures that the navbar stays on the left side of the screen, even
<html>
<head>
<style>
padding-bottom: 300px}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
Page | 55
<li><a href="#">Articles</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">eBook</a></li>
</ul>
<div class="heading">
<h1>Welcome to TutorialsPoint</h1>
</div>
</body>
</html>
Image Gallery
CSS image gallery is a collection of images that is displayed using CSS. CSS can be used to
control the layout of the images, their size, spacing, and other visual properties.
CSS image galleries are commonly used on websites to display products, portfolios, or other
The following example shows a simple image gallery layout that is displayed in a row −
<html>
<head>
<style>
Page | 56
.image-gallery {display: flex;flex-flow: row wrap;justify-content: space-between;
align-items: center;}
</style>
</head>
<body>
<div class="image-gallery">
</div>
</body>
</html>
Multi Background
CSS Multi background property is used to add one or more images at a time without HTML
code, We can add images as per our requirement. A sample syntax of multi background images
is as follows.
#multibackground {
Page | 57
background-image: url(/css/images/logo.png), url(/css/images/border.png);
padding: 75px;
section
Example:
<html>
<head>
<style>
url(/css/images/border.png);
Page | 58
padding: 75px;
</style>
</head>
<body>
<div id = "multibackground">
<h1>www.tmptc.com</h1>
<p>
Entoto Polytechnic College (EPTC) the former Taferi Mekonen School was
The college has today’s name and task starting from 1994 E.C. The college provides
surveying, drafting, and urban and land, business, and urban agriculture. </p>
</div>
</body>
</html>
Page | 59
Multi background property is accepted to add different sizes for different images.A sample
#multibackground {
repeat;
As shown above an example, each image is having specific sizes as 50px, 130px and auto size.
Gradients
What is Gradients?
Types of gradients
Linear Gradients(down/up/left/right/diagonally)
Radial Gradients
Linear gradients are used to arrange two or more colors in linear formats like top to bottom.
Top to bottom
<html>
<head>
<style>
#grad1 {
Page | 60
height: 100px;
background: -webkit-linear-gradient(pink,green);
background: -o-linear-gradient(pink,green);
background: -moz-linear-gradient(pink,green);
background: linear-gradient(pink,green);
</style>
</head>
<body>
<div id = "grad1"></div>
</body>
</html>
Output:
Left to right-example
Page | 61
Diagonal:example
Multi color
Page | 62
There are tons of different layout designs to choose from. However, the structure above, is one of
the most common, and we will take a closer look at it in this tutorial.
Header
A header is usually located at the top of the website (or right below a top navigation menu). It
Navigation Bar
A navigation bar contains a list of links to help visitors navigating through your website:
The layout in this section, often depends on the target users. The most common layout is one (or
We will create a 3-column layout, and change it to a 1-column layout on smaller screens:
Page | 63
Unequal Columns
The main content is the biggest and the most important part of your site.
It is common with unequal column widths, so that most of the space is reserved for the main
content. The side content (if any) is often used as an alternative navigation or to specify
Footer
The footer is placed at the bottom of your page. It often contains information like copyright and
contact info:
I. position: static
HTML elements are positioned static by default.
Static positioned elements are not affected by the top, bottom, left, and right properties.
An element with position: static; is not positioned in any special way; it is always positioned
Example
Page | 64
div. Static {
position: static;
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it
to be adjusted away from its normal position. Other content will not be adjusted to fit into any
NOTE − You can use bottom or right values as well in the same way as top and left.
Example
<html>
<head>
</head>
<body>
Page | 65
</div>
</body>
</html>
However; if an absolute positioned element has no positioned ancestors, it uses the document
NOTE − You can use bottom or right values as well in the same way as top and left.
Example
<html>
<head>
</head>
<body>
</div>
Page | 66
</body>
</html>
stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are
A fixed element does not leave a gap in the page where it would normally have been located.
NOTE − you can use bottom or right values as well in the same way as top and left.
Example
<html>
<head>
</head>
<body>
</div>
Page | 67
</body>
</html>
The <link> element can be used to include an external stylesheet file in your HTML document.
An external style sheet is a separate text file with .css extension. You define all the Style rules
within this text file and then you can include this file in any HTML document using <link>
element.
<head>
</head>
@import is used to import an external stylesheet in a manner similar to the <link> element. Here
<head>
@import "URL";
</head>
Here URL is the URL of the style sheet file having style rules. You can use another syntax as
well –
<head>
@import url("URL");
</head>
Page | 68
Example
Following is the example showing you how to import a style sheet file into HTML document −
<head>
@import "mystyle.css";
</head>
Responsive web design provides an optimal experience, easy reading and easy navigation with a
Page | 69
Flexible Grid
<html>
<head>
<style>
body {
"HelveticaNeue-Light",
"Helvetica Neue",
Helvetica, Arial,
"Lucida Grande",
Sans-Serif;
h1 {
color: #9799a7;
font-size: 14px;
font-weight: bold;
margin-bottom: 6px;
.container:before, .container:after {
content: "";
Page | 70
display: table;
.container:after {
clear: both;
.container {
background: #eaeaed;
margin-bottom: 24px;
*zoom: 1;
.container-75 {
width: 75%;
.container-50 {
margin-bottom: 0;
width: 50%;
border-radius: 6px;
section, aside {
Page | 71
background: #2db34a;
color: #fff;
margin: 1.858736059%;
padding: 20px 0;
text-align: center;
section {
float: left;
width: 63.197026%;
aside {
float: right;
width: 29.3680297%;
</style>
</head>
<body>
<section>Section</section>
<aside>Aside</aside>
Page | 72
</div>
<section>Section</section>
<aside>Aside</aside>
</div>
<section>Section</section>
<aside>Aside</aside>
</div>
</body>
</html>
Output:
Page | 73
Media queries
Media queries is for different style rules for different size devices such as mobiles, desktops, etc.,
<html>
<head>
<style>
body {
background-color: lightpink;
</style>
</head>
<body>
<p>
Page | 74
If screen size is less than 420px, then it will show lightblue
</p>
</body>
</html>
application of different layers of design elements, styles, and functionality to achieve a desired
overall design for a website. This approach helps in creating a modular and maintainable design
system. In CSS, the z-index property is used for controlling the stacking order of positioned
elements
Page | 75