Skip to content

Instantly share code, notes, and snippets.

@keskinonur
Created February 16, 2024 15:03
Show Gist options
  • Select an option

  • Save keskinonur/259f9598e76c90101f289bf64b024fe8 to your computer and use it in GitHub Desktop.

Select an option

Save keskinonur/259f9598e76c90101f289bf64b024fe8 to your computer and use it in GitHub Desktop.
Centering within the viewport
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Centering within the viewport</title>
<style>
.element {
/*
Thanks https://www.joshwcomeau.com/css/center-a-div/?mc_cid=bd8fb6a12b
*/
position: fixed;
/*
width: 12rem;
height: 5rem;
*/
inset: 0px;
width: fit-content;
height: fit-content;
max-width: 100vw;
max-height: 100dvh;
margin: auto;
background-color: blueviolet;
/*
left: 0px;
right: 0px;
bottom: 8px;
width: 12rem;
max-width: calc(
100vw - 8px * 2
);
margin-inline: auto;
*/
}
</style>
</head>
<body>
<div class="element">
Hello !!
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment