CSS to keep element at "fixed" position on screen

HtmlCss

Html Problem Overview


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 through the document. I'm not sure what the proper term for this is.

It would be like the chat button on Facebook or the Feedback button that is on some websites that follows you throughout the page.

In my situation, I want to keep a div at the absolute bottom-right corner of the screen at all times. Sample CSS appreciated.

Html Solutions


Solution 1 - Html

You may be looking for position: fixed.

Works everywhere except IE6 and many mobile devices.

Solution 2 - Html

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)

Solution 3 - Html

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..

Solution 4 - Html

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

Solution 5 - Html

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

Solution 6 - Html

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.

Solution 7 - Html

Try this one:

p.pos_fixed {
    position:fixed;
    top:30px;
    right:5px;
}

Solution 8 - Html

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

Solution 9 - Html

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!

Solution 10 - Html

#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.

Solution 11 - Html

HTML

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

CSS

#fixedbtn{
 position: fixed;
 margin: 0px 10px 0px 10px;
 width: 10%;
}

Solution 12 - Html

You can try this code:

<div style="top: 0; position: sticky;">your code</div>

or you can add class/id like this:

html:

<div class="FixedPosition">your code</div>

css:

.FixedPosition{
 position: sticky;
 top: 0;
}

you may change the "top" if you want it to not be on top of the screen and don't delete the top else it won't work.

I hope this help : )

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMikeView Question on Stackoverflow
Solution 1 - HtmlPekkaView Answer on Stackoverflow
Solution 2 - HtmlmreqView Answer on Stackoverflow
Solution 3 - HtmlSrinivas08View Answer on Stackoverflow
Solution 4 - HtmlHermes NguyenView Answer on Stackoverflow
Solution 5 - HtmlRobert F Wainblat IIIView Answer on Stackoverflow
Solution 6 - Htmlsg3sView Answer on Stackoverflow
Solution 7 - HtmlAltaf PatelView Answer on Stackoverflow
Solution 8 - HtmlrealshadowView Answer on Stackoverflow
Solution 9 - HtmldgsinclairView Answer on Stackoverflow
Solution 10 - HtmlChambah RussellView Answer on Stackoverflow
Solution 11 - HtmlRana AalamgeerView Answer on Stackoverflow
Solution 12 - HtmlAyden CheongView Answer on Stackoverflow