Cascading Style Sheet Lecture 4
Cascading Style Sheet Lecture 4
The position property specifies the type of positioning method used for
an element.
There are five different position values:
static
Relative
fixed
Absolute
sticky
THE POSITION PROPERTY
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;
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 according to the normal flow of the page:
THE POSITION PROPERTY
position: relative;
An element with position: relative; is positioned relative to its normal
position.
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 gap left by
the element.
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.
THE POSITION PROPERTY
A fixed element does not leave a gap in the page where it would
normally have been located.
position: absolute;
An element with position: absolute; is positioned relative to the nearest
positioned ancestor (instead of positioned relative to the viewport, like
fixed).
However; if an absolute positioned element has no positioned
ancestors, it uses the document body, and moves along with page
scrolling.
Note: A "positioned" element is one whose position is anything except
static
THE POSITION PROPERTY
position: sticky;
An element with position: sticky; is positioned based on the user's
scroll position.
A sticky element toggles between relative and fixed depending on
the scroll position. It is positioned relative until a given offset position
is met in the viewport - then it "sticks" in place (like position:fixed).
OVERLAPPING
OVERLAPPING
CSS Overflow
The CSS overflow property controls what happens to content that is too
big to fit into an area.
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.
The overflow property has the following values:
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
OVERLAPPING
scroll The overflow is clipped, and a scrollbar is added to see the rest of
the content
Auto Similar to scroll, but it adds scrollbars only when necessary
FLOAT
FLOAT
CSS Combinators
A CSS selector can contain more than one simple selector. Between the
simple selectors, we can include a combinator.
There are four different combinators in CSS:
descendant selector (space)
child selector (>)
adjacent sibling selector (+)
general sibling selector (~)
COMBINATORS
Descendant Selector
The descendant selector matches all elements that are descendants of
a specified element.
The following example selects all <p> elements inside <div> elements:
div p {
background-color: yellow;
}
COMBINATORS
Child Selector
The child selector selects all elements that are the children of a
specified element.
The following example selects all <p> elements that are children of a
<div> element:
div > p {
background-color: yellow;
}
COMBINATORS