Absolute Positioning
Absolute positioning removes an element from the document flow. Situates it at a designated position relative to its nearest positioned ancestor (if any). If no ancestor is positioned it positions it relative to the containing block.
Code Sample:
<!DOCTYPE html> <html> <head> <style> .container { position: relative; width: 300px; height: 200px; background-color: lightgreen; } .absolute-box { position: absolute; top: 50px; right: 50px; width: 100px; height: 50px; background-color: lightsalmon; } </style> </head> <body> <div class="container"> <div class="absolute-box">This box is absolutely positioned.</div> </div> </body> </html> |
Absolute Positioning
Absolute positioning removes an element from the document flow. Situates it at a designated position relative to its nearest positioned ancestor (if any). If no ancestor is positioned it positions it relative to the containing block.
Code Sample:
<!DOCTYPE html> <html> <head> <style> .container { position: relative; width: 300px; height: 200px; background-color: lightgreen; } .absolute-box { position: absolute; top: 50px; right: 50px; width: 100px; height: 50px; background-color: lightsalmon; } </style> </head> <body> <div class="container"> <div class="absolute-box">This box is absolutely positioned.</div> </div> </body> </html> |
Copyrights © 2024 letsupdateskills All rights reserved