Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove fixed position of a DIV for all mobile devices?

I have a DIV that is fixed positioned, but I would like it to be relative when viewed by mobile devices. Is this possible with a specific css?

Erik

like image 437
Erik Avatar asked Dec 19 '12 23:12

Erik


People also ask

How do you handle position fixed inside a div?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.

How do I move a fixed position in CSS?

Fixed Positioning You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.

What is the difference between position fixed and sticky?

A sticky element toggles between relative and fixed , depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).


1 Answers

You can use media queries to do this.

CSS

div {
    position: fixed;
}

@media only screen and (max-device-width : 480px) {
    div {
        position: relative;
    }
}
​
like image 109
3dgoo Avatar answered Sep 26 '22 04:09

3dgoo