Problem:
A user seeks to create a button that maintains a fixed vertical distance from the viewport while also remaining a specific distance from the right edge of a div, regardless of viewport size.
Solution:
Horizontal Positioning:
While "absolute horizontal" positioning is not technically achievable with the provided solution, the goal of maintaining a fixed distance from the div's right edge can be met. By avoiding setting the left or right properties for the horizontally fixed element, the container divs are used to control its horizontal position.
Vertical Positioning:
The element is positioned vertically fixed using the position: fixed property. By setting a top value, the vertical positioning is maintained regardless of the viewport size.
Code Sample:
The following code demonstrates the implementation:
HTML:
<body> <div class="inflow"> <div class="positioner"> <div class="fixed"></div> </div> </div> </body>
CSS:
div.inflow { width: 200px; height: 1000px; border: 1px solid blue; float: right; position: relative; margin-right: 100px; } div.positioner {position: absolute; right: 0;} div.fixed { width: 80px; border: 1px solid red; height: 100px; position: fixed; top: 60px; margin-left: 15px; }
Key Considerations:
The above is the detailed content of How to Vertically Fix and Horizontally Position an Element Relative to a Div?. For more information, please follow other related articles on the PHP Chinese website!