CSS to keep element at “fixed” position on screen

后端 未结 11 1398
旧巷少年郎
旧巷少年郎 2020-12-04 23:22

I\'m looking for a trick to create a \"fixed\" HTML object on the browser screen using CSS. I want it to stay in the same position all the time, even when the user scrolls t

相关标签:
11条回答
  • 2020-12-05 00:01

    Make sure your content is kept in a div, say divfix.

    <div id="divfix">Your Code goes here</div>
    

    CSS :

    #divfix {
           bottom: 0;
           right: 0;
           position: fixed;
           z-index: 3000;
    }
    

    Hope ,It will help you..

    0 讨论(0)
  • 2020-12-05 00:06

    You may be looking for position: fixed.

    Works everywhere except IE6 and many mobile devices.

    0 讨论(0)
  • 2020-12-05 00:08

    In order to keep floating text in the same location over an image when changing browser zoom, I used this CSS:

    position: absolute;
    margin-top: -18%
    

    I think the % instead of fixed pixels is what does it. Cheers!

    0 讨论(0)
  • 2020-12-05 00:11
    position: sticky;
    

    The sticky element sticks on top of the page (top: 0) when you reach its scroll position.

    See example: https://www.w3schools.com/css/tryit.asp?filename=trycss_position_sticky

    0 讨论(0)
  • 2020-12-05 00:13

    The easiest way is to use position: fixed:

    .element {
      position: fixed;
      bottom: 0;
      right: 0;
    }
    

    http://www.w3.org/TR/CSS21/visuren.html#choose-position

    (note that position fixed is buggy / doesn't work on ios and android browsers)

    0 讨论(0)
提交回复
热议问题