show name of file on custom input field - html

i am using a custom file input on an upload page on my website and it is working as per my requirement the only issue is i have hidden the default layout of filetype="input" but i want to show the name of the file being uploaded so that the user may know which file he has uploadedand the name of the file here's the fiddle
JsFiddle
here's the html and css
<div class="custom-upload">
<div class="fake-file">
<input placeholder="Choose File" type="file" name="fileToUpload" id="fileToUpload" />
</div>
</div>
.custom-upload {
position: relative;
height: 40px;
width: 100%;
margin-top: 20px;
border-bottom: 1px solid #625f5b;
}
.custom-upload input[type=file]
{
outline:none;
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
width:100%;
height:100%;
}
.custom-upload .fake-file
{
background:url(https://s4.postimg.org/hy3g354ot/upload.png) center right no-repeat;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
padding: 0;
margin: 0;
z-index: 1;
line-height: 100%;
}
.custom-upload .fake-file input
{
font-size:16px;
height:40px;
width: 100%;
}

Look at the JavaScript I added.
Note: I used jQuery. If you are using native JavaScript, I have to change the code
$(function(){
$("#fileToUpload").on('change',function(){
fpath = $(this).val();
$('#filePath').html('<b>You selected the file:</b> ' + fpath);
});
});
.custom-upload {
position: relative;
height: 40px;
width: 100%;
margin-top: 20px;
border-bottom: 1px solid #625f5b;
}
.custom-upload input[type=file]
{
outline:none;
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
width:100%;
height:100%;
}
.custom-upload .fake-file
{
background:url(https://s4.postimg.org/hy3g354ot/upload.png) center right no-repeat;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
padding: 0;
margin: 0;
z-index: 1;
line-height: 100%;
}
.custom-upload .fake-file input
{
font-size:16px;
height:40px;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="custom-upload">
<div class="fake-file">
<input placeholder="Choose File" type="file" name="fileToUpload" id="fileToUpload" />
</div>
<div id="filePath">
</div>
</div>

Another choise could be without using jquery, but pure javascript. This is my solution.
<span id='filename'></span>
<div class="custom-upload">
<div class="fake-file">
<input placeholder="Choose File" type="file" name="fileToUpload" id="fileToUpload" />
</div>
</div>
<script>
document.getElementById('fileToUpload').addEventListener('change', function() {
var dest = document.getElementById('filename');
dest.innerHTML = document.getElementById('fileToUpload').value;
});
</script>
I let you the personalization of css of the elements to fit your needs.
Hope this help.

Related

Google Contact Form Animation?

How would I go about implementing the onclick animation seen on this Google login form?
As you click the button box, the placeholder text shrinks and moves to the top left and the button border forms around the text.
https://accounts.google.com/v3/signin/identifier?dsh=S906398310%3A1668018211534020&flowName=GlifWebSignIn&flowEntry=ServiceLogin&ifkv=ARgdvAv8SiraKrw6QlE0WDM_jQ_IMyyYjxsvr8JLQ_L2BGzFth9-H3ZsW5aunSdhTVq1iMWqAgCTtg
With pure CSS I would approach it like that:
<style>
input:focus ~ .floating-label,
input:not(:focus):valid ~ .floating-label{
top: -6px;
left: 0.5rem;
padding: 0.5rem;
font-size: 11px;
opacity: 1;
}
.inputText {
font-size: 14px;
width: 200px;
height: 35px;
outline: 1px!important;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 1rem;
transform: translateY(-50%);
top: 50%;
background: white;
transition: 0.2s ease all;
}
</style>
<div style="position:relative; display:inline;">
<input type="text" class="inputText" required/>
<span class="floating-label">Your email address</span>
</div>
That isn't a placeholder. Its just a label sitting absolute above an input field. There are 2 options.
First one is only html and css. But it only works if all input fields are required. So you cant send the formular if one is empty.
<style>
.wrapper {
width: 100%;
height: 50vh;
display: flex;
justify-content: center;
align-items: center;
}
.wrapper .your-label {
position: absolute;
}
#input:focus ~ .your-label,
#input:valid ~ .your-label {
background-color: yellow;
color: blue;
transform: translateY(-1rem);
scale: 0.8;
}
</style>
<body>
<div class="wrapper">
<input id="input" type="text" required />
<label class="your-label" for="input">Your Text</label>
</div>
</body>
Second one would be with js and you are able to send also forms that are empty.
<style>
.wrapper {
width: 100%;
height: 50vh;
display: flex;
justify-content: center;
align-items: center;
}
.wrapper .your-label {
position: absolute;
}
.your-label.active {
background-color: yellow;
color: blue;
transform: translateY(-1rem);
scale: 0.8;
}
</style>
<body>
<div class="wrapper">
<input id="input" type="text" />
<label class="your-label" for="input">Yourt Text</label>
</div>
</body>
<script>
const form_input = document.querySelectorAll("#input");
form_input.forEach((e) => {
e.addEventListener("focus", () => {
e.nextElementSibling.classList.add("active");
});
e.addEventListener("blur", () => {
if (e.value === "") {
e.nextElementSibling.classList.remove("active");
} else {
e.nextElementSibling.classList.add("active");
}
});
});
</script>

Best practice for an animated image gallery with CSS

I'm trying to do a photo gallery. I have this code:
<head>
<style>
.thumb {
max-height: 171px;
border: solid 6px rgba(5, 5, 5, 0.8);
}
.box {
position: fixed;
z-index: 999;
height: 0;
width: 0;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
opacity: 0;
}
.box img {
max-width: 90%;
max-height: 80%;
margin-top: 2%;
}
.box:target {
outline: none;
width: 100%;
height: 100%;
opacity: 1;
}
.box:target img {
border: solid 17px rgba(77, 77, 77, 0.8);
}
.light-btn {
color: #fafafa;
background-color: #333;
border: solid 3px #777;
padding: 5px 15px;
border-radius: 1px;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
position: absolute;
top: 45%;
z-index: 99;
}
.light-btn:hover {
background-color: #111;
}
.btn-close {
position: absolute;
right: 2%;
top: 2%;
color: #fafafa;
background-color: #92001d;
padding: 10px 15px;
border-radius: 1px;
text-decoration: none;
}
.btn-close:hover {
background-color: #740404;
}
</style>
</head>
<body>
<img class="thumb" src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<img class="thumb" src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
<img class="thumb" src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
<div class="box" id="img1">
prev
X
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
next
</div>
<div class="box" id="img2">
prev
X
<img src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
next
</div>
<div class="box" id="img3">
prev
X
<img src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
next
</div>
</body>
But I want to add animation. I want the photos to come from the left when I click on "next" and from the right when I click on "prev", like a slider.
Is it possible to achieve it with CSS? For example with transform property? If not what script should I use?
You can do something like this with radio buttons. If you have a radio button at the top for each transition you want to make, you can use CSS to select on every radio button there is and add the CSS transitions as needed. Use <label>s instead of <a>s to check the radio buttons, and then make the actual radio buttons invisible. But this would take a lot of code and wouldn't scale very well. So if you plan on having more images, you have to add CSS for each on individually, which can be a lot of work.
Here is a quick example putting the images into a reel and sliding the whole thing side to side. It may not be exactly what you want, but it is much less code. It's at least a good starting place.
<head>
<style>
.thumb {
max-height: 171px;
border: solid 6px rgba(5, 5, 5, 0.8);
}
.reel-wrapper {
position: fixed;
z-index: 999;
height: 0;
width: 0;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
opacity: 0;
overflow: hidden;
}
.reel {
position: absolute;
width: auto;
height: auto;
display: flex;
transition: left 1s ease-in-out;
}
#radio-close:not(:checked) ~ .reel-wrapper {
outline: none;
width: 100%;
height: 100%;
opacity: 1;
}
.box {
position: relative;
width: 100vw;
height: 100vh;
}
.box img {
max-width: 90%;
max-height: 80%;
margin-top: 2%;
border: solid 17px rgba(77, 77, 77, 0.8);
}
input[type="radio"] {
display: none;
}
#radio-img1:checked ~ .reel-wrapper .reel {
left: 0;
}
#radio-img2:checked ~ .reel-wrapper .reel {
left: -100vw;
}
#radio-img3:checked ~ .reel-wrapper .reel {
left: -200vw;
}
.light-btn {
color: #fafafa;
background-color: #333;
border: solid 3px #777;
padding: 5px 15px;
border-radius: 1px;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
position: absolute;
top: 45vh;
z-index: 99;
}
.light-btn:hover {
background-color: #111;
}
.btn-close {
position: absolute;
right: 2%;
top: 2%;
color: #fafafa;
background-color: #92001d;
padding: 10px 15px;
border-radius: 1px;
text-decoration: none;
}
.btn-close:hover {
background-color: #740404;
}
.btn-prev {
left: 5vw;
}
.btn-next {
right: 5vw;
}
</style>
</head>
<body>
<input id="radio-close" type="radio" name="gallery-nav" checked>
<input id="radio-img1" type="radio" name="gallery-nav">
<input id="radio-img2" type="radio" name="gallery-nav">
<input id="radio-img3" type="radio" name="gallery-nav">
<label for="radio-img1"><img class="thumb" src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80"></label>
<label for="radio-img2"><img class="thumb" src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80"></label>
<label for="radio-img3"><img class="thumb" src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80"></label>
<div class="reel-wrapper">
<div class="reel">
<div class="box" id="img1">
<label for="radio-img3" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<label for="radio-img2" class="light-btn btn-next">next</label>
</div>
<div class="box" id="img2">
<label for="radio-img1" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
<label for="radio-img3" class="light-btn btn-next">next</label>
</div>
<div class="box" id="img3">
<label for="radio-img2" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
<label for="radio-img1" class="light-btn btn-next">next</label>
</div>
</div>
</div>
</body>
Typically this kind of thing would be easier to do with JavaScript. You could just keep track of which image you are looking at, and then on clicking a button toggle the right classes to make CSS do the actual animation. It is much easier to manage for scale. But pure CSS solutions are always more fun.

Increase HTML Button Font size without altering button size

The issue I am having is that when I change the size of the font in my button, the button then resizes. As of now, I would like to keep the buttons at one specific size. So, I have fixed my buttons to a specific size but now I cannot change the font size. I am currently running my program on Chrome.
Here is the HTML chunk:
<div class="file-input-wrapper">
<button class="btn-file-input">Upload Documents</button>
<input type="file" name="filesToUpload[]" id="filesToUpload" multiple="" onChange="makeFileList();" />
</div>
<p>
<strong>Files You Selected:</strong>
<ul id="fileList">
<li>No Files Selected</li>
</ul>
<div class="file-input-wrapper1">
<button class="btn-file-input1">Upload Documents</button>
<input type="submit" value="Upload!" />
</div>
</p>
<style type="text/css">
.file-input-wrapper {
width: 400px;
height: 125px;
overflow: hidden;
position: relative;
}
.file-input-wrapper>input[type="file"] {
font-size: 200px;
position: absolute;
top: 0;
right: 0;
opacity: 0;
}
.file-input-wrapper>.btn-file-input {
display: inline-block;
width: 400px;
height: 125px;
}
.file-input-wrapper:hover>.btn-file-input {
background-color: #aaa;
}
.file-input-wrapper1 {
width: 400px;
height: 125px;
overflow: hidden;
position: relative;
}
.file-input-wrapper1>input[type="submit"] {
font-size: 200px;
position: absolute;
top: 0;
right: 0;
opacity: 0;
}
.file-input-wrapper1>.btn-file-input1 {
display: inline-block;
width: 400px;
height: 125px;
}
.file-input-wrapper1:hover>.btn-file-input1 {
background-color: #ffff00;
}
</style>
You can set the button font size with the following:
button {
font-size: 40px;
}
Since your buttons have a defined height and width, it should not change their dimensions.
Add an additional class to all your buttons. Even if you have some "buttons" that are not actually buttons, but instead input type="submit" or input type="button", add this class to all of those things.
Then do this in your CSS:
.some_class_added_to_all_buttons{
width: some-width;
height: some-height;
font-size: some-font-size;
}
if you have a button that already has a class, add an additional one like this
<button class="btn-file-input1 additional_class">Upload Documents</button>

elements don't shine through overlay

I want to create an overlay, which is shown, when an edit button is clicked. Only the edit fields should be visible through the overlay.
I have this div at the end of my html:
<div class='overlay closed'></div>
with following css:
.closed
{
display: none;
}
.overlay {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: black;
opacity: 0.3;
z-index: 70;
}
This correctly shows an overlay over the website.
I have several forms, which should be accesible while the overlay is visible.
For example:
<div class='edit-container closed'>
<form action="#" method='post'>
<textarea></textarea>
<input type='submit' value="safe" />
<input type='reset' value='cancel' />
</form>
</div>
i have tried following css to put those divs over the overlay:
#content.project .edit-container {
z-index: 71;
}
#content.project .edit-container * {
z-index: 71;
}
Can you tell me why, or what I am doing wrong?
Thanks in advance.
You need a position:relative; on edit-container
http://jsfiddle.net/hwh0nnxo/
HTML
<div class='edit-container'>
<form action="#" method='post'>
<textarea></textarea>
<input type='submit' value="safe" />
<input type='reset' value='cancel' />
</form>
</div>
<div class='overlay'></div>
CSS
.closed {
display: none;
}
.overlay {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: black;
opacity: 0.3;
z-index: 70;
}
.edit-container{
position: relative;
z-index: 71;
}

Customized <input type=“file”>?

I need to add in my form a few customized <input type=“file”>
I tried to use this code
<div id="upload-file-container">
<input type="file" name="pic[]" class="photo" value="Add photo" />
</div>
CSS
#upload-file-container {
position: relative;
width: 50px;
height: 20px;
overflow: hidden;
}
#upload-file-container input {
position: absolute;
left: 0;
top: 0;
font-size: 20px;
opacity: 0;
margin: 0;
padding: 0;
border: none;
width: 50px;
height: 20px;
}
but my inputs just became invisible.
http://jsfiddle.net/FXTCg/4/
How to make visible input title "Add photo"?
take a look at this: http://jsfiddle.net/gabrieleromanato/mxq9R/ . Your input need to be invisible opacity: 0 becuase you cannot apply any style or custom text in it. You need to put your visible content underneath it