为图像和视频设置上传按钮的样式

时间:2017-12-24 22:19:28

标签: javascript html css

我试图按照这些方式设置input的样式:

Example

有没有办法像这样设置input

 <input id="fileupload" class="file-upload" name="media" type="file">

.file-upload {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0px;
  left: 0px;
  opacity: 0;
}

.file-upload-input {
  display: none;
}

2 个答案:

答案 0 :(得分:1)

试试这个

<input id="fileupload" name="media" type="file">
<label for="file" class="file-upload">Choose a file</label>

<style>
#fileupload {
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}
.file-upload {
  font-size: 20px;
  font-family: sans-serif;
  color: #fff;
  border-radius: 7px;
  padding: 10px 20px;
  background: #bd1a59;
}
.file-upload-input {
  display: none;
}
</style>

答案 1 :(得分:0)

实时示例:

#fileupload {
  opacity: 0;
  position: absolute;
}
.file-upload {
  color: white;
  width: 326px;
  padding: 13px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  border-radius: 8px;
  background: #ff4279;
  display: inline-block;
  font-family: sans-serif;
}
<input id="fileupload" name="media" type="file">
<label for="file" class="file-upload">Choose a File</label>


参考: