-
Hajipur, Bihar, 844101
object-position
?The CSS object-position
property specifies the alignment (position) of replaced content like images or videos inside their container when the content is resized using object-fit
(especially with cover
or contain
).
It controls which part of the image is visible when it is cropped or fitted.
img {
object-position: 50% 50%; /* horizontal vertical */
}
First value: horizontal position (left to right)
Second value: vertical position (top to bottom)
Value Type | Description | Examples |
---|---|---|
Keywords | Position by keywords | top , bottom , left , right , center |
Percentages | Percentage positions relative to container | object-position: 25% 75%; |
Length units | Pixels, em, rem, etc. | object-position: 10px 20px; |
object-position: 50% 50%;
— centers the content horizontally and vertically.
img {
object-fit: cover;
object-position: center;
}
img {
object-fit: cover;
object-position: left top;
}
img {
object-fit: cover;
object-position: 30% 70%;
}
img {
object-fit: cover;
object-position: 10px 20px;
}
object-position
?When using object-fit: cover
or contain
, and you want to control which part of the image remains visible.
For cropping images with focus on important areas (like faces).
Adjusting image position inside fixed containers without stretching.
Q1. Center an image with object-position
.
Q2. Align image top-right inside its container.
Q3. Position image 25% from left and 50% from top.
Q4. Use pixels to position image 15px from left and 30px from top.
Q5. Combine object-fit: cover
with object-position: bottom center
.
Q6. Align image to bottom-left corner.
Q7. Use object-position
to show the upper-left quarter of an image.
Q8. Position image using keywords right
and center
.
Q9. Set object-position
to 0 0
(top-left).
Q10. Adjust image position responsively with media queries.
Q1: What does object-position control?
Q2: What is the default value of object-position?
Q3: Which values can be used in object-position?
Q4: If object-fit: cover crops the image, which property controls visible part?
Q5: What does object-position: left bottom; do?
Q6: Can object-position accept two percentage values?
Q7: Which CSS property must be used with object-position to see its effect?
Q8: What does object-position: 0 0; mean?
Q9: Is object-position applicable to background images?
Q10: What unit is NOT valid in object-position?