Skip to content Skip to sidebar Skip to footer

How Can You Style Django's File Picker Form Button?

I am attempting to style my Django file upload button, but since it's handled through the form and not explicitly written in the HTML within the template I cannot style it directly

Solution 1:

For posterity's sake here is the solution which I found using Bootstrap here.

.fileUpload {
	position: relative;
	overflow: hidden;
	margin: 10px;
}
.fileUploadinput.upload {
	position: absolute;
	top: 0;
	right: 0;
	margin: 0;
	padding: 0;
	font-size: 20px;
	cursor: pointer;
	opacity: 0;
	filter: alpha(opacity=0);
}
<linkhref="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" /><divclass="fileUpload btn btn-primary"><span>Upload</span><inputtype="file"class="upload" /></div>

Solution 2:

If you want to style the file upload button define another button or link and style that. Then set it's click event to trigger file upload button.

HTML:

<div><aid="browse"class="my_class">Browse</a><inputtype="file"name="data"style="display: none" /></div>

Javascript:

$('#browse').click(function(){
    $(this).parent().find('input').click();
});

To make this work in a Django form you can do it by a widget.

Post a Comment for "How Can You Style Django's File Picker Form Button?"