Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Implement Absolute Positioning | Mastering CSS Positioning
Advanced CSS Techniques

bookChallenge: Implement Absolute Positioning

Task

Center the child element (div with the class name child) within the parent element (div with the class name parent) using absolute positioning.

Steps:

  1. Apply absolute positioning to the child element.
  2. Calculate the values for the top and left properties to center the child element within the parent element. The parent element has a width and height of 220px, while the child element has a width and height of 80px.
  3. Ensure that one element has absolute positioning, and the other has relative positioning to establish the correct positioning context. Otherwise, the absolute positioning will be relative to the body element.
index.html

index.html

index.css

index.css

copy
  1. To calculate the value for the top property, use the formula: (parentHeight - childHeight) / 2.
  2. To calculate the value for the left property, use the formula: (parentWidth - childWidth) / 2.
index.html

index.html

index.css

index.css

copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 2.04

bookChallenge: Implement Absolute Positioning

Sveip for å vise menyen

Task

Center the child element (div with the class name child) within the parent element (div with the class name parent) using absolute positioning.

Steps:

  1. Apply absolute positioning to the child element.
  2. Calculate the values for the top and left properties to center the child element within the parent element. The parent element has a width and height of 220px, while the child element has a width and height of 80px.
  3. Ensure that one element has absolute positioning, and the other has relative positioning to establish the correct positioning context. Otherwise, the absolute positioning will be relative to the body element.
index.html

index.html

index.css

index.css

copy
  1. To calculate the value for the top property, use the formula: (parentHeight - childHeight) / 2.
  2. To calculate the value for the left property, use the formula: (parentWidth - childWidth) / 2.
index.html

index.html

index.css

index.css

copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5
some-alt