WebPHP Unit20 - PDF
WebPHP Unit20 - PDF
Unit II CSS
CSS CSS stands for Cascading Style Sheets. It is a style sheet language which is used to describe the
look and formatting of a document written in markup language. CSS is used along with HTML and
JavaScript in most websites to create user interfaces for web applications and for many mobile
applications.
No HTML
Tags
Appearance of an entire
Inline style(1) has the highest web site can be
priority, and will override changed with a change styles.css
external(2) and internal(3) in external style sheet,
styles (both in head section) which is separately
and browser defaults. saved in .css extension.
2
an exception...? NSS College Rajakumari, Dept. of Computer Applications
Web Programming using PHP
Unit II
CSS CSS Properties - Fonts
The CSS font properties defines the font family, boldness, size, and the style of a text.
Properties Values
font-style normal, italic, oblique
font-variant normal, small-caps
font-weight normal, bold, bolder, lighter, 100, 200….900
xx-small, x-small, small, medium, large, x-large, xx-large,smaller, larger, size
font-size
in pixels or in %
line-height normal,number,length in px, %
font-family any font family eg. Arial, Helvetica, and ends with generic family
The font CSS property is a shorthand property which sets the style, variant, boldness, size/line-height,
and the font family for an element's text content in a single declaration.
font : font-style font-variant font-weight font-size/line-
height font-family|caption|icon|menu|message-
box|small-caption|status-bar|initial|inherit;
NSS College Rajakumari, Dept. of Computer Applications 3
Web Programming using PHP
Unit II
CSS CSS Properties – Fonts example
Individual assignment
Shorthand property
shorthand
background-color url
background-repeat
background-attachment
background-position
In addition to Font,
Text, Background and
Lists CSS also have
some other
properties like Border,
Margin, Color,
Animation …….
NSS College Rajakumari, Dept. of Computer Applications 9
Web Programming using PHP
Unit II CSS Selectors
CSS CSS selectors are used to "find" (or select) the HTML elements that want to be styled.
Different categories of CSS Selectors
1. Simple selectors (based on….)
a) Universal selector a wildcard(*) symbol is used to give style for all HTML elements in a page.
b) Name(Element) selector selects all elements with the specified element name.
a hash (#) character followed by id styles the element with the specified id. The id of an
c) id selector element is unique within a page. Selector uses this id attribute of an HTML element to
select a specific element.
select all elements which belong to a particular class attribute. For this a period ( . )
d) Class selector followed by class name is used. Styling a particular element is also possible by starting
with that element name then period(.) followed by class name.
is used to select multiple elements and style them together. Each selector is separated
e) Group selector by a space. This reduces the code and extra effort to declare common styles for each
element.
2. Combinator selectors - select elements based on a specific relationship between them
3. Pseudo-class selectors - select elements based on a certain state
4. Pseudo-element selectors - select and style a part of an element
5. Attribute selectors - select elements based on an attribute or attribute value
NSS College Rajakumari, Dept. of Computer Applications 10
Web Programming using PHP
Unit II CSS Simple Selector
CSS
Universal
Name
id
Class
Group
:
selector : pseudo-class { property : value } selector . class : pseudo-class { property : value }
Some commonly used pseudo-classes are
Selector Description
:link Use this class to add special style to an unvisited link.
:visited Use this class to add special style to a visited link.
LOVE
:hover Use this class to add special style to an element when mouse is moved over it
HATE
:active Use this class to add special style to an active element.
:focus Use this class to add special style to an element while the element has focus.
Use this class to add special style to an element that is the first child of some other element.
:first-child
( p : first-child - selects every <p> elements that is the first child of its parent)
Use this class to add special style to an element that is the last child of some other element.
:last-child
( p : last-child - selects every <p> elements that is the first child of its parent)
• Pseudo-class names are not case-sensitive.
a:hover must come after a:link and a:visited in the CSS definition. • Pseudo-class are different from CSS classes but
a:active must come after a:hover in the CSS definition. they can be combined.
NSS College Rajakumari, Dept. of Computer Applications 13
Web Programming using PHP
Unit II
CSS
Focus with “input” & CSS class combined with pseudo class
All pseudo-elements
selector :: pseudo-element { property : value; } ::
Selector Description
::first-line used to add a special style to the first line of a text. (only for block-level elements)
::first-letter used to add a special style to the first letter of a text.
::before used to insert some content before the content of an element.
::after used to insert some content after the content of an element.
matches the portion of an element that is selected by a user. color, background, cursor,
::selection
and outline properties can be applied.
References
1. https://www.tutorialspoint.com
2. https://www.geeksforgeeks.org
3. https://www.w3schools.com
4. https://www.javapoint.com
5. Background vector created by grmarc - www.freepik.com
https://www.freepik.com/free-photos-
vectors/background