To center a div both horizontally and vertically, we use flex.
if you want the full code , here it is :
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
margin: 0;
overflow: hidden;
}
#centered{
width: 100;
height: 99vh;
display: flex;
justify-content: center;
align-items: center;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>yt</title>
</head>
<body>
<script src="yt.js"></script>
<div id="centered"><div id="centre">centered</div></div>
</body>
</html>
now, in this code, the main three lines of code is this :
display: flex;
justify-content: center;
align-items: center;
------------------------------------------------
you would need to add the above given code into the css of the parent div.
here is how it would look without using the above three lines :
Thanks for reading
Comments
Post a Comment