Skip to content

Instantly share code, notes, and snippets.

@victory-sokolov
Created December 4, 2018 11:31
Show Gist options
  • Save victory-sokolov/16d8d1389abea09735281eba890870eb to your computer and use it in GitHub Desktop.
Save victory-sokolov/16d8d1389abea09735281eba890870eb to your computer and use it in GitHub Desktop.
Some css shortcuts
// disallow select content on the page
.no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/*
* https://github.com/h5bp/html5-boilerplate/blob/v5.0.0/src/css/main.css#L126-L156
*
* Hide only visually, but have it available for screen readers:
* http://snook.ca/archives/html_and_css/hiding-content-for-accessibility
*/
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
/*
* Extends the .visuallyhidden class to allow the element
* to be focusable when navigated to via the keyboard:
* https://www.drupal.org/node/897638
*/
.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}
/* Center elements */
// 1. Center using grid
.container {
display: grid;
height: 100vh;
margin: 0;
place-items: center center;
}
//2. Using Flexbox
html, body, .container {
height: 100%;
}
.container {
display: flex;
align-items: center;
justify-content: center;
}
//3. Using position absolute
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment