gpt-4-0314· openai
Suzhen/CodeChat
how to make div center
- User
how to make div center
- Assistant
To center a div element, you can use various methods such as Flexbox, Grid, or the classic method of margin auto. Here's how you can do it using different CSS techniques:
- Flexbox
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> .container { display: flex; justify-content: center; align-items: center; height: 100vh; } .center { width: 200px; height: 100px; background-color: orangered; } </style> </head> <body> <div class="container"> <div class="center"></div> </div> </body> </html>