How to make a fixed div element with css ?

2019-09-17 05:52发布

I need to create div element that would always be at the top right corner above all other elements

Here is what I tried

<div id="prompt" style=" height:50px;  width:50px;  background: #F00;  position: fixed;  top: 150px;    margin-left: 948px; z-index: 9999">Test</div>

I need it to work with IE8 , but it is not working.

3条回答
Evening l夕情丶
2楼-- · 2019-09-17 06:25

You need to set left: 0; or use right without margin-left.

查看更多
该账号已被封号
3楼-- · 2019-09-17 06:26

For positioning in the top-right corner: <div id="prompt" style="height:50px; width:50px; background: #F00; position: fixed; top: 150px; right: 0; z-index: 9999">Test</div>

Change the right value as you see fit (i.e. if you want the element an equal distance from the top as it is from the right, make the right value 150px)

查看更多
做个烂人
4楼-- · 2019-09-17 06:27

By removing margin-left: 948px; and adding right: 0px;, your #prompt div will position itself on the right side of the screen in IE 8 and in major browsers as well I believe (Firefox confirmed).

查看更多
登录 后发表回答