Using label to style File Input

Developer
Size
2,646 Kb
Views
14,168

How do I make an using label to style file input?

What is a using label to style file input? How do you make a using label to style file input? This script and codes were developed by Jesper Hills on 13 October 2022, Thursday.

Using label to style File Input Previews

Using label to style File Input - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Using label to style File Input</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ /* Basics */
body { background: #eee; padding: 5em;
}
label, input { color: #333; font: 14px/20px Arial;
}
h2 { font-size: 16px; font-weight: bold; text-transform: uppercase; margin: 0 0 1em;
}
label { display: inline-block; width: 5em; padding: 0 1em; text-align: right;
}
/* Hide the file input using
opacity */
[type=file] { position: absolute; filter: alpha(opacity=0); opacity: 0;
}
input,
[type=file] + label { border: 1px solid #CCC; border-radius: 3px; text-align: left; padding: 10px; width: 150px; margin: 0; left: 0; position: relative;
}
[type=file] + label { text-align: center; left: 7.35em; top: 0.5em; /* Decorative */ background: #333; color: #fff; border: none; cursor: pointer;
}
[type=file] + label:hover { background: #3399ff;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body>
<form> <label for="f01">Name</label> <input id="f01" type="text" /> <br /> <input id="f02" type="file" placeholder="Add profile picture" /> <label for="f02">Add profile picture</label>
</form> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Using label to style File Input - Script Codes CSS Codes

/* Basics */
body { background: #eee; padding: 5em;
}
label, input { color: #333; font: 14px/20px Arial;
}
h2 { font-size: 16px; font-weight: bold; text-transform: uppercase; margin: 0 0 1em;
}
label { display: inline-block; width: 5em; padding: 0 1em; text-align: right;
}
/* Hide the file input using
opacity */
[type=file] { position: absolute; filter: alpha(opacity=0); opacity: 0;
}
input,
[type=file] + label { border: 1px solid #CCC; border-radius: 3px; text-align: left; padding: 10px; width: 150px; margin: 0; left: 0; position: relative;
}
[type=file] + label { text-align: center; left: 7.35em; top: 0.5em; /* Decorative */ background: #333; color: #fff; border: none; cursor: pointer;
}
[type=file] + label:hover { background: #3399ff;
}

Using label to style File Input - Script Codes JS Codes

$("[type=file]").on("change", function(){ // Name of file and placeholder var file = this.files[0].name; var dflt = $(this).attr("placeholder"); if($(this).val()!=""){ $(this).next().text(file); } else { $(this).next().text(dflt); }
});
Using label to style File Input - Script Codes
Using label to style File Input - Script Codes
Home Page Home
Developer Jesper Hills
Username nopr
Uploaded October 13, 2022
Rating 3
Size 2,646 Kb
Views 14,168
Do you need developer help for Using label to style File Input?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Jesper Hills (nopr) Script Codes
Create amazing video scripts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!