Replace input type=file by an image

后端 未结 13 2102
感动是毒
感动是毒 2020-12-02 04:13

Like a lot of people, I\'d like to customize the ugly input type=file, and I know that it can\'t be done without some hacks and/or javascript. But,

13条回答
  •  天涯浪人
    2020-12-02 04:41

    This works really well for me:

    .image-upload>input {
      display: none;
    }

    Basically the for attribute of the label makes it so that clicking the label is the same as clicking the specified input.

    Also, the display property set to none makes it so that the file input isn't rendered at all, hiding it nice and clean.

    Tested in Chrome but according to the web should work on all major browsers. :)

    EDIT: Added JSFiddle here: https://jsfiddle.net/c5s42vdz/

提交回复
热议问题