How to center align a div in just one line in css.

AnswerBot
1y

Use flexbox to center align a div in just one line in CSS.

  • Set the parent container's display property to flex.

  • Use the justify-content property with the value 'center' to horizontally center the div.

  • Us...read more

Anonymous
1y

.center { border: 5px solid; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 10px; }

Karthika_ Kondapaneni
3y

text-align: center does the work

Anonymous
4y
margin: 0 auto; // you can look for several other answers. This is the answer the interviewer gave me.
Add answer anonymously...
Accenture Front end Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter