CSS Fundamentals for Web Design
CSS Fundamentals for Web Design
UNIT – II
CSS: CSS home, introduction, syntax, CSS combinators, colors, background, borders, margins,
padding, height/width, text, fonts, tables, lists, position, overflow, float, pseudo class, pseudo
elements, opacity, tool tips, image gallery, CSS forms, CSS counters.
CSS Introduction:
CSS makes it visually appealing or stylish. It controls the layout of a web page i.e. how
HTML elements will be displayed on a webpage.
When tags like <font>, and color attributes were added to the HTML, it is difficult for web
developers. Development of large websites, where fonts and color information were added to
every single page, became a long and expensive process.
Advantages of CSS
Limitations of CSS
CSS Syntax
1. Selector: A CSS selector is the initial portion of a CSS syntax rule. It's a collection of
HTML elements that tells the browser which HTML elements should get the rule's CSS
property values applied to them.
2. Declaration Block: A declaration block contains a list of declarations that define how the
selected elements should be styled. A declaration consists of a property and a value,
separated by a colon and terminated by a semicolon.
3. Property: The property is an identifier that specifies which feature, such as color or font
size, is taken into account.
4. Value: CSS values are allocated to CSS Properties and saved in the CSS declaration block,
which is part of the CSS rule/statement. For example, the color is set to black.
Types of selectors
1. Universal Selector
The very first CSS selector we will be discussing will be the universal selector, It selects
all the HTML elements present on the HTML page. To use the universal selector, we need to
use asterisks (*) and then define the CSS property and after that, all the elements will be
selected.
Syntax
*{
//css properties
}
PROGRAM: Program to use universal selector
<!DOCTYPE html>
<html>
<head>
<style>
*{
font-size:21px;
background-color:pink;
color: red;
}
</style>
</head>
<body>
<h1>Universal Selector</h1>
<h2>This is a heading(h2)</h2>
<p>This is a para</p>
<div>This is a div</div>
<p>CSS properties inside (*) will be applied to all elements</p>
</body>
</html>
Output:
etc. To use a type selector, you just need to give the name of the HTML tag and then in the
curly braces define the CSS properties.
Syntax
element_name{
//css properties
}
PROGRAM: Program to element selector
<!DOCTYPE html>
<html>
<head>
<style>
h1{
text-align:center;
background-color:pink;
color: red;
}
h2{
text-align:right;
background-color:red;
color: green;
}
p{
font-size:21px;
background-color:pink;
color: blue;
}
</style>
</head>
<body>
<h1>Element Selector</h1>
<h2>This is a heading(h2)</h2>
<p>This is a para</p>
<div>This is a div</div>
</body>
</html>
Output:
3. Class Selector
We generally use class to group HTML elements and to apply unique styling to them.
The class selector in CSS selects elements that belong to a particular class attribute. To
select elements with a specific class, write a period or dot (.) character, and then the name
of the class.
Syntax:
.class_name{
//css properties;
<!DOCTYPE html>
<html>
<head>
<style>
.marked{
text-align:center;
background-color:yellow;
color: red;
}
.unmarked{
font-size:21px;
background-color:pink;
color: blue;
}
</style>
</head>
<body>
<h1 class="marked">Class Selector</h1>
<h2 class="unmarked">This is a heading(h2)</h2>
<p class="marked">This is a para</p>
<div class="unmarked">
<p>this para is in div</p>
<p class="marked">This is an example for class selectors</p>
</div>
</body>
</html>
Output:
For suppose you have a set of CSS properties selected under a class name, and you only
want to apply a specific CSS property to a specific HTML element under the class. For that
specify the element name, then give the full stop/period(.) character, followed by the class
name.
<!DOCTYPE html>
<html>
<head>
<style>
[Link]{
text-align:center;
background-color:yellow;
color: red;
}
[Link]{
font-size:21px;
background-color:pink;
color: blue;
}
</style>
</head>
<body>
<h1 class="marked">Class Selector</h1>
<h2 class="unmarked">This is a heading(h2)</h2>
<p class="marked">This is a para</p>
<div class="unmarked">
<p>this para is in div</p>
<p class="marked">This is an example for class selectors</p>
</div>
</body>
</html>
Output:
4. ID SELECTOR
The CSS ID selector uses the HTML element’s ID attribute to select elements on a page
and apply CSS properties on that. The id attribute is the unique identifier in an HTML
document to use an ID selector in CSS, use a hashtag (#) followed by the name of the ID of
the HTML element. The HTML element will only be selected if its id attribute matches
exactly with the value given in the selector. ID attribute must contain at least one character
and cannot begin with a number.
Syntax:
#id{
//css properties.
}
PROGRAM: Program to id selector
<!DOCTYPE html>
<html>
<head>
<style>
#head1,#head2{
text-align:center;
background-color:yellow;
color: red;
}
#para1,#para2{
font-size:21px;
background-color:pink;
color: blue;
}
</style>
</head>
<body>
<h1 id="head1">Class Selector</h1>
<h2 id="head2">This is a heading(h2)</h2>
<p id="para1">This is a para</p>
<div id="d1">
<p>this para is in div</p>
<p id="para2">This is an example for class selectors</p>
</div>
</body>
</html>
Output:
The CSS grouping selector allows you to select multiple HTML elements having the same
CSS properties and group them so that the style can be applied at once to all the
elements.
This reduces the code redundancy and makes code simpler, readable, re-usable.
To group HTML elements, first, we need to check if there are elements whose CSS
properties are the same??, if yes!! Then we will group those elements and separate
them with a comma(,) and then you are free to implement the same style to all the
selected elements.
Syntax:
element_1,element_2,…{
css properties;
}
PROGRAM: Program to grouping selector
<!DOCTYPE html>
<html>
<head>
<style>
h1,h2{
text-align:center;
background-color:yellow;
color: red;
}
p{
font-size:21px;
background-color:pink;
color: blue;
}
</style>
</head>
<body>
<h1>Groupping Selector</h1>
<h2>This is a heading(h2)</h2>
<p>This is a para</p>
<div>This is a div</div>
</body>
</html>
Output:
CSS Combinator
Combinators in CSS help in locating and selecting specific elements within a document
by establishing the relationship between selectors.
A CSS combinator is a type of selector in CSS which is used to specify the relationship
between any two CSS selectors. This helps in uniquely identifying and selecting only
those elements within a document that satisfy the specified relationship.
Syntax
selector(combinator)selector {
styles;
}
There are four distinct Combinators in CSS, and each specifies a different type of relationship
among the two selectors they are placed
Descendant selector (space)
Syntax:
Parent_element Child_element {
css properties;
}
PROGRAM: Program to Descendant selector
<!DOCTYPE html>
<html>
<head>
<style>
div p {
background-color: yellow;
color:blue;
font-style: italic;
}
</style>
</head>
<body>
<h2>Descendant Selector</h2>
<p>The descendant selector in CSS selects all HTML elements that are descendants of a
specified ancestor element.</p>
<div>
<h2>heading inside div</h2>
</div>
<div>
<p>This is paragraph in the div.</p>
</div>
<p>This paragraph is not inside div.</p>
</body>
</html>
Output:
Syntax:
Element_1 ~ Element_2 {
css properties;
}
PROGRAM: Program to sibling selector
<!DOCTYPE html>
<html>
<head>
<style>
div ~ p {
background-color: yellow;
color:blue;
font-style: italic;
}
</style>
</head>
<body>
<h1>sibling Selector</h2>
<p>This para is div sibling but appears before div.</p>
<div>
<p>This para is inside the div.</p>
</div>
<p>first para. This para is div sibling and also appears after div.</p>
<p>second para. This para is div sibling and also appears after div.</p>
</body>
</html>
Output:
The adjacent sibling selector is used to select an element that is adjacent to the first
specified element and also the sibling of the first element.
It uses the plus (+) sign to combine the two elements. The second element is selected
only when the element specified in the second place is immediately after the first
element and the first and the second elements are siblings. This sibling selector selects
the adjacent element, or we can say that the element is next to the specified tag.
Syntax:
Element_1 + Element_2 {
css property;
}
PROGRAM: Program to adjacent sibling selector
<!DOCTYPE html>
<html>
<head>
<style>
div + p {
background-color: yellow;
color:blue;
font-style: italic;
}
</style>
</head>
<body>
<h1>adjacent sibling Selector</h2>
<p>This para is div sibling but appears before div.</p>
<div>
<p>This para is inside the div.</p>
</div>
<p>first para. This para is div sibling and also appears after div.</p>
<p>second para. This para is div sibling and also appears after div.</p>
</body>
</html>
Output:
4. Child selector (>) The child selector selects all elements that are the immediate children of a
specified element.
It uses the greater than (>) sign as the separator between the elements. The parent element
must always be placed at the left of the ">". It only selects the elements that are the immediate
child of the specified parent element. If we remove the greater than (>) symbol that designates
this as a child combinator, then it will become the descendant selector.
Syntax:
<p>This paragraph will be selected because it is inside a div (inside another div element).</p>
</div>
<section>
<p>This paragraph will not be selected because it is inside a div but also inside a section
element.</p>
</section>
<p>This paragraph will be selected because it is inside a div.</p>
</div>
<p>This paragraph will not be selected because it is not inside a div.</p>
</body>
</html>
Output:
Inline styles are styles that are written directly in the tag on the document. Inline styles
affect only the tag they are applied to.
<p style="text-decoration: none;">Use inline style sheets when you want to apply a style to a
single occurrence of an element. Inline style sheets are declared within individual tags and
affect those tags only. Inline style sheets are declared with the style attribute.
Syntax:
<style type="text/css">
styles go here
</style>
<head>
<style type="text/css">
p {color: green}
</style>
</head>
<body>
<h1>heading</h1>
</body>
</html>
Output:
If you made any change in an external style sheet, the change is applied on all the pages
where the style sheet is used.
An external style sheet is saved in an external file with a .css extension.
Syntax:
rel-When using an external style sheet on a webpage, this attribute takes the value
"style sheet"
type- When using an external style sheet on a webpage, this attribute takes the
value"text/css"
href- Denotes the name and location of the external style sheet to be used.
h1
color:red;
background:yellow;
p{
color:blue;
background:pink;
font-size:12pt;
<html>
<head>
</head>
<body>
<h1>heading</h1>
</body>
</html>
Output:
CSS Properties
<title>color property</title>
</head>
<body>
<h1 style="color: red;">heading</h1>
<h2 style="color: #00ff00;">heading</h2>
<p style="color: rgb(0,0,255);">this is para</p>
</body>
</html>
Output:
The CSS background properties are used to define the background effect for element.
<html>
<head>
<body>
</body>
</head>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title>background property</title>
<style>
body {
background-image: url("../images/[Link]");
background-repeat: no-repeat;
backgound-attachment: fixed;
background-position: center;
</style>
</head>
<body>
<p align="center">Here, the background image will be positioned in the center of the element
(in this case, the body element).</p>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title>background property</title>
<style>
body {
background-image: url("../images/[Link]");
background-repeat: no-repeat;
backgound-attachment: fixed;
background-position: center;
</style>
</head>
<body>
<p align="center">Here, the background image will be positioned in the center of the element
(in this case, the body element).</p>
</body>
</html>
Output:
Border-style
The values for border-style properties are:
solid
Double
Groove
Dotted
Dashed
Inset
Outset
Ridge
hidden
Border-width
This property specifies the width of the four borders.
The values for border-width property are:
thick
thin
medium
Or give specific size in px, pt, cm, em, etc.
Note: The border-style property must be defined to get the result of border-width.
Border-color: This property sets the color for the borders. The "border-color" property
does not work if it is used alone. Use the "border-style" property to set the borders first.
Border colors are set by:
Specifying a color name, like “orange”.
Specifying hex value, like “#ff0000”.
Specifying RGB value, like “rgb(255,0,0)”.
Border-direction
If you want an individual look for each side of the border, this property can be
used.
The border direction values are: top/bottom/right/left.
Example:
border-bottom-style: solid;
border-bottom-color: red;
border-bottom-width: 5px;
border-Allinone: It is used to create a uniform border.
Example:
border:10px outset green;
border:20px solid;
PROGRAM: Program for border properties
<html>
<head>
<style>
[Link]
{
font-size:30;
border-style:solid;
border-color: red;
border-width: thin;
}
[Link]{
font-size:30;
border-style: dashed;
border-color:green;
border-width: thick;
}
[Link]{
font-size:30;
border-style:dotted;
border-color: blue;
border-width: 5;
}
</style>
</head>
<body>
<h2>Theborder-colorProperty</h2>
<p>Thispropertyspecifiesthecolorofthefour borders:</p>
<p class="one">A solid red border</p>
<p class="two">A solid green border</p>
<p class="three">A dotted blue border</p>
</body>
</html>
Output:
</body>
</html>
Output:
</body>
</html>
Output:
The CSS height and width properties are used to set the height and width of an element. The
height and width properties do not include padding, borders, or margins. It sets the
height/width of the area inside the padding, border, and margin of the element.
<head>
<style>
div {
height: 200px;
width: 50%;
background-color: lightblue;
</style>
</head>
<body>
</body>
</html>
Output:
7. CSS Text
Text Color and Background Color- The color property is used to set the color of the text.
Text Alignment- The text-align property is used to set the horizontal alignment of a text. A text
can be left or right aligned, centered, or justified.
Text Decoration
text-decoration-line : overline;/underline;/line-through;
text-decoration-style: solid;/double;/dotted;/dashed;/wavy;
Text Shadow
The text-shadow property adds shadow to text. In its simplest use, you only specify the
horizontal shadow and the vertical shadow. Then, we can add a blur effect (px) to the shadow
and also add a color to the shadow.
<head>
<style>
h1 {
color: green;
text-align: center;
h2 {
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
</body>
</html>
Output:
8. CSS Fonts:
Property Description
Font Families
1. Serif fonts have a small stroke at the edges of each letter. They create a sense of
formality and elegance.
2. Sans-serif fonts have clean lines (no small strokes attached). They create a modern and
minimalistic look.
3. Monospace fonts - here all the letters have the same fixed width. They create a
mechanical look.
font-size Property
font-style Property
font-weight Property
This property sets how thick or thin characters in text should be displayed.
font-variant
This property specifies whether or not a text should be displayed in a small-caps font.
<head>
<style>
p{
</style>
</head>
<body>
<p>This is a paragraph. The font is set to italic, small-caps and bold, the font size is set to 20
pixels, and the font family is Georgia.</p>
</body>
</html>
Output:
CSS Tables
Table Borders- To specify table borders in CSS, use the border property.
Full-Width Table- If you need a table that should span the entire screen (full-width), add width:
100% to the <table> element.
Collapse Table Borders- This property sets whether the table borders should be collapsed into a
single border. It has two values collapse and separate.
Width and Height- The width and height of a table are defined by
the width and height properties.
text-align- The text-align property sets the horizontal alignment (like left, right, or center) of
the content in <th> or <td>
Vertical Alignment- The vertical-align property sets the vertical alignment (like top, bottom, or
middle) of the content in <th> or <td>
Table Padding- To control the space between the border and the content in a table, use
the padding property on <td> and <th> elements.
<head>
<style>
table, th, td {
border-collapse:collapse;
width:50%;
height:100px;
text-align:center;
vertical-align:bottom;
</style>
</head>
<body>
<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</table>
</body>
</html>
Output:
CSS Lists
unordered lists (<ul>) - the list items are marked with bullets.
ordered lists (<ol>) - the list items are marked with numbers or letters.
list-style-type- property specifies the type of list item marker. Values like Circle, square, upper-
roman, lower-alpha. Some of the values are for unordered lists, and some for ordered lists.
list-style-type: square;
list-style-position- property specifies the position of the list-item markers (bullet points).
"list-style-position: outside;" means that the bullet points will be outside the list item.
The start of each line of a list item will be aligned vertically.
"list-style-position: inside;" means that the bullet points will be inside the list item. As it
is part of the list item, it will be part of the text and push the text at the start.
list-style- property is a shorthand property. It is used to set all the list properties in one
declaration.
When using the shorthand property, the order of the property values is:
list-style-type
list-style-position
list-style-image
<head>
<style>
ul {
</style>
</head>
<body>
<p>The list-style property is a shorthand property, which is used to set all the list properties in
one declaration.</p>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Output:
The position property specifies the type of positioning method used for an element.
static
relative
fixed
absolute
sticky
Elements are then positioned using the top, bottom, left, and right properties. However, these
properties will not work unless the position property is set first. They also work differently
depending on the position value.
position: static;
position: relative;
position: fixed;
An element with position: fixed; is positioned relative to the viewport, which means it
always stays in the same place even if the page is scrolled.
The top, right, bottom, and left properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been
located.
position: absolute;
position: absolute;
</html>
Output:
The overflow property specifies whether to clip the content or to add scrollbars when the
content of an element is too big to fit in the specified area.
visible - Default. The overflow is not clipped. The content renders outside the element's
box
hidden - The overflow is clipped, and the rest of the content will be invisible
scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content
<head>
<style>
div {
background-color: coral;
width: 100px;
height: 100px;
overflow: scroll;
</style>
</head>
<body>
<h2>Overflow: scroll</h2>
<div>You can use the overflow property when you want to have better control of the layout.
The overflow property specifies what happens if content overflows an element's box.</div>
</body>
</html>
Output:
The float property is used for positioning and formatting content e.g. let an image float left to
the text in a container.
none - The element does not float (will be displayed just where it occurs in the text).
This is default
In its simplest use, the float property can be used to wrap text around images.
<head>
<style>
img {
width:170px;
height:170px;
margin-left:15px;
float: right;
</style>
</head>
<body>
<h2>Float Right</h2>
<p><img src="../images/[Link]">
a high metabolic rate, a four-chambered heart, and a strong yet lightweight skeleton.</p>
</body>
</html>
Output:
CSS Pseudo-classes
selector:pseudo-class {
property: value;
}
Anchor Pseudo-classes
The pseudo class is used to set the style of the unvisited element. The word unvisited
means the user has not been or visited to that page or element.
a:link{
color: green;
The pseudo class is used to set style of the visited elements/ links. The word visited
means the user has been to or visited to that page or element.
a: visited {
color: darkblue;
If you are unfamiliar with the term hover, we will help you to understand the same.
Hover means to move the mouse cursor over something.
a:hover {
color: red;
}
The pseudo class come into picture when the user clicks or activates the state of a
particular element. While using a mouse, the activation typically means when the user presses
the primary mouse button.
a:active {
color:pink;
}
The decreasing order of specificity is as follows- The acronym is LVHA-order: :link — :visited —
:hover — :active.
div:hover {
background-color: blue;
}
<p>CSS</p>
Example:
[Link]:hover {
color: #ff0000;
}
:first-child Pseudo-class
The pseudo class is used to select the first element of the parent. It selects the first child
of the parent. This is very useful to style lists.
Consider the example for understanding the concept of parents and children.
<div>
</div>
Example:
p:first-child {
color: blue;
:last-Child Pseudo-Class
The last-child pseudo class is used to select the last element of the parent.
li:last-child{
color:orange;
:Focus Pseudo-Class
The focus pseudo class is used to represent a element that has received focus. An element is
said to have received focus when the user clicks on it. This is generally applied on form-inputs.
input:focus{
background-color:sandybrown;
:Lang Pseudo-Class
The <q> tag defines a short quotation. Browsers normally insert quotation marks around the
quotation.
The pseudo class is used to select elements with a lang attribute having a specific value. This
pseudo class is useful when we want our document in multiple languages.
:lang(en){
:lang(fr){
<head>
<style>
a:link{
color:green;
a: visited {
color:darkblue;
a:hover {
color: red;
a:active {
color: pink;
h1:hover {
background-color: blue;
[Link]:hover {
color: red;
p:first-child {
color: blue;
input:focus{
background-color:lightblue;
</style>
</head>
</body>
<p>CSS</p>
<div>
</div>
<form action="">
</form>
</body>
</html>
Output:
CSS Pseudo-elements
selector::pseudo-element {
property: value;
}
The ::first-line pseudo-element is used to add a special style to the first line of a text.
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
font properties
color properties
background properties
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
clear
The ::first-letter pseudo-element is used to add a special style to the first letter of a text.
p::first-letter {
color: #ff0000;
font-size: xx-large;
}
font properties
color properties
background properties
margin properties
padding properties
border properties
text-decoration
text-transform
line-height
float
clear
The ::before pseudo-element can be used to insert some content before the content of an
element.
h1::before {
content: url([Link]);
}
The ::after pseudo-element can be used to insert some content after the content of an
element.
h1::after {
content: url([Link]);
}
::marker {
color: red;
font-size: 23px;
}
The ::selection pseudo-element matches the portion of an element that is selected by a user.
color
background
cursor
outline
::selection {
color: red;
background: yellow;
}
CSS Opacity
The opacity property specifies the opacity/transparency of an element. The opacity property
can take a value from 0.0 - 1.0. The lower the value, the more transparent.
img {
opacity: 0.5;
}
The opacity property is often used together with the :hover selector to change the opacity on
mouse-over. Opacity can be used for images and also for other elements.
If you do not want to apply opacity to child elements, like in our example above,
use RGBA color values. The following example sets the opacity for the background color and
not the text:
div {
background: rgba(76, 175, 80, 0.3) /* Green background with 30% opacity */
}
<head>
<style>
img {
opacity: 0.5;
img:hover {
opacity: 1.0;
</style>
</head>
<body>
<h1>Image Transparency</h1>
<p>The opacity property is often used together with the :hover selector to change the opacity
on mouse-over:</p>
</body>
</html>
Output:
CSS Tooltip
A CSS tooltip is a small, non-interactive pop-up box that appears when a user hovers
over an HTML element, providing supplemental information or context about that
element. These tooltips are typically styled and controlled entirely using CSS, eliminating the
need for JavaScript in basic implementations.
PROGRAM: Program to create a tooltip that appears when the user moves the mouse over an
element
<html>
<style>
.tooltip {
position: relative;
display: inline-block;
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: white;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
.tooltip:hover .tooltiptext {
visibility: visible;
</style>
<body>
<h2>Basic Tooltip</h2>
</div>
</body>
</html>
Output:
Image gallery
A CSS image gallery involves using HTML to structure the image elements and CSS to
control their layout, appearance, and responsiveness.
<html>
<head>
<style>
[Link] {
margin: 5px;
float: left;
width: 180px;
[Link]:hover {
[Link] img {
width: 100%;
height: 130;
[Link] {
padding: 15px;
text-align: center;
</style>
</head>
<body>
<div class="gallery">
</a>
</div>
<div class="gallery">
</a>
</div>
<div class="gallery">
</a>
</div>
<div class="gallery">
</a>
</div>
</div>
</body>
</html>
Output:
CSS forms
CSS (Cascading Style Sheets) is used extensively to style HTML forms, providing control
over their appearance and layout. This allows developers to create visually appealing and user-
friendly forms that integrate seamlessly with a website's overall design.
Width: Use the width property to determine the width of the input field
Padding: Use the padding property to add space inside the text field.
Border: Use the border property to change the border size and color.
Background-color: Use the background-color property to add a background color to the input.
:focus pseudo-class: Use the :focus selector to do something with the input field when it gets
focus.
background-image: If you want an icon inside the input, use the background-image property.
Styling Textarea
width
height
padding
box-sizing
border
border-radius
background-color
resize: Use the resize property to prevent textareas from being resized (disable the
"grabber" in the bottom right corner)
width
padding
border
border-radius
background-color
background-color
border
color
padding
text-decoration
margin
cursor: The cursor property with a value of "not-allowed", which will display a "no
parking sign" when you mouse over the button. We can also use a value “pointer” which
shows a hand symbol when hover on a button.
:hover pseudo-class: Use the :hover selector to change the style of a button when you
move the mouse over it.
<html>
<head>
<style>
*{
box-sizing: border-box;
width: 100%;
padding: 12px;
border-radius: 4px;
resize: vertical;
label {
display: inline-block;
input[type=submit] {
background-color: #04AA6D;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
input[type=submit]:hover {
background-color: #45a049;
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
.row::after {
content: "";
display: table;
clear: both;
</style>
</head>
<body>
<h2>Responsive Form</h2>
<div class="container">
<form action="">
<div class="row">
<div class="col-25">
</div>
<div class="col-75">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="country">Country</label>
</div>
<div class="col-75">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="india">India</option>
<option value="usa">USA</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="subject">Subject</label>
</div>
<div class="col-75">
</div>
</div>
<br>
<div class="row">
</div>
</form>
</div>
</body>
</html>
Output:
CSS counters
CSS counters are "variables" maintained by CSS whose values can be incremented by
CSS rules (to track how many times they are used). Counters let you adjust the appearance of
content based on its placement in the document.
CSS counters are like "variables". The variable values can be incremented by CSS rules (which
will track how many times they are used).
<html>
<head>
<style>
body {
counter-reset: section;
h2::before {
counter-increment: section;
</style>
</head>
<body>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h2>JavaScript Tutorial</h2>
<h2>Python Tutorial</h2>
<h2>SQL Tutorial</h2>
</body>
</html>
Output: