-5

How to center it horizontally on the page using css

I have used a div and used margin:auto , but it does not work.

#up {
  margin: auto;
  display: block;
}
<div id="up">
  <input type="file" name="fileToUpload" id="fileToUpload">
</div>
web-tiki
  • 99,765
  • 32
  • 217
  • 249
Semi Developer
  • 151
  • 1
  • 1
  • 10

1 Answers1

1

This is duplicate question, however:

You want the input to be centered? Then add text-align:center; to the container div.

#up { margin: auto; display:block; }
#up { border: 1px solid blue; }

#alignCenter {text-align:center;}
#alignCenter {border:1px solid purple;}

/* To illustrate what is happening */
#fileToUpload {background:red;}
<div id="up">
  <input type="file" name="fileToUpload" id="fileToUpload">
</div>

<div id="alignCenter">
  <input type="file" name="fileToUpload" id="fileToUpload">
</div>
S.Kiers
  • 4,086
  • 3
  • 32
  • 38