简体   繁体   中英

Style p:fileUpload button size

I want to make the PrimeFaces fileload button smaller than the default, and I want to adjust the positions of the buttons. This is the xhtml file.

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title></title>

    <style>
.ui-fileupload-buttonbar .ui-icon {

    margin: 0px 0px 0px 0px !important;
    padding: 0px 0px 0px 0px !important;
    border: none;

    visibility: hidden !important;
}

.ui-button-text-icon-left .ui-button-text {
  font-size: 0.5em;
  color: #339966;  
}
/* Icon */
.ui-button-text-icon-left .ui-icon {
  display: none;
}
.ui-fileupload {
    margin: 0px 0px 0px 0px !important;
    padding: 0px 0px 0px 0px !important;
    display: inline-block;
    border: none;
}
.ui-fileupload-content {
    display: none;
}
</style>

</h:head>
<h:body>

    <h:form>
        <p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}"
            mode="advance" dragDropSupport="false" multiple="true"
            update="messages" sizeLimit="100000" fileLimit="3"
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

        <p:growl id="messages" showDetail="true" />
    </h:form>
</h:body>
</html>

My current button is attached. How to get rid of the outer layer of the box? And how to adjust the distance between "choose" and "upload"?

在此处输入图片说明

Proposal

I used the following css:

/* hide the icons in the file upload button bar */
.ui-fileupload-buttonbar .ui-icon {
    display: none;
}

/* adjust the padding of all buttons inside the file upload button bar */
.ui-fileupload-buttonbar .ui-button-text-icon-left .ui-button-text {
    font-size: 0.8em;
    padding: 0 0.2em;
}

/* unstyle the file upload button bar background */
.ui-fileupload-buttonbar.ui-widget-header {
    background-color: transparent;
    border: 0 none;
}

/* increase fileupload button spacing between 'choose' and 'upload' */
.ui-fileupload-buttonbar .ui-fileupload-choose {
    margin-right: 10em;
}

/* remove the border of file upload content list */
.ui-fileupload-content {
    border: 0 none;
}

Explanations

  • visibility:hidden; does not remove the covered space, display:none; does

  • the large padding comes from .ui-button-text-icon-left .ui-button-text , so we override that

  • a general rule of thumb: try to avoid !important but find a more specific css selector instead

  • browsers like Firefox and Chrome let you inspect the source code of your page by pressing F12 and provide a live preview of any changes made to either html or css content

The result

小文件上传框

I'm assuming this is the button you're referring to: http://www.primefaces.org/showcase/ui/file/upload/basic.xhtml

If so, then your options are limited to making the font smaller, reducing the padding, and/or removing the icon.

For example:

/* Button */
.ui-button-text-icon-left .ui-button-text {
  font-size: 0.8em;
  padding: 0.2em;
}

/* Icon */
.ui-button-text-icon-left .ui-icon {
  display: none;
}

Regarding your additional questions in the comments, you can remove the containing styles with this:

.ui-fileupload-buttonbar {
  background: none;
  border: 0;
  padding: 0;  
}

You can add some margin after the "choose" button with this:

.ui-fileupload-choose.ui-button {
  margin-right: 40px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM