2

I am building a html form that needs file uplod. While I got the file upload part working, I am unable to get the styling of form upload button and " No file selected" text.

My desired markup is enter image description here

Is there a way to do it?

PS: Please ignore the green text ( "Upload a screen shot"). I have that working.

Current behavior the button and the "no file chosen"is in the same line.

HTML Code:

 <div class="formField">
    <label for="fileToUpload">Upload a screen shot (optional) </label>
    <input type="file" name="fileToUpload" id="fileToUpload"/> 
 </div>

Fiddle: http://jsfiddle.net/5tLokkjh/

1

1 Answer 1

0

You could enter a line break after the label:

<div class="formField">
  <label for="fileToUpload">Upload a screen shot (optional)</label><br />
  <input type="file" name="fileToUpload" id="fileToUpload"/> 
</div>

But it's much better to use CSS:

label {
  display: block;
}
<div class="formField">
  <label for="fileToUpload">Upload a screen shot (optional)</label>
  <input type="file" name="fileToUpload" id="fileToUpload" />
</div>

Setting display: block on an element makes it fill the entire width of the page.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! But it still doesn't behave the way I need it ( like in the image in my first post).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.