如何设置联系表单7文件输入按钮

时间:2017-10-25 09:30:54

标签: html css wordpress contact-form-7

我似乎无法定位按钮以在联系表单7中加载文件。如何定位选择文件按钮,以便我可以添加背景颜色等。哦,我也这样做是WordPress因为你需要知道这一点。所以在后端它看起来像这样;

<label class="form_label"> Your Name<span>*</span>
[text* your-name]</label>

<label class="form_label"> Your Email<span>*</span>
[email* your-email]</label>

<label class="form_label">Tel
[tel tel]</label>

<label class="form_label">CV<span>*</span>
[file cv id:upload]</label>

<label class="form_label">Cover Letter
[textarea your-message]</label>

[submit "Send"]

我的输出html如下所示。

&#13;
&#13;
<div role="form" class="wpcf7" id="wpcf7-f47-o1" lang="en-US" dir="ltr">
  <div class="screen-reader-response"></div>
  <form action="/Lester_Goddard_New/#wpcf7-f47-o1" method="post" class="wpcf7-form" enctype="multipart/form-data" novalidate="novalidate">
    <div style="display: none;">
      <input type="hidden" name="_wpcf7" value="47" />
      <input type="hidden" name="_wpcf7_version" value="4.9" />
      <input type="hidden" name="_wpcf7_locale" value="en_US" />
      <input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f47-o1" />
      <input type="hidden" name="_wpcf7_container_post" value="0" />
    </div>
    <p><label class="form_label"> Your Name<span>*</span><br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" /></span></label></p>
    <p><label class="form_label"> Your Email<span>*</span><br />
<span class="wpcf7-form-control-wrap your-email"><input type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">Tel<br />
<span class="wpcf7-form-control-wrap tel"><input type="tel" name="tel" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-tel" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">CV<span>*</span><br />
<span class="wpcf7-form-control-wrap cv"><input type="file" name="cv" size="40" class="wpcf7-form-control wpcf7-file" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">Cover Letter<br />
<span class="wpcf7-form-control-wrap your-message"><textarea name="your-message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea" aria-invalid="false"></textarea></span></label></p>
    <p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" /></p>
    <div class="wpcf7-response-output wpcf7-display-none"></div>
  </form>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

您不能像任何按钮那样设置文件上传按钮的样式,而是可以使用伪元素覆盖按钮并对其应用样式。你可以尝试这样的事情。您可以更改&#34; new&#34;的内容和风格。按钮就像你想要的那样:

&#13;
&#13;
span.cv {
  position:relative;
}
span.cv:before {
  content:"Upload file";
  position:absolute;
  left:0;
  padding:5px;
  background:red;
  color:#fff;
  width:130px;
  text-align:center;
  border-radius:5px;
  cursor:pointer;
}
span.cv>input {
  visibility:hidden;
}
&#13;
<div role="form" class="wpcf7" id="wpcf7-f47-o1" lang="en-US" dir="ltr">
  <div class="screen-reader-response"></div>
  <form action="/Lester_Goddard_New/#wpcf7-f47-o1" method="post" class="wpcf7-form" enctype="multipart/form-data" novalidate="novalidate">
    <div style="display: none;">
      <input type="hidden" name="_wpcf7" value="47" />
      <input type="hidden" name="_wpcf7_version" value="4.9" />
      <input type="hidden" name="_wpcf7_locale" value="en_US" />
      <input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f47-o1" />
      <input type="hidden" name="_wpcf7_container_post" value="0" />
    </div>
    <p><label class="form_label"> Your Name<span>*</span><br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" /></span></label></p>
    <p><label class="form_label"> Your Email<span>*</span><br />
<span class="wpcf7-form-control-wrap your-email"><input type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">Tel<br />
<span class="wpcf7-form-control-wrap tel"><input type="tel" name="tel" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-tel" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">CV<span>*</span><br />
<span class="wpcf7-form-control-wrap cv"><input type="file" name="cv" size="40" class="wpcf7-form-control wpcf7-file" aria-invalid="false" /></span></label></p>
    <p><label class="form_label">Cover Letter<br />
<span class="wpcf7-form-control-wrap your-message"><textarea name="your-message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea" aria-invalid="false"></textarea></span></label></p>
    <p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" /></p>
    <div class="wpcf7-response-output wpcf7-display-none"></div>
  </form>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我不得不更改visibility:hidden;opacity:0;

根据https://www.quirksmode.org/dom/inputfile.html,因此该按钮将继续起作用,否则单击不会提示浏览。