Which of the following CSS Property controls how an element is positioned?

position
set
static
fix

The correct answer is: A. position

The position property in CSS is used to control the positioning of an element on a page. It can be used to position an element absolutely, relatively, or statically.

  • Absolute positioning: An absolutely positioned element is positioned relative to its nearest positioned ancestor element.
  • Relative positioning: A relatively positioned element is positioned relative to its parent element.
  • Static positioning: A statically positioned element is positioned according to the normal flow of the page.

The position property can also be used to create fixed elements, which remain in the same position on the page regardless of scrolling.

Here is an example of how the position property can be used to position an element absolutely:

css
div {
position: absolute;
top: 10px;
left: 10px;
width: 100px;
height: 100px;
background-color: red;
}

This code will create a red box that is 100px wide and 100px high, and is positioned 10px from the top and left of the page.

Here is an example of how the position property can be used to position an element relatively:

css
div {
position: relative;
top: 10px;
left: 10px;
width: 100px;
height: 100px;
background-color: red;
}

This code will create a red box that is 100px wide and 100px high, and is positioned 10px from the top and left of its parent element.

Here is an example of how the position property can be used to create a fixed element:

css
div {
position: fixed;
top: 10px;
left: 10px;
width: 100px;
height: 100px;
background-color: red;
}

This code will create a red box that is 100px wide and 100px high, and is positioned 10px from the top and left of the viewport, regardless of scrolling.

Exit mobile version