admin管理员组文章数量:1296454
I want to add a button inside my input
in React
. Now I know I could place it there by setting the button absolute and moving in on there using css
but I assume that there is a better option to do it?
My moving a field there with absolute value then the search text might go under button.
This is the end result I would like to have but having a normal button there would suffice also.
Here is my input box code:
In this case I can put 2 boxes under eachother and when I place a button inside input
I get an error that input can't have any child elements
.
I want to add a button inside my input
in React
. Now I know I could place it there by setting the button absolute and moving in on there using css
but I assume that there is a better option to do it?
My moving a field there with absolute value then the search text might go under button.
This is the end result I would like to have but having a normal button there would suffice also.
Here is my input box code:
In this case I can put 2 boxes under eachother and when I place a button inside input
I get an error that input can't have any child elements
.
-
There isn't a better way to do it, as you've seen from that error you can't put elements inside an
<input/>
so using CSS to make icon appear inside them is your only choice. This is also what all the CSS libraries like Bootstrap and Material UI do – Jayce444 Commented May 12, 2020 at 10:32
3 Answers
Reset to default 4Just a simple code snippet, how you can achieve what you are asking :
.inputWithButton {
position: relative;
height: 100px;
width : 200px;
}
.inputWithButton input{
width: 70%;
height: 25px;
padding-right: 60px;
}
.inputWithButton button {
position: absolute;
right: 0;
top : 5px;
}
<div class='inputWithButton'>
<input type="text"/>
<button>Search</button>
</div>
You can also check same change on :
If your intention is to have just a "search button", may I remend the Input Group from react-bootstrap lib. You can add a button with whatever you want inside of it. (Using v2.1.0 - Bootstrap 5)
<InputGroup className="mb-3">
<FormControl placeholder="Search" />
<Button variant="outline-secondary">
本文标签:
javascriptAdd button inside Input field ReactJSStack Overflow
版权声明:本文标题:javascript - Add button inside Input field ReactJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1741601224a2387711.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论