I want to show a div
which is always visible even as the user scrolls the page. I have used the CSS position: fixed;
for that.
Now I also want to show the div
at the right hand corner of the parent div
.
I tried to use this CSS code to achieve the goal:
.test { position: fixed; text-align: right; }
But it doesn't align the element on the right side.
My example page can be found here, the div
element I want to align is called test
under the parent class parent
.
Is there any CSS or JavaScript solution to aligning the fixed position element on the right side of the screen?
To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property text-align for the center, left and right alignment.
You can use two imbricated div. But you need a fixed width for your content, that's the only limitation.
<div style='float:right; width: 180px;'> <div style='position: fixed'> <!-- Your content --> </div> </div>
Use the 'right' attribute alongside fixed position styling. The value provided acts as an offset from the right of the window boundary.
Code example:
.test { position: fixed; right: 0; }
If you need some padding you can set right
property with a certain value, for example: right: 10px
.
Note: float
property doesn't work for position fixed
and absolute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With