0

I have a simple form and I just need it centered in the middle of the page. Like, directly square in the middle. But no matter what I change in my CSS file it stays on the left side of the page.

My HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Search</title>
    </head>
    <link rel="stylesheet" href="search.css" type="text/css">
    <body>

        <div>
            <form action="https://google.com/search">
                <input id="search" type="text" name="q">
                <br>
                <input id="button" type="submit" value="Google Search">
            </form>
        </div>

       
    </body>
</html>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
  • For example `form { width: 250px; margin: 0 auto; }` will give the form a width and center it horizontaly in the middle. – bron Jul 13 '21 at 18:29

1 Answers1

0

You can make use of flexbox's align-items property:

body{
  display:flex;
  align-items:center;
  justify-content:center;
  height:100vh;
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Search</title>
    </head>
    <link rel="stylesheet" href="search.css" type="text/css">
    <body>

        <div>
            <form action="https://google.com/search">
                <input id="search" type="text" name="q">
                <br>
                <input id="button" type="submit" value="Google Search">
            </form>
        </div>

       
    </body>
</html>
Spectric
  • 30,714
  • 6
  • 20
  • 43