Bohdan Bohdan
Bohdan Bohdan

Reputation: 51

Can you center the button?

Help me to center the button below

Here is my codepen link.

don't know how to center the button

#form {
        display: grid;
        align-self: flex-start;
        margin: 0 7.5rem;
        width: 50%;
        grid-template-columns: repeat(2, 1fr);
        grid-column-gap: 2rem;
        grid-row-gap: 1.5rem;
        vertical-align: center;
        margin-top: 5rem;
}

Upvotes: 2

Views: 79

Answers (3)

Yuriy Ivanochko
Yuriy Ivanochko

Reputation: 156

Try this one. Add next

HTML: You can create a new div outside of #form:

<div class="button">
  <button type="submit">Отправить</button>
</div> 

CSS:

.button{
   display: flex;
  justify-content:center;
  margin: 0 7.5rem;
     width: 50%;
}

then move your class buttons styles outside of #form

https://codepen.io/juricon/pen/PoYPmOE

Upvotes: 0

Kareem Dabbeet
Kareem Dabbeet

Reputation: 3994

just Edit your button css to make it:

button {
   margin-top: 3rem;
   justify-self: center; /*Center Horizontally*/
   grid-column: 1/3; /*to take 2 columns*/
}

CodePen Demo

Upvotes: 0

davecar21
davecar21

Reputation: 2674

You can try doing this to center the button.

you need to set the grid-column-start and grid-column-end then set justify-self to center so that the button will be centered.

button {
            margin-top: 3rem;
            justify-self: center;
            grid-column-start: 1;
            grid-column-end: 3;
        }

Upvotes: 3

Related Questions