Learn CSS

"If you want to learn how to style and design web pages, you need to master CSS. CSS stands for Cascading Style Sheets, and it is the language that defines the appearance and layout of HTML elements. In this course, you will learn the basics of CSS, such as selectors, properties, values, units, and colors. You will also learn how to use CSS to create responsive web design, animations, transitions, and more. By the end of this course, you will be able to create beautiful and functional web pages using CSS."

CSS Position Property

The position property in CSS is used to specify the positioning of an element on a web page. It allows you to control the location of an element, and how it interacts with other elements on the page.

 

There are several values for the position property:

 

static: 

This is the default value for the position property. It means that the element is positioned according to the normal flow of the document. You cannot use the top, bottom, left, or right properties with the static value.


div {
 position: static;
}

 

relative: 

This value positions the element relative to its normal position in the document flow. You can use the top, bottom, left, or right properties to move the element from its original position.


div {
 position: relative;
 top: 20px;
 left: 10px;
}

 

absolute: 

This value positions the element relative to its nearest positioned ancestor element. If there is no positioned ancestor, the element is positioned relative to the initial containing block (usually the body element). You can use the top, bottom, left, or right properties to position the element.


div {
 position: absolute;
 top: 50%;
 left: 50%;
 transform: translate(-50%, -50%);
}

 

fixed: 

This value positions the element relative to the viewport. The element will not move even if the page is scrolled. You can use the top, bottom, left, or right properties to position the element.


div {
 position: fixed;
 top: 0;
 left: 0;
}

 

sticky: 

This value is similar to fixed, but the element becomes fixed only when it reaches a specified scroll position. You can use the top, bottom, left, or right properties to position the element.


div {
 position: sticky;
 top: 0;
}


By using the position property with these values, you can control the location of HTML elements on your webpage, and create complex, dynamic layouts that adapt to different screen sizes and devices.