简体   繁体   English

在输入字段内放置问号提交按钮

[英]Place question mark submit button inside input field

I have an input field and a submit button which looks like a question mark due to css styling.我有一个输入字段和一个提交按钮,由于 css 样式,它看起来像一个问号。 This is what it currently looks like:这是它目前的样子:

在此处输入图片说明

How can I position the question mark inside the input field like this:如何在输入字段中放置问号,如下所示:

在此处输入图片说明

HTML HTML

<div class="div">
  <form method="post">
    <input type="text" class="input">
    <input type="submit" value="?" class="submit">
  </form>
</div>

CSS CSS

.div {
  position: relative;
  top: 50%;
  transform: translateY(50%);
}

.input {
  display: block;
  margin: 0 auto;
  width: 50%;
}

.submit {
  background: none;
  border: none;
}

JsFiddle: https://jsfiddle.net/TheCodesee/8h72tjcL/2/ JsFiddle: https ://jsfiddle.net/TheCodesee/8h72tjcL/2/

You could use the question mark as a background image in the input field with some CSS, eg:您可以使用一些 CSS 将问号用作输入字段中的背景图像,例如:

.form-input {
  padding-right: 4rem;
  background-image: url(your image);
  background-repeat: no-repeat;
  background-position: center right 1rem;
  background-size: 2rem 2rem;
}

You may need to adjust the numbers depending on your image size of course.当然,您可能需要根据图像大小调整数字。 Your submit button may still exist, but you want to hide (via visibility or display ).您的提交按钮可能仍然存在,但您想隐藏(通过visibilitydisplay )。 Thus, the use can still hit enter to submit the form.因此,用户仍然可以按回车键提交表单。 Another possibility would be to auto submit the form on input blur.另一种可能性是在输入模糊时自动提交表单。

Like that, you can avoid moving the button itself around.这样,您可以避免移动按钮本身。

Use position: absolute on your submit input.在提交输入中使用position: absolute

 .div { position: relative; top: 50%; transform: translateY(50%); width: 50%; margin: 0 auto; } .input { display: block; margin: 0 auto; width: 100%; } .submit { border: none; background: none; outline: none; position: absolute; top: 2px; right: 0px; }
 <div class="div"> <form method="post"> <input type="text" class="input"> <input type="submit" value="?" class="submit"> </form> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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