1

Guys I am facing a problem: HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>CSS</title>
        <meta http-equiv="author" content="@infinite"><!--Credits-->
        <link rel="stylesheet" type="text/css" href="css.css">
    </head>
    <body>
        <form >
            <input type="submit" value="Submit">
        </form>
    </body>
</html>

CSS:

body{
    background-color:black;
}
form{
    width:500px;
    border:solid 5px white;
}
input[type="submit"]{
    width:200px;
    border:solid 5px white;
    border-radius:50px;
    font-family:Impact,fantasy;
    font-size:300%;
    color:white;
    background-color:inherit;
    margin:300px auto 300px auto;
}

I want to centralize the submit button in the form, but it still sticks to the left side of the form. The "auto" in the margin for the submit button is not working.

Please help..

codetalker
  • 576
  • 1
  • 6
  • 21

4 Answers4

3

Here's a working demo

If you want the margin: 0 auto method to work, the element must be a block, so adding display: block to the submit button does the trick.

Referring from this answer it's good to know that if you want margin: 0 auto to work:

  • The element must display: block
  • The element must not float
  • The element must not have a fixed or absolute position
  • The element must have a width that is not auto
Community
  • 1
  • 1
Sohail
  • 558
  • 1
  • 9
  • 23
0

you can try add this in form:

form{
  width:500px;
  border:solid 5px white;
  text-align: center;
}
step
  • 186
  • 7
0

Try adding the following to the input button's style:

display:block;
Joe Magaro
  • 213
  • 1
  • 14
0

margin: auto; center horizontally only when

  1. Display is block (or table)
  2. Element is not floating
  3. Width should not be auto or 100%

So, to solve your problem, add

input[type="submit"] {
    display: block;
}

as input is displayed inline by default.

Barun
  • 4,245
  • 4
  • 23
  • 29