我想在input
中的React
中添加一个按钮。现在,我知道可以通过将按钮设置为绝对值并使用css
将其移到那里,但是我认为有更好的选择吗?
我将一个具有绝对值的字段移到那里,然后搜索文本可能会在按钮下面。
这是我想要的最终结果,但是在那里有一个普通按钮也足够。
这是我的输入框代码:
在这种情况下,我可以在彼此下面放2个盒子,当我在input
内放置一个按钮时,会出现input can't have any child elements
的错误。
只是一个代码片段,您如何实现所要的内容:
.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>
您还可以在:]上检查相同的更改