我需要将一个表格分成两部分。一个站点上有3个字段,另一个站点上有3个字段,而另一个站点上有提交按钮。我为他们提供了一个全称为“ contactform”的类,供按钮使用。我正在使用drupal,这意味着我只能使用CSS。所以我不能添加除inputfields之外的其他任何HTML标记类。

What i have

What i'm trying to achieve

我可以提供的唯一代码是“检查元素”中的HTML代码,我无法在此处发布,因此我将在下面的评论中发布

希望你们能帮助我,并在此先感谢您!

这就是我能给你的。这是一堆混乱的代码,但是我无能为力了:

  <form class="webform-client-form webform-client-form-14" action="/drupal/contact-0" method="post" id="webform-client-form-14" accept-charset="UTF-8"><div><div class="form-item webform-component webform-component-textfield webform-component--naam form-group form-item form-item-submitted-naam form-type-textfield form-group"><input required="required" placeholder="Uw naam" class="contactform form-control form-text required" type="text" id="edit-submitted-naam" name="submitted[naam]" value="" size="50" maxlength="40" /> <label class="control-label element-invisible" for="edit-submitted-naam">Naam <span class="form-required" title="This field is required.">*</span></label>
</div><div class="form-item webform-component webform-component-email webform-component--email form-group form-item form-item-submitted-email form-type-webform-email form-group"><input required="required" class="email contactform form-control form-text form-email required" placeholder="Uw emailadres" type="email" id="edit-submitted-email" name="submitted[email]" size="50" /> <label class="control-label element-invisible" for="edit-submitted-email">Email <span class="form-required" title="This field is required.">*</span></label>
</div><div class="form-item webform-component webform-component-textfield webform-component--onderwerp form-group form-item form-item-submitted-onderwerp form-type-textfield form-group"><input required="required" placeholder="Uw onderwerp" class="contactform form-control form-text required" type="text" id="edit-submitted-onderwerp" name="submitted[onderwerp]" value="" size="50" maxlength="255" /> <label class="control-label element-invisible" for="edit-submitted-onderwerp">Onderwerp <span class="form-required" title="This field is required.">*</span></label>
</div><div class="form-item webform-component webform-component-textarea webform-component--bericht form-group form-item form-item-submitted-bericht form-type-textarea form-group"><div class="form-textarea-wrapper"><textarea required="required" placeholder="Uw bericht" class="contactform2 form-control form-textarea required" id="edit-submitted-bericht" name="submitted[bericht]" cols="50" rows="5"></textarea></div> <label class="control-label element-invisible" for="edit-submitted-bericht">Bericht <span class="form-required" title="This field is required.">*</span></label>
</div><input type="hidden" name="details[sid]" />
<input type="hidden" name="details[page_num]" value="1" />
<input type="hidden" name="details[page_count]" value="1" />
<input type="hidden" name="details[finished]" value="0" />
<input type="hidden" name="form_build_id" value="form-4vEZg04Y8Zevfr2GC6ONWVw8UI_4vxf3AL8NRrCFWtg" />
<input type="hidden" name="form_token" value="gNUgTXDR4TC0WhrHOwB7IaYOMOR6Nxz01qjuvrsVPPQ" />
<input type="hidden" name="form_id" value="webform_client_form_14" />
<div class="form-actions"><button class="webform-submit button-primary btn btn-primary form-submit" type="submit" name="op" value="Submit">Submit</button>
</div></div></form>
</section>


CSS

.webform-client-form-14 {
 float: left;
 width: 45%;
 margin-top: 20px;
 margin-bottom: 30px;
}

.contactform {
 border-radius: 0;
 border: none;
}

最佳答案

问题是您将整个表单的宽度设置为45%,但是我们只希望其中的元素为45%的宽度。在无法向html中添加包装器的情况下,您将需要使用:nth-child(n) css选择器或字段组的自定义类(例如:.webform-component--bericht)将每个输入组一个一个地定位。

例:

.webform-client-form-14 .form-item:nth-child(1) {
  width:45%;
  display:block;
  float:left;
}

10-05 20:56
查看更多