Last active
February 7, 2022 15:08
-
-
Save gokulkrishh/9ff9c05300634088d8268d255f2783e1 to your computer and use it in GitHub Desktop.
Revisions
-
gokulkrishh revised this gist
Jan 3, 2019 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,14 +53,14 @@ /* Way 4 - Using position: absolute; transform */ .container { position: relative; } .child { position: absolute; transform: translate(-50%, -50%); top: 50%; left: 50%; } /* Way 5 - Using display: table & table-cell */ @@ -71,7 +71,7 @@ .child { background: red; display: table-cell; vertical-align: middle; text-align: center; } -
gokulkrishh created this gist
Jan 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ /* HTML */ <div class="container"> <div class="child"></div> <div> /* Basic Style */ .container { width: 500px; height: 500px; background: #ccc; } .child { background: red; width: 100px; height: 100px; } /* Different ways to make an element horizontal & vertical center */ /* Way 1 - Using position: absolute; */ .container { position: relative; } .child { position: absolute; left: 0; right: 0; bottom: 0; top: 0; margin: auto; } /* Way 2 - Using Flexbox */ .container { display: flex; align-items: center; justify-content: center; } /* Way 3 - Using CSS Grid */ .container { display: grid; place-items: center; } /* Way 4 - Using position: absolute; transform */ .container { position: relative; } .child { position: absolute; transform: translate(-50%, -50%); top: 50%; left: 50%; } /* Way 5 - Using display: table & table-cell */ .container { display: table; } .child { background: red; display: table-cell; vertical-align: middle; text-align: center; }