Position fixed element in bottom right corner of page with CSS3

Fidel90

My page has a max width of 1280px. The body is centered on larger screens using margin: 0 auto; Now I want to place an element in the bottom right corner. That has to be fixed as it should scroll with the content. On screens larger than 1280px the element should stay on the corner of the centered body and not stick to the right side of the window.

The element should stick there, independent of the current viewport width.

I've solved this by using a combination of media-query and CSS3-calc operation. It feels like an overkill for this simple task but I can't find a solution simpler as mine. Here is some sample css (I've changed the maximum page width to 500px here):

body {
    max-width: 500px;
    height: 1000px;
    margin: 0 auto;
    padding: 0;
    border: 1px solid black;
}

div {
    position: fixed;
    right: 0;
    bottom: 0;
    height: 30px;
    width: 30px;
    margin: 0;
    padding: 0;
    background-color: red;
}

@media all and (min-width: 515px) /*max body width + (element width / 2)*/ {
    div {    
        margin-right: -webkit-calc((100% - 500px) / 2);
        margin-right: -moz-calc((100% - 500px) / 2);
        margin-right: calc((100% - 500px) / 2);
    }
}

JSFiddle: https://jsfiddle.net/nh95dc8u/

My JSFiddle shows exactly what I want. I'm just asking if this is possible to achieve with more "standard-CSS" (I'm not really sure about calc across different browsers)? What could be a simpler solution?

Julia
@media all and (min-width: 515px) {
    div {    
        right: 50%;
        margin-right: -250px;
  }

Moves fixed div to 50% of window width and then to 50% of container width https://jsfiddle.net/nh95dc8u/5/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to position to bottom right corner without overlapping

From Dev

css: how to position a X sign at the top right corner of the img element

From Dev

the position of overlay is bottom right of page

From Dev

bootstrap fixed button in window right bottom corner with bootstrap

From Dev

CSS: aligning two divs to the bottom of the page on the right side with position: absolute

From Dev

(CSS) How to position the Div near to the bottom right corner of the browser Relatively to the Browser Size?

From Dev

How to add fixed button to the bottom right of page

From Dev

How to position the GWT dialog to the bottom right corner of the browser?

From Dev

half borders at top right corner and bottom left corner with css

From Dev

Css position corner absolute bottom left

From Dev

CSS background-position top right corner

From Dev

How to position a child element at the bottom of a fixed position parent

From Dev

Position fixed element within fixed element relative to page

From Dev

stick a image to the bottom right corner

From Dev

Move form to bottom right corner

From Dev

Extjs button on the bottom right corner

From Dev

Put TextView on right bottom corner

From Dev

Moving an div from the top left corner to bottom right using css

From Dev

bottom left corner shading effect in css or css3

From Dev

How to position an element at the bottom of the screen on load but not make it fixed?

From Dev

Set multiple div elements to "position: fixed" at the bottom of a page

From Dev

css3 transform reverts position: fixed

From Dev

css3 transform reverts position: fixed

From Dev

How to set a div's position inside another div to bottom right corner?

From Dev

CSS3 skew only top right corner

From Dev

Footer not fixed to the bottom of the page

From Dev

Why is my nav bar with 'position:fixed' displaying at bottom of web page not bottom of viewport on mobile?

From Dev

CSS: position div at the bottom of parent element?

From Dev

CSS rotate and position to bottom left of page

Related Related

  1. 1

    How to position to bottom right corner without overlapping

  2. 2

    css: how to position a X sign at the top right corner of the img element

  3. 3

    the position of overlay is bottom right of page

  4. 4

    bootstrap fixed button in window right bottom corner with bootstrap

  5. 5

    CSS: aligning two divs to the bottom of the page on the right side with position: absolute

  6. 6

    (CSS) How to position the Div near to the bottom right corner of the browser Relatively to the Browser Size?

  7. 7

    How to add fixed button to the bottom right of page

  8. 8

    How to position the GWT dialog to the bottom right corner of the browser?

  9. 9

    half borders at top right corner and bottom left corner with css

  10. 10

    Css position corner absolute bottom left

  11. 11

    CSS background-position top right corner

  12. 12

    How to position a child element at the bottom of a fixed position parent

  13. 13

    Position fixed element within fixed element relative to page

  14. 14

    stick a image to the bottom right corner

  15. 15

    Move form to bottom right corner

  16. 16

    Extjs button on the bottom right corner

  17. 17

    Put TextView on right bottom corner

  18. 18

    Moving an div from the top left corner to bottom right using css

  19. 19

    bottom left corner shading effect in css or css3

  20. 20

    How to position an element at the bottom of the screen on load but not make it fixed?

  21. 21

    Set multiple div elements to "position: fixed" at the bottom of a page

  22. 22

    css3 transform reverts position: fixed

  23. 23

    css3 transform reverts position: fixed

  24. 24

    How to set a div's position inside another div to bottom right corner?

  25. 25

    CSS3 skew only top right corner

  26. 26

    Footer not fixed to the bottom of the page

  27. 27

    Why is my nav bar with 'position:fixed' displaying at bottom of web page not bottom of viewport on mobile?

  28. 28

    CSS: position div at the bottom of parent element?

  29. 29

    CSS rotate and position to bottom left of page

HotTag

Archive