Web Interface Design - II
Web Interface Design - II
Unit-II
# What is css?
CSS (Cascading Style Sheets) is a fundamental technology used in web development to control the
presentation and layout of web pages. While HTML is used to structure content, CSS is used to style and
visually organize that content — including colors, fonts, spacing, positioning, animations, and more.
CSS (Cascading Style Sheets) is a style sheet language used to describe the presentation of a document
written in HTML or XML. While HTML provides the structure and content of a web page, CSS controls how
that content looks - its layout, colors, fonts, and overall visual style.
CSS Syntax
CSS syntax is made up of rules that tell the browser how to style specific HTML elements.
Selector {
Property: value;
}
Selector – the HTML element you want to style (e.g., h1, p, div)
Property – the style feature you want to change (e.g., color, font-size)
Value – the setting you give to the property (e.g., red, 16px)
Example 1:
h1 {
color: blue;
text-align: center;
}
This means:
h1, h2, h3 {
Page 1
Web Interface Designing Technologies
Comments in CSS
You can add comments to explain your code. Comments do not affect how the page is displayed.
/* This is a comment */
p{
color: gray;
}
Complete Example
/* Headings */
h1 {
color: navy;
font-size: 36px;
}
/* Paragraphs */
p{
color: black;
line-height: 1.6;
}
There are several ways to incorporate Cascading Style Sheets (CSS) into an HTML document.
1. Inline Styles:
Inline styles involve directly embedding CSS rules within HTML elements using the style attribute. This
approach applies styles to individual elements, overriding any styles defined in external or internal
stylesheets.
Page 2
Web Interface Designing Technologies
Example:
Internal stylesheets involve embedding CSS rules within the <style> tag inside the <head> section of an
HTML document. This approach allows you to define styles for the entire page in one place.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #f0f0f0;
h1 {
color: green;
p{
font-size: 14px;
</style>
</head>
Page 3
Web Interface Designing Technologies
<body>
<h1>This is a heading.</h1>
<p>This is a paragraph.</p>
</body>
</html>
External stylesheets involve creating separate .css files containing CSS rules and linking them to HTML
documents using the <link> tag in the <head> section. This is the most recommended and widely used
approach for styling web pages.
Example:
HTML (index.html):
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading.</h1>
<p>This is a paragraph.</p>
</body>
</html>
Page 4
Web Interface Designing Technologies
CSS (styles.css):
body {
background-color: #f0f0f0;
h1 {
color: green;
p{
font-size: 14px;
# CSS Combinators
CSS combinators are symbols that explain the relationship between the selectors. They are used to select
elements based on their relationship to other elements in the HTML structure. Without combinators, CSS
selectors would only be able to target elements based on their type, class, ID, or attributes. Combinators add
a layer of specificity and control, allowing you to target elements based on their context within the
document.
Descendant Combinator (Space): Selects all elements that are descendants of a specified element.
Child Combinator (>): Selects all elements that are direct children of a specified element.
Adjacent Sibling Combinator (+): Selects the first element that is immediately preceded by another
specified element.
General Sibling Combinator (~): Selects all elements that are preceded by another specified element.
The descendant combinator is represented by a space between two selectors. It selects all elements that are
descendants (children, grandchildren, etc.) of a specified element.
Page 5
Web Interface Designing Technologies
Syntax:
ancestor descendant {
/* CSS rules */
Example:
HTML:
<div class="container">
<div>
</div>
</div>
CSS:
.container p {
color: blue;
In this example, the CSS rule will apply to all <p> elements that are descendants of the element with the
class container. Both paragraphs in the HTML will be colored blue.
The child combinator is represented by the > symbol. It selects all elements that are direct children of a
specified element.
Syntax:
Page 6
Web Interface Designing Technologies
/* CSS rules */
Example:
HTML:
<div class="container">
<div>
</div>
</div>
CSS:
.container > p {
color: blue;
In this example, the CSS rule will only apply to the <p> element that is a direct child of the element with the
class container. The second paragraph, which is nested inside another <div>, will not be affected.
The adjacent sibling combinator is represented by the + symbol. It selects the first element that is
immediately preceded by another specified element.
Syntax:
element1 + element2 {
/* CSS rules */
Example:
Page 7
Web Interface Designing Technologies
HTML:
<h2>Heading</h2>
<p>This is a paragraph.</p>
CSS:
h2 + p {
color: green;
In this example, the CSS rule will apply to the first <p> element that immediately follows the <h2> element.
The second <p> element will not be affected.
The general sibling combinator is represented by the ~ symbol. It selects all elements that are preceded by
another specified element.
Syntax:
element1 ~ element2 {
/* CSS rules */
Example:
HTML:
<h2>Heading</h2>
<p>This is a paragraph.</p>
<ul>
<li>List Item</li>
</ul>
Page 8
Web Interface Designing Technologies
CSS:
h2 ~ p {
color: red;
In this example, the CSS rule will apply to all <p> elements that follow the <h2> element, regardless of
whether they are immediately adjacent or separated by other elements.
# Colors in CSS
Colors are a fundamental aspect of web design, influencing the look and feel of a website and impacting user
experience. CSS offers several ways to specify colors, each with its own advantages and use cases. Choosing
the right color format and understanding how to apply it effectively is crucial for creating visually appealing
and accessible web pages.
Hexadecimal colors are one of the most common ways to specify colors in CSS. They use a six-digit
hexadecimal number (base 16) to represent the red, green, and blue components of a color. Each pair of
digits represents the intensity of one of these components, ranging from 00 (minimum intensity) to FF
(maximum intensity).
Syntax: #RRGGBB
Example:
#FF0000 (Red)
#00FF00 (Green)
#0000FF (Blue)
#FFFFFF (White)
#000000 (Black)
2. RGB Colors
Page 9
Web Interface Designing Technologies
RGB (Red, Green, Blue) colors specify the intensity of each color component using decimal values ranging
from 0 to 255.
Example:
rgb(255, 0, 0) (Red)
rgb(0, 0, 0) (Black)
3. RGBA Colors
RGBA (Red, Green, Blue, Alpha) colors are an extension of RGB that include an alpha channel, allowing you
to specify the transparency of the color. The alpha value ranges from 0.0 (fully transparent) to 1.0 (fully
opaque).
Example:
4. HSL Colors
HSL (Hue, Saturation, Lightness) colors provide a more intuitive way to specify colors based on their
perceptual properties.
Hue: Represents the color's position on the color wheel, ranging from 0 to 360 degrees. 0 is red, 120 is
green, and 240 is blue.
Saturation: Represents the intensity of the color, ranging from 0% (grayscale) to 100% (fully saturated).
Page 10
Web Interface Designing Technologies
Lightness: Represents the brightness of the color, ranging from 0% (black) to 100% (white).
Example:
5. HSLA Colors
HSLA (Hue, Saturation, Lightness, Alpha) colors are an extension of HSL that include an alpha channel for
specifying transparency, similar to RGBA.
Example:
6. Named Colors
CSS provides a set of predefined named colors that you can use directly. These names are case-insensitive.
Example:
red
green
blue
Page 11
Web Interface Designing Technologies
Example:
body {
h1 {
p{
Page 12
Web Interface Designing Technologies
In CSS, backgrounds allow you to control the look and feel of an element’s background. CSS provides
multiple properties to customize backgrounds, such as color, image, position, size, repeat behavior, and
more
Background Color:
The background-color property sets the background color of an element. It accepts color values in various
formats, including:
Example:
body {
.header {
color: white;
Background Image:
The background-image property sets an image as the background of an element. You specify the image
using the url() function.
Example:
body {
background-image: url("images/background.jpg");
Background Repeat:
Page 13
Web Interface Designing Technologies
space: The image is repeated as much as possible without clipping, and the extra space is distributed evenly
between the images.
round: The image is repeated as much as possible without clipping, and the image is scaled to fit the
available space.
Example:
body {
background-image: url("images/pattern.png");
Background Position:
The background-position property specifies the initial position of the background image. You can use
keywords like top, bottom, left, right, and center, or you can use pixel or percentage values.
Example:
.hero {
background-image: url("images/hero.jpg");
Background Size:
cover: The image is scaled to cover the entire element, potentially cropping the image.
Page 14
Web Interface Designing Technologies
contain: The image is scaled to fit within the element, maintaining its aspect ratio. This may result in empty
space around the image.
length: Specifies the width and height of the background image in pixels or other units.
percentage: Specifies the width and height of the background image as a percentage of the element's width
and height.
Example:
.logo {
background-image: url("images/logo.png");
Background Attachment:
The background-attachment property specifies whether the background image scrolls with the page or is
fixed.
Example:
body {
background-image: url("images/background.jpg");
CSS borders are lines that surround an HTML element, adding visual separation and emphasis. They are a
fundamental aspect of web design, allowing you to define the appearance of elements and create visually
appealing layouts. Borders can be applied to any HTML element, including <div>, <p>, <span>, <h1>, and
more.
Page 15
Web Interface Designing Technologies
Border Properties
border-style: Defines the appearance of the border (e.g., solid, dashed, dotted).
These properties can be set individually or combined using the shorthand border property.
`border-width`
The border-width property determines the thickness of the border. It accepts values in pixels (px), points
(pt), ems (em), or other CSS units. You can specify different widths for each side of the border using the
following syntax: border-width: top right bottom left;
Example:
.element {
border-width: 2px 5px 1px 3px; /* Top: 2px, Right: 5px, Bottom: 1px, Left: 3px */
border-style`
The border-style property defines the appearance of the border. Here are the most common values:
Example:
.element {
Page 16
Web Interface Designing Technologies
border-style: solid dashed dotted double; /* Top: solid, Right: dashed, Bottom: dotted, Left:
double */
border-color:
The border-color property sets the color of the border. You can use any valid CSS color value, such as:
Example:
.element {
border-color: red green blue yellow; /* Top: red, Right: green, Bottom: blue, Left: yellow */
.element2 {
The border shorthand property allows you to set the border-width, border-style, and border-color in a single
declaration. The order of the values doesn't matter.
Example:
.element {
border: 2px solid black; /* Width: 2px, Style: solid, Color: black */
# Margins:
In CSS, margins define the space around an element's outside. They create a gap between the element's
border and surrounding elements. Margins contribute to the overall layout and spacing of a webpage,
preventing elements from appearing too crowded or overlapping. Unlike padding, which adds space inside
an element, margins add space outside the element.
Page 17
Web Interface Designing Technologies
Margin Properties
margin: This is the shorthand property for setting all four margins (top, right, bottom, and left) at
once.
margin-top: Sets the margin on the top side of an element.
margin-right: Sets the margin on the right side of an element.
margin-bottom: Sets the margin on the bottom side of an element.
margin-left: Sets the margin on the left side of an element.
length: Specifies a fixed margin size using units like px (pixels), em (relative to the font size of the element),
rem (relative to the root font size), pt (points), cm (centimeters), etc.
auto: The browser calculates the margin. This is often used to horizontally center block-level elements
within their parent container.
inherit: The element inherits the margin value from its parent element. For example: margin-top: inherit;
%: Specifies a margin as a percentage of the width of the containing block. The top and bottom margins are
calculated as a percentage of the width, not the height, of the containing block. For example: margin-left:
10%;
Example:
.centered-element {
width: 300px;
margin-left: auto;
margin-right: auto;
background-color: lightblue;
Page 18
Web Interface Designing Technologies
# Padding
Padding refers to the space between the content of an HTML element and its border. It's like adding a
cushion inside the element, pushing the content away from the edges. Padding is defined using CSS and can
be applied to all four sides of an element: top, right, bottom, and left.
Padding Properties
padding: This is the shorthand property for setting the padding on all four sides at once.
Pixels (px): A fixed size in pixels. For example, padding: 10px; sets a 10-pixel padding on all sides.
Ems (em): Relative to the font size of the element. padding: 1em; sets the padding to the same size
Rems (rem): Relative to the font size of the root element (the <html> element). padding: 1rem; sets
the padding to the same size as the root element's font size.
Percentages (%): Relative to the width of the containing element. padding: 10%; sets the padding to
Auto: The auto value is not typically used for padding. It's more commonly used for margins to
Page 19
Web Interface Designing Technologies
CSS properties provide a wide range of options for styling and manipulating text, allowing developers to
create visually appealing and accessible web content.
1.Font Properties:
The font properties in CSS control the typeface used to render text. They are crucial for establishing the
visual identity and readability of a website.
font-family: Specifies the font to be used. You can provide a list of fonts as a fallback mechanism. The
browser will try to use the first font in the list, and if it's not available, it will move on to the next, and so on.
It's good practice to include a generic font family (e.g., serif, sans-serif, monospace, cursive, fantasy) as the
last item in the list.
body {
font-size:
Sets the size of the font. Common units include pixels (px), ems (em), rems (rem), and percentages (%).
body {
h1 {
Page 20
Web Interface Designing Technologies
font-weight`
Controls the boldness of the font. Common values include normal, bold, bolder, lighter, and numeric values
from 100 to 900 (where 400 is equivalent to normal and 700 is equivalent to bold).
h1 {
font-weight: bold;
font-style`
em {
font-style: italic;
CSS provides properties to control the alignment and spacing of text within an element.
`text-align`: Specifies the horizontal alignment of text. Values include left, right, center, and justify.
h1 {
text-align: center;
p{
line-height: Sets the height of a line of text. A value without units is multiplied by the element's font size.
letter-spacing: Adjusts the spacing between letters. Values can be positive or negative.
word-spacing: Adjusts the spacing between words. Values can be positive or negative.
Page 21
Web Interface Designing Technologies
3. Text Decoration
CSS allows you to add decorations to text, such as underlines, overlines, and line-throughs.
text-decoration-line:
Specifies the type of text decoration. Values include none, underline, overline, and line-through.
a{
text-decoration-style: Specifies the style of the text decoration. Values include solid, double, dotted,
dashed, and wavy.
text-transform: Changes the capitalization of text. Values include none, capitalize, uppercase, and
lowercase.
h1 {
text-shadow: Adds a shadow to text. The syntax is: horizontal-offset vertical-offset blur-radius color.
# Tables In CSS:
CSS provides various properties applicable to tables, including basic styling, borders, spacing, layout control,
and advanced techniques for creating visually appealing and responsive tables.
The fundamental elements of an HTML table (<table>, <tr>, <th>, <td>) can be styled using CSS just like any
other HTML element. Here's a breakdown of common properties:
Page 22
Web Interface Designing Technologies
border: Applies a border to the table, rows, cells, or headers. You can specify the border width, style
(solid, dashed, dotted, etc.), and color.
background-color: Sets the background color of the table, rows, cells, or headers.
color: Sets the text color within the table, rows, cells, or headers.
font-family: Specifies the font used for the text in the table.
font-size: Sets the size of the text in the table.
text-align: Aligns the text horizontally within cells (left, center, right, justify).
vertical-align: Aligns the text vertically within cells (top, middle, bottom).
padding: Adds space between the cell content and the cell border.
margin: Adds space around the table itself.
Table Layout
The table-layout property controls how the table's columns are sized.
table-layout: auto;: The column widths are determined by the content of the cells. This is the default
behavior.
table-layout: fixed;: The column widths are determined by the first row of the table or by explicitly set
width properties on the col or colgroup elements. This can significantly improve rendering performance,
especially for large tables.
Zebra Striping
Zebra striping (alternating row colors) can improve readability, especially in large tables. This can be
achieved using the :nth-child() pseudo-class.
Example:
tr:nth-child(even) {
background-color: #f2f2f2;
Responsive Tables
Making tables responsive is essential for ensuring they display correctly on different screen sizes. Here are a
few approaches:
Page 23
Web Interface Designing Technologies
Horizontal Scrolling: Wrap the table in a container with overflow-x: auto;. This will allow the table to scroll
horizontally on smaller screens.
Stacking Columns: Use media queries to change the table layout on smaller screens. You can hide the table
headers and display each row as a series of stacked blocks.
# Lists in CSS:
CSS offers several properties to control the appearance of lists. The primary properties are list-style-type,
list-style-position, and list-style-image.
list-style-type
The list-style-type property defines the type of marker used for list items. It applies to both ordered (<ol>)
and unordered (<ul>) lists.
Example : ol {
list-style-type: decimal;
ul {
list-style-type: square;
Unordered list:
Page 24
Web Interface Designing Technologies
# CSS Positioning:
CSS positioning allows you to control the placement of elements on a webpage. The position property
determines the positioning scheme used for an element. There are five main values for the position
property:
static: This is the default value. Elements are positioned according to the normal document flow. top, right,
bottom, and left properties have no effect.
relative: The element is positioned relative to its normal position in the document flow. Using top, right,
bottom, and left properties will offset the element from its normal position. Other elements are positioned
as if the element were still in its original location.
absolute: The element is removed from the normal document flow and positioned relative to its nearest
positioned ancestor (an ancestor with a position value other than static). If there is no positioned ancestor, it
is positioned relative to the initial containing block (the <html> element). top, right, bottom, and left
properties are used to specify the offset from the containing block.
fixed: The element is removed from the normal document flow and positioned relative to the viewport (the
browser window). It remains in the same position even when the page is scrolled. top, right, bottom, and
left properties are used to specify the offset from the viewport.
sticky: The element is positioned based on the user's scroll position. It behaves like relative until the element
reaches a specified threshold, at which point it becomes fixed. You must specify at least one of top, right,
bottom, or left for sticky positioning to work.
Example:
</div>
# CSS Overflow
The overflow property controls how content that exceeds the boundaries of its container is handled. It
specifies whether to clip the content, add scrollbars, or display the overflow. The possible values are:
visible: This is the default value. Content that overflows the container is displayed outside of it.
Page 25
Web Interface Designing Technologies
scroll: Scrollbars are added to the container, allowing the user to scroll to view the overflowing content.
Scrollbars are always displayed, even if the content doesn't overflow.
auto: Scrollbars are added to the container only when the content overflows.
overlay: Similar to auto, but scrollbars take up no space. This is not supported by all browsers.
Example:
<div style="width: 100px; height: 50px; border: 1px solid black; overflow: visible;">
</div>
CSS Floats
The float property is used to position an element to the left or right of its container, allowing other content
to flow around it. Floats are often used to create multi-column layouts or to wrap text around images. The
possible values are:
none: This is the default value. The element does not float.
Clearing Floats
When an element is floated, it is removed from the normal document flow. This can cause the container
element to collapse if it only contains floated children. To prevent this, you need to clear the floats. Clearing
a float means that the element will be rendered below any floated elements.
Using the clear property: The clear property can be applied to an element to specify which sides of the
element should not have floats. The possible values are left, right, both, and none.
Using the "clearfix" hack: This involves adding a pseudo-element (::after) to the container element and
setting its clear property to both. This is a common and effective way to clear floats.
Example:
Page 26
Web Interface Designing Technologies
Pseudo-classes are keywords added to selectors that specify a special state of the selected element(s). They
allow you to style elements based on factors other than their position in the document tree, such as user
interaction (e.g., hovering, clicking), state (e.g., enabled, disabled), or structural position (e.g., first child, last
child).
Syntax
selector:pseudo-class {
property: value;
The colon (:) is used to separate the selector from the pseudo-class.
Common Pseudo-classes:
:hover: Applies styles when the user hovers the mouse over an element.
:active: Applies styles when an element is being activated (e.g., clicked).
:focus: Applies styles when an element has focus (e.g., when a user tabs to it).
:visited: Applies styles to links that the user has already visited.
:link: Applies styles to links that have not been visited.
:first-child: Applies styles to the first child element of its parent.
:last-child: Applies styles to the last child element of its parent.
:nth-child(n): Applies styles to elements that are the nth child of their parent. n can be a number, a
keyword (even, odd), or a formula (e.g., 2n+1).
:nth-of-type(n): Applies styles to elements that are the nth element of their type within their parent.
:disabled: Applies styles to disabled form elements.
:enabled: Applies styles to enabled form elements.
Page 27
Web Interface Designing Technologies
# Pseudo-elements :
Pseudo-elements allow you to style specific parts of an element. They create virtual elements that are not
part of the actual document tree but can be styled as if they were.
Syntax
selector::pseudo-element {
property: value;
The double colon (::) is used to separate the selector from the pseudo-element. (Note: Single colon syntax ::
is also supported for backwards compatibility, but the double colon is the preferred syntax).
Common Pseudo-elements:
::before: Inserts content before the content of an element. Requires the content property.
::after: Inserts content after the content of an element. Requires the content property.
# Opacity in CSS:
The opacity property in CSS is used to control the transparency of an element. It determines how much of
the background behind the element is visible. A value of 0 makes the element completely transparent, while
a value of 1 makes it completely opaque. Values between 0 and 1 create varying degrees of transparency.
Syntax
Page 28
Web Interface Designing Technologies
element {
opacity: value;
Example:
.transparent-box {
opacity: 0.5;
# Tooltips in CSS:
The fundamental concept behind CSS-only tooltips involves leveraging the :hover pseudo-class and the data-
* attributes. We'll use a span element to wrap the text that needs a tooltip. The tooltip text itself will be
stored in a data-tooltip attribute on the span. CSS will then be used to display this text when the user hovers
over the span.
Example:
Css:
.tooltip {
position: relative;
Page 29
Web Interface Designing Technologies
# image gallery:
One of the oldest methods for creating image galleries is using floats. This approach involves floating each
image to the left or right, allowing them to wrap around each other.
HTML Structure:
<div class="gallery">
</div>
CSS Styling:
.gallery {
.gallery img {
Page 30
Web Interface Designing Technologies
The .gallery class sets the overall width of the gallery and centers it on the page.
The img selector styles each image, setting its width, height, and margin. float: left; is the key
property that allows the images to arrange themselves horizontally.
Another basic approach is using display: inline-block. This allows elements to flow like inline elements but
retain block-level properties like width and height.
HTML Structure:
HTML Structure:
<div class="gallery">
</div>
CSS Styling:
.gallery {
width: 80%;
Page 31
Web Interface Designing Technologies
margin: 0 auto;
.gallery img {
width: 200px;
height: auto;
margin: 10px;
display: inline-block; allows the images to sit side-by-side while still allowing you to set their width
and height.
text-align: center; on the .gallery container horizontally centers the images.
vertical-align: top; ensures the images are aligned to the top, preventing potential alignment issues
due to different image heights.
CSS Grid offers the most powerful and flexible layout options for creating image galleries. It allows you to
define rows and columns, creating complex and responsive layouts.
Example:
width: 80%;
Page 32
Web Interface Designing Technologies
margin: 0 auto;
.gallery img {
width: 100%;
height: auto;
# CSS Forms:
The foundation of styling forms lies in understanding how to target and modify the appearance of individual
form elements using CSS selectors.
CSS (Cascading Style Sheets) enables to make HTML forms look more attractive and user-friendly by styling
form elements like <input>, <textarea>, <select>, and <button>.
Examle:
input, textarea, select {
width: 100%;
padding: 10px;
margin: 5px 0 15px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
2. Styling Form Lables:
Page 33
Web Interface Designing Technologies
Form labels play a crucial role in both accessibility and usability. Using CSS, you can transform plain, default
labels into visually appealing components that not only enhance the look of your form but also improve its
functionality. Here’s how you can style form labels effectively:
Ex:
label {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
font-weight: bold;: This makes the label text appear bolder, improving its prominence and
readability. It helps the label stand out from the associated input field.
font-family: Select a font that is easy to read and consistent with the overall design of your website.
Consider using a sans-serif font for better readability on screens.
Color: applies the color to label text
Background-color: applies background color to the label
Font – size: applies the font size to lable text
padding: Add padding to the label to create more visual space around the text.
margin-bottom: 5px;: This adds a small margin below the label, creating visual separation between
the label and the input field. Adjust the value as needed to achieve the desired spacing.
Hover and Focus States:
Provide visual feedback when the user hovers over or focuses on the label. This can improve the user
experience by indicating that the label is interactive (especially for radio buttons and checkboxes).
Example:
label:hover {
background-color: #e0e0e0;
cursor: pointer; /* Change cursor to indicate interactivity */
}
label:focus {
Page 34
Web Interface Designing Technologies
3. Styling Buttons:
To style buttons, we can target the following HTML elements using CSS: <input type="submit">, <input
type="reset">, and <button>. A basic styling approach involves setting the background color, text color,
removing the border, adding padding, and rounding the corners.
Example:
background-color: Sets the background color of the button. In this example, it's set to #4CAF50, a
shade of green.
color: Sets the text color of the button. Here, it's set to white.
border: Removes the default border that some browsers apply to buttons. Setting it to none gives
you more control over the button's appearance.
Page 35
Web Interface Designing Technologies
padding: Adds space around the text inside the button. The first value (10px) sets the top and
bottom padding, while the second value (20px) sets the left and right padding.
border-radius: Rounds the corners of the button. A value of 5px creates a subtle rounded effect.
cursor: Changes the cursor to a pointer when the mouse hovers over the button, indicating that it's
clickable.
font-size: Sets the size of the text within the button.
CSS provides a variety of properties to style and align form elements on a webpage. It helps create a visually
appealing and user-friendly form layout by controlling aspects such as width, margins, padding, background
color, borders, and shadows.
Example:
form {
max-width: 400px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
max-width: 400px;: This property sets the maximum width of the form to 400 pixels.
margin: 0 auto;: This is a shorthand property for setting the top, right, bottom, and left margins. 0
sets the top and bottom margins to zero, while auto horizontally centers the form within its parent
container.
padding: 20px;: This property adds 20 pixels of padding around the content inside the form. Padding
creates space between the form's content (e.g., labels, input fields, buttons) and the form's border,
improving readability and visual appeal.
background-color: #f9f9f9;: This sets the background color of the form to a light gray (#f9f9f9).
border: 1px solid #ddd;: This adds a 1-pixel solid border around the form.
Page 36
Web Interface Designing Technologies
# CSS counters:
CSS counters are essentially variables maintained by CSS that can be incremented by CSS rules to track how
many times they are used. They allow you to automatically generate and update numbers or other markers
for elements on your page, providing a flexible alternative to static numbering or JavaScript-based solutions.
They are particularly useful for numbering sections, figures, tables, or any other content that needs to be
sequentially identified.
Core Properties
The following CSS properties are essential for working with counters:
counter-reset: This property initializes or resets a counter to a specific value (defaulting to 0). It's typically
applied to the parent element of the elements you want to number. You can reset multiple counters at
once.
counter-increment: This property increments the value of a counter each time the associated element
appears. It's applied to the element you want to number. You can increment multiple counters at once, and
specify the increment value (defaulting to 1).
content: This property is used to insert generated content before or after an element. It's often used in
conjunction with the ::before or ::after pseudo-elements to display the counter value. The counter() and
counters() functions are used within the content property to access and format the counter value.
Example:
<!DOCTYPE html>
<html>
<head>
<title>CSS Counters Example</title>
<style>
body {
counter-reset: section; /* Initialize the 'section' counter */
}
h2 {
counter-increment: section; /* Increment the 'section' counter for each h2 */
Page 37
Web Interface Designing Technologies
}
h2::before {
content: "Section " counter(section) ": "; /* Display the counter value */
font-weight: bold;
}
</style>
</head>
<body>
<h2>Introduction</h2>
<p>This is the introduction section.</p>
<h2>Background</h2>
<p>This section provides background information.</p>
<h2>Methods</h2>
<p>This section describes the methods used.</p>
</body>
</html>
Page 38