How can You horizontally center an element?
Ankit Verma

Ankit Verma @ankitvermaonline

About: Full Stack Developer 7+ years of experience in Web development, specializing in PHP frameworks.

Location:
Lucknow
Joined:
Sep 18, 2023

How can You horizontally center an element?

Publish Date: Feb 27
0 0

With flex it is very easy to style the div horizontally and vertically centered.

#centered {  
  border: 0.05em solid black;
}

#main {
  border: 0.05em solid red;
  width:100%;
  display: flex;
  justify-content: center;
}
Enter fullscreen mode Exit fullscreen mode
<div id="main">
  <div id="centered">Foo foo</div>
</div>
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment