按钮在搜索内部

huangapple go评论68阅读模式
英文:

Button inside the search

问题

如何强制我的按钮显示在输入框上方?它想要移到第二行:

我想要的效果:

输入框应该占据整个宽度。

英文:

How to force my button to show up over the input? It wants to go to the second line:
按钮在搜索内部

What I would like:

按钮在搜索内部

The input should be 100% wide.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

input {
  width: 100%;
  border-radius:30px;
  padding-right:50px;
}

button {
  border-radius:30px;
  margin-left:-50px;
}

<!-- language: lang-html -->

&lt;div&gt;
&lt;input type=&quot;text&quot; placeholder=&quot;search for something&quot;/&gt;
&lt;button&gt;search&lt;/button&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

给容器(div)添加 position: relative,然后将按钮设置为 position: absolute

div {
  position: relative;
}

button {
  border-radius: 30px;
  position: absolute;
  top: 0;
  right: 0;
}

不要忘记为输入框设置 padding-right 以将输入文本偏移到按钮的宽度。

英文:

give the contaienr (div) a position: relative and then position the button absolute:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

div {
  position: relative;
}

input {
  width: 100%;
  border-radius: 30px;
  padding-right: 4em;
}

button {
  border-radius:30px;
  position: absolute;
  top: 0;
  right: 0;
}

<!-- language: lang-html -->

&lt;div&gt;
&lt;input type=&quot;text&quot; placeholder=&quot;search for something&quot;/&gt;
&lt;button&gt;search&lt;/button&gt;
&lt;/div&gt;

<!-- end snippet -->

PS: Don't forget to set a padding-right for the input to offset the input text to the button width.

huangapple
  • 本文由 发表于 2023年5月25日 21:04:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定