News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Following CSS code not centering my button horizontally within a div element?

Started by Mark011, August 18, 2023, 04:15:35 AM

Previous topic - Next topic

Mark011

Why is the following CSS code not centering my button horizontally within a div element? It appears off-center on my webpage:

<!DOCTYPE html>
<html>
<head>
<style>
  .container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .btn {
    background-color: #3498db;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
  }
</style>
</head>
<body>

<div class="container">
  <button class="btn">Click Me</button>
</div>

</body>
</html>

The button seems to be slightly toward the left side within the container. What am I missing in the CSS that is preventing the button from being perfectly centered?

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: