[ReactJS输入字段内的添加按钮

问题描述 投票:0回答:1

我想在input中的React中添加一个按钮。现在,我知道可以通过将按钮设置为绝对值并使用css将其移到那里,但是我认为有更好的选择吗?

我将一个具有绝对值的字段移到那里,然后搜索文本可能会在按钮下面。

这是我想要的最终结果,但是在那里有一个普通按钮也足够。

Searchbox

这是我的输入框代码:

Edit mystifying-water-8the6

在这种情况下,我可以在彼此下面放2个盒子,当我在input内放置一个按钮时,会出现input can't have any child elements的错误。

javascript reactjs search input
1个回答
0
投票

只是一个代码片段,您如何实现所要的内容:


.inputWithButton {
  position: relative;
  height: 100px;
  width : 200px;
}

.inputWithButton input{
  width: 100%;
  height: 25px;
  padding-right: 
}

.inputWithButton button {
  position: absolute;
  right: 0;
  top : 5px;
}
<div class='inputWithButton'>
  <input type="text"/>
  <button>Search</button>
</div>

您还可以在:]上检查相同的更改

Edit romantic-lewin-q7s7b

© www.soinside.com 2019 - 2024. All rights reserved.