将div与右侧的固定位置对齐 [英] Align div with fixed position on the right side

查看:132
本文介绍了将div与右侧的固定位置对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要显示一个 div ,即使用户滚动页面也始终可见。我已经使用CSS position:fixed;

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.

现在我还想显示 div 在父母 div 的右手角落。

Now I also want to show the div at the right hand corner of the parent div.

尝试使用此CSS代码实现目标:

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.

我的示例页面可以在这里 div 元素我想对齐在父类下调用 test / code>。

My example page can be found here, the div element I want to align is called test under the parent class parent.

有没有任何CSS或JavaScript解决方案来对齐屏幕右侧的固定位置元素?

Is there any CSS or JavaScript solution to aligning the fixed position element on the right side of the screen?

推荐答案

在位置固定的情况下,您需要提供值来设置div的放置位置,
是因为它是 >位置。

With position fixed, you need to provide values to set where the div will be placed, since it's a fixed position.

有点像....

.test
{
   position:fixed;
   left:100px;
   top:150px;
}

修复 - 生成绝对定位的元素相对于浏览器窗口。元素的位置由left,top,right和bottom属性指定

Fixed - Generates an absolutely positioned element, positioned relative to the browser window. The element's position is specified with the "left", "top", "right", and "bottom" properties

更多位置此处

这篇关于将div与右侧的固定位置对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆