Jump to content

Why is the following CSS code not centering my button horizontally within a div element?


Techi11
 Share

Recommended Posts

Why is the following CSS code not centering my button horizontally within a div element? It appears off-center in 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 towards the left side within the container. What am I missing in the CSS that is preventing the button from being perfectly centered?

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...