CSS to keep element at “fixed” position on screen

后端 未结 11 1397
旧巷少年郎
旧巷少年郎 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-04 23:49

    The tweak:

    position:fixed; 
    

    works, but it breaks certain options....for example a scrollable menu that is tagged with a fixed position will not expand with the browser window anymore...wish there was another way to pin something on top/always visible

    0 讨论(0)
  • #fixedbutton {
        position: fixed;
        bottom: 0px;
        right: 0px; 
        z-index: 1000;
    }
    

    The z-index is added to overshadow any element with a greater property you might not know about.

    0 讨论(0)
  • 2020-12-04 23:51

    Try this one:

    p.pos_fixed {
        position:fixed;
        top:30px;
        right:5px;
    }
    
    0 讨论(0)
  • 2020-12-04 23:53

    position: fixed;

    Will make this happen.

    It handles like position:absolute; with the exception that it will scroll with the window as the user scrolls down the content.

    0 讨论(0)
  • 2020-12-04 23:53

    HTML

    <div id="fixedbtn"><button type="button" value="Delete"></button></div>
    

    CSS

    #fixedbtn{
     position: fixed;
     margin: 0px 10px 0px 10px;
     width: 10%;
    }
    
    0 讨论(0)
  • 2020-12-04 23:57

    You can do like this:

    #mydiv {
        position: fixed; 
        height: 30px; 
        top: 0; 
        left: 0; 
        width: 100%; 
    }
    

    This will create a div, that will be fixed on top of your screen. - fixed

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