HTML Form How to - Restyle input[type=file] control








Question

We would like to know how to restyle input[type=file] control.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.fileContainer {<!--  w  ww . j  a  v a  2 s .  co m-->
  overflow: hidden;
  position: relative;
}

.fileContainer [type=file] {
  cursor: inherit;
  display: block;
  font-size: 999px;
  filter: alpha(opacity = 0);
  min-height: 100%;
  min-width: 100%;
  opacity: 0;
  position: absolute;
  right: 0;
  text-align: right;
  top: 0;
}
.fileContainer {
  background: red;
  border-radius: .5em;
  float: left;
  padding: .5em;
}

.fileContainer [type=file] {
  cursor: pointer;
}
</style>
</head>
<body>
  <label class="fileContainer"> Click here to trigger the file
    uploader! <input type="file" />
  </label>
</body>
</html>

The code above is rendered as follows: