Skip to main content

how to center a div horizontlly and verticaly in html

 You can use CSS Flexbox or Grid to center a <div> both horizontally and vertically. This is a short Flexbox example:.

.center-div {

  display: flex;

  justify-content: center; /* Horizontally center */

  align-items: center; /* Vertically center */

  height: 100vh; /* Ensures it covers the entire viewport height */

}


All you have to do is give your <div> the center-div class. The flex container created by this code aligns its child both horizontally and vertically. Once the height is adjusted as necessary, your <div> will be centered. By utilizing place-items: center and display: grid, you may use CSS Grid to get a similar effect.

Comments

Popular posts from this blog

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.

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 > </ ...

How to increase subscribers on youtube ?

 Growing your subscribers on YouTube takes time and effort. Here are some strategies to help you increase your subscriber count: 1. **Create High-Quality Content:**    - Your content is the most critical factor. Create videos that are interesting, valuable, and well-produced. High-quality content is more likely to be shared and subscribed to. 2. **Consistent Upload Schedule:**    - Upload videos regularly and maintain a consistent schedule. This helps your audience know when to expect new content from you. 3. **Engage with Your Audience:**    - Respond to comments on your videos. Engage with your audience through likes, comments, and community posts. Building a community around your channel can encourage people to subscribe. 4. **Optimize Video Titles and Thumbnails:**    - Use compelling and descriptive video titles. Create eye-catching thumbnails that accurately represent the content of your video. This can increase click-through rates. 5. ...