Skip to main content

How to center a div both horizontally and vertically ?(with code)

 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

Popular posts from this blog

Top ways to increase your youtube channel views !

If you want to increase the views of your youtube channel in 2024, Here are some ways ! 1.Make entertaining content Make your content more entertaining and less boring, so that viewers can stay for long and watch your other videos as well. You can do this by adding some animations, improving editing, improving camera quality etc. 2.Make catchy thumbnails Your thumbnail is the most important thing to get more views. If your thumbnail is nice but your is not that much good, you will still get more view. So , make your thumbnail attractive by watching some turtorials on youtube, learning photoediting skills etc. 3.Make titles which create suspense If your viewers do not get curious after watching your title, they will not click on your video, so add some suspense in your titles for the viewers to click your videos. 4.Upload consistently this is the most important part. If you upload your videos consistently, even if they are not good, your views , subscribers and likes all will go up. Bec

when will spacex send people to mars ?

There was no specific timetable for SpaceX's ambitious intentions to carry humans to Mars as of my most recent information update in January 2022.  Elon Musk is the company's leader. Musk has proposed a crewed journey to Mars that might launch in the middle of the 2020s, but there are a number of technological, legal, and financial obstacles that could prevent this from happening.  The precise timescale for SpaceX's development of the Starship spaceship, a crucial element for Mars missions, is yet unknown. For the most recent details on SpaceX's intentions for Mars, check out the company's official website or the most recent news sources.