Ask Your Question
0

How can I center a button using CSS if it is not movable?

asked 2022-07-21 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-09-02 17:00:00 +0000

devzero gravatar image

If a button cannot be moved with CSS, you can try the following steps to center it:

  1. Set the button's display property to "block" or "inline-block".
  2. Set the left and right margins of the button to "auto".
  3. Set the width of the button if necessary.

For example, if your button has the class "my-button", you would use the following CSS:

.my-button {
  display: block;
  margin: 0 auto;
  /* optional, set the width of the button */
  width: 150px;
}

This will center the button horizontally within its parent element. If you also want to center it vertically, you can use flexbox or other techniques.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-07-21 11:00:00 +0000

Seen: 12 times

Last updated: Sep 02 '22