Skip to content

Instantly share code, notes, and snippets.

@IgorKurkov
Created February 12, 2018 00:40
Show Gist options
  • Save IgorKurkov/cfe5aaa70e8b9682f96d206d21b4aadf to your computer and use it in GitHub Desktop.
Save IgorKurkov/cfe5aaa70e8b9682f96d206d21b4aadf to your computer and use it in GitHub Desktop.

Revisions

  1. IgorKurkov created this gist Feb 12, 2018.
    8 changes: 8 additions & 0 deletions set absolute element to center
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    .child {
    position: absolute;
    top: 50%; /* position the top edge of the element at the middle of the parent */
    left: 50%; /* position the left edge of the element at the middle of the parent */

    transform: translate(-50%, -50%); /* This is a shorthand of
    translateX(-50%) and translateY(-50%) */
    }