CSS Right property
Right property in CSS?
The right property is used to set the right position of a positioned element.
It works in conjunction with the position property.
Relative Positioning with Right:
div {
position: relative;
right: 20px; /* Move 20 pixels to the left from its normal position */
}
This example positions the div element 20 pixels to the left of its normal position within the document flow.
Absolute Positioning with Right:
div {
position: absolute;
right: 50px; /* Position 50 pixels to the left of the nearest positioned ancestor */
}
In this example, the div element is positioned 50 pixels to the left of its nearest positioned ancestor.
Fixed Positioning with Right:
div {
position: fixed;
right: 0; /* Fixed to the right edge of the viewport */
}
The div element is fixed to the right edge of the viewport. It will stay in the same position even when the page is scrolled.
Percentage Values:
div {
position: relative;
right: 10%; /* Move 10% of the containing element's width to the left */
}
This example moves the div element 10% of its containing element's width to the left.
Negative Values:
div {
position: relative;
right: -30px; /* Move 30 pixels to the right of its normal position */
}
Negative values for right will move the element to the right of its normal position.
Combining with Other Properties:
div {
position: absolute;
top: 50px;
right: 20px;
}
This instance blends with both the top and right attributes to position the element 50 pixels from the highest part of the page and 20 pixels to the left of the nearest placed up element.