Created
May 20, 2021 09:06
-
-
Save Ankhena/f73247eddd3dfbee510af30988df6e21 to your computer and use it in GitHub Desktop.
Styling the input file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<input id="file" class="visually-hidden" type="file"> | |
<label for="file">Загрузить файл</label> | |
</p> | |
<p> | |
<input id="file2" class="visually-hidden" type="file"> | |
<label for="file2">Загрузить файл</label> | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inputFile = document.querySelectorAll('input[type="file"]'); | |
inputFile.forEach(input => input.addEventListener('input', (e) => { | |
let file = e.target.files[0].name; | |
e.target.nextElementSibling.innerHTML = file; | |
e.target.nextElementSibling.classList.add('success'); | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url('https://fonts.googleapis.com/css2?family=Neucha&display=swap'); | |
* { | |
box-sizing: inherit; | |
} | |
html { | |
box-sizing: border-box; | |
} | |
body { | |
padding: 50px; | |
margin: 0; | |
font-family: 'Neucha', cursive; | |
} | |
.visually-hidden { | |
position: fixed; | |
transform: scale(0); | |
} | |
input[type="file"] + label { | |
display: inline-block; | |
width: 200px; | |
padding: 0.6em 1em; | |
border: none; | |
border-radius: 4px; | |
background: deepskyblue; | |
color: white; | |
font-size: 18px; | |
text-align: center; | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
cursor: pointer; | |
&:hover { | |
background: skyblue; | |
} | |
} | |
.success { | |
background: deeppink; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment