Web Technologies
CSS #2
Claudia Chiriță . 2026/2027
selector:pseudo-class {
property: value;
}
- keyword added to a selector to specify a special state of the selected element
- eg. used for defining
- the style of an element when the mouse is over it
- different styles for visited and unvisited links
:link /* links that haven't been visited */
:visited /* links that have been visited */
:hover /* elements when we move the mouse over them */
:active /* active links */
:not() /* elements that are not an argument of not */
selects an element that is the first child of another element
Pseudo-classes
:first-of-type
selects the element that is the first child of the specified type of another element
:nth-of-type(n)
selects the element that is the n-th child of the specified type of another element
:nth-child(n)
selects the element of the specified type that is the n-th child of another element
n can be a natural number, a keyword (odd, even), formula (an+b, with n starting from 0)
- used to define the style of a part of an element
- virtual elements, created with CSS, which do not appear in the HTML tree of the page
::first-letter /* first letter of a text */
::first-line /* first line of a block element */
::before, ::after /* used to add content */
/* before/after an HTML element; */
/* used with the content property */
-
custom CSS properties
(nonstandard, defined by users)
- defined to be reused inside a document
- the implicit position of any HTML element
- with static position, the element will have a normal flux in the page
- the elements with static position are not affected by left,
right, top, bottom properties
- an element with position:relative is positioned relatively to the position it would have normally had in the page
- for positioning we use the properties
left, right, top and bottom
- the element is positioned relatively to the first parent that has position:absolute/relative/fixed
- the element is taken out of the flux of the document
- it can overlap with other elements (exit Flatland!)
- the element has a fixed position in the browser window
- the element is taken out of the flux of the document and is not affected by the scroll
- for positioning we use the properties
left, right, top and bottom
- the element commutes between relative and fixed positioning depending
on the scroll
- if the position of the scroll does not go pass the element, it will be positioned relatively, otherwise it behaves like a fixed element
z-index: ...,-100 /* 0, 100,... */
- through positioning, the elements can overlap; there can appear stacks of elements
- the order of elements in the stack is given by z-index
- most visibile elements have higher z-index
- z-index can be set only for elements
that are have an absolute, relative or fixed position
float: left; /* right, none */
- elements with float property are taken out of the flux of the document
and positioned according to the given value, to the left or to the right
- they affect the other elements: these arrange themselves by "wrapping" the float elements
- the elements with an absolut position ignore the float property
clear: left; /* right, none, both */
- determines if an element must be positioned below float elements that preceed it
- elements with clear property do not arrange themselves around the
float elements; they go below them
- unidimensional layout method for arranging items un rows and columns
- items extend (flex) to fill the available space or shrink to fit in smaller spaces
- the flexible layout offers an efficient method for positioning, aligning and distributing the space between the elements in the document even when the viewport and element dimension is unknown or dynamic
flexbox tutorial
- the flexible layout consists in defining
two types of elements:
- flex container - parent element
- flex items - child elements
parent properties:
display
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
display: flex; /* inline-flex */
- defines a flexible container, inline or block, depending on the given value
- creates a flexible context for all its direct children
flex-direction: row; /* row-reverse, column, column-reverse*/
- defines the direction in which the items are placed in the container: horizontally (left-right or right-left) or vertically (up-down or down-up)
flex-wrap: wrap; /* nowrap, wrap-reverse*/
- establishes if the items will be arranged on a single line (column) or several
- implicitly, the items will be arranged on a single line (column)
flex-flow: flex-direction flex-wrap;
- shorthand for properties flex-direction, flex-wrap
- implicitly: flex-flow: row nowrap
justify-content: start; /* end, center, space-between,
space-around, space-evenly */
- specifies the way in wich items are aligned along the main axis
align-items: stretch; /* start, end, center, baseline */
- specifies the way in wich items are aligned along the secondary axis (the axis perpendicular to the main axis)
align-content: stretch; /* start, end, center,
space-between, space-around */
- distributes the space between and around items
on the secondary axis
- has no effect if there is only a single line in the container
children properties:
order
flex-grow
flex-shrink
flex-basis
flex
align-self
order: <integer>; /* implicitly 0*/
- establishes the order in which the items will appear in the flexible container
- implicitly, items appear in the order in which they are written in the HTML document
flex-grow: <number>; /* implicitly 0*/
- establishes the capacity of items to extend their dimension if there is available space inside the container
- if all items have a flex-grow of 1, they will share the available space equally
flex-shrink: <number>; /* implicitly 1*/
- the capacity of items to shrink if necessary
flex-basis: <length>; /* auto (implicitly) */
- defines the implicit dimension of an element before the distribution of the available space
flex: flex-grow flex-shrink flex-basis;
- shorthand for properties flex-grow, flex-shrink and flex-
basis
- implicitly flex: 0 1 auto
align-self: stretch; /* start, end, center, baseline, auto */
- allows individual alignment of items on the secondary axis
- overrides the alignment specified with align-items
- bidimensional layout system, based on a grid, with rows and columns, used for positioning, aligning and distributing the space between the elements in a document
grid tutorial
- CSS grid consists in defining two types of elements:
- grid container - parent element
- grid items - child elements
parent properties:
display
grid-template-columns & grid-template-rows
grid-template-areas
column-gap & row-gap
justify-content
align-content
justify-items & align-items
display: grid; /* inline-grid */
- defines the element as a grid container, inline or block, depending on the given value
- establishes a grid format context for all its direct children
justify-content: start; /* end, center, space-between,
space-around, space-evenly */
- specifies the way in which the grid is aligned inside the container
- the alignment is done horizontally
align-content: stretch; /* start, end, center,
space-between, space-around, space-evenly */
- specifies the way in which the grid is aligned inside the container, vertically
place-content: align-content justify-content
children properties:
grid-column & grid-row
grid-area
justify-self & align-self
place-self
grid-column: start-column / end-column
- defines the columns in which an element is placed
- shorthand for properties grid-column-start and grid-column-end
grid-row: start-line / end-line
- defines the rows in which an element is placed
- shorthand for properties grid-row-start and grid-row-end
grid-area: start-line / start-column
/ end-line / end-column
- shorthand for properties
grid-row-start, grid-column-start, grid-row-end, grid-column-end
grid-area: name-item
- can name an item of the grid which is then referred using the property grid-template-areas for the container
justify-self: stretch /* start, end, center */
- aligns an item of the grid inside a cell, on the main axis
align-self: stretch /* start, end, center */
- aligns an item of the grid inside a cell, on the secondary axis
place-self: align-self justify-self
(\ /)
( . .)
C(")(")
questions?