search bar html css in react - html

I am trying to use a search bar css from code pen. I used their exact code but the search bar seems to be really buggy on react.
Here is code sandbox for better reference. https://codesandbox.io/s/sad-moser-mdxmd?file=/src/Dashboard.js
Here's the code that I am currently using.
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" id="input_text"></input>
<button type="submit" class="searchButton">
<i class="fa fa-search"></i>
</button>
</div>
</div>
.search {
width: 100%;
position: center;
display: flex;
}
.searchTerm {
width: 100%;
border: 3px solid #00b4cc;
border-right: none;
padding: 5px;
height: 20px;
border-radius: 5px 0 0 5px;
outline: none;
color: #9dbfaf;
}
.searchTerm:focus {
color: #00b4cc;
}
.searchButton {
width: 40px;
height: 36px;
border: 1px solid #00b4cc;
background: #00b4cc;
text-align: center;
color: #fff;
border-radius: 0 5px 5px 0;
cursor: pointer;
font-size: 20px;
}
/*Resize the wrap to see the search bar change!*/
.wrap {
width: 30%;
position: flex;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
I want the search bar to look like this: enter image description here
This is the link to the code that I attempted to use.
https://codepen.io/huange/pen/rbqsD

because you are using simple html you have to use jsx here. Use any online jsx convertor like "https://magic.reactjs.net/htmltojsx.htm" etc.
for this you can use :
<div className="wrap">
<div className="search">
<input type="text" className="searchTerm" id="input_text" />
<button type="submit" className="searchButton">
<i className="fa fa-search" />
</button>
</div>
</div>

Related

Icons inside input text field

I have a problem. I want to create a input text field with icons inside of the code.
I want to have my icons inside of the input text field. Unfortunately my CSS style didn't work. With others code the icons disappeared. I hope you can help me. Thank you in advance. Please see below for my code.
HTML
<div class="col-md-6 login-form">
<h3>Los gehts</h3>
<div class="form_login">
<div class="form-group">
<input type="text" id="email_field" placeholder="Email *">
<i class="fa fa-user" aria-hidden="true"></i>
</span>
</div>
<div class="form-group">
<input type="password" id="password_field" placeholder="Passwort *">
<i class="fa fa-lock" aria-hidden="true"></i>
</span>
</div>
<div class="form-group">
<button type="submit" class="btnSubmit" onclick="signIn()">Login</button>
</div>
<!--
<div class="form-group">
Forget Password?
</div> -->
</div>
</div>
CSS
.login-container {
margin-top: 5%;
margin-bottom: 5%;
text-align: center;
margin: auto;
padding-bottom: 5%;
}
.login-form {
padding: 5%;
text-align: center;
margin: auto;
}
.login-form h3 {
text-align: center;
color: #333;
}
.login-container form {
padding: 10%;
text-align: center;
display: inline-block;
position: relative;
width: 100%;
z-index: 1;
margin-bottom: 10px;
}
.btnSubmit {
width: 50%;
border-radius: 1rem;
padding: 1.5%;
border: none;
cursor: pointer;
}
.btnLogout {
margin-top: 1rem;
border-radius: 1rem;
cursor: pointer;
color: #fff;
background-color: #0062cc;
text-align: center;
display: inline-block;
border: none;
margin-bottom: 10px;
}
.btnLogout:hover {
background-color: #0575ec;
}
.login-form .btnSubmit {
font-weight: 600;
color: #fff;
background-color: #0062cc;
}
.login-form .ForgetPwd {
color: #0062cc;
font-weight: 600;
text-decoration: none;
}
.loggedin-div {
text-align: center;
padding-bottom: 5%;
}
You need to create a div with border that imitate a input border. Then, you need to create the text input at the left and add this code: <input type="image" src="yourimagefile.jpg">
I hope I help you.
If you want something to float somewhere else, you can use a combination of position:relative; and top/left with CSS. For instance, let's add an id to that login button and make it our icon...
<div class="form-group" id="submit">
<button type="submit" class="btnSubmit" onclick="signIn()">Login</button>
</div>
Then some styling...
#submit {
top:-21px;
left:228px;
position:relative;
width:100px;
}
And what we get, then, is an icon floating over the input field. Working Demo.
Works for me. Before:
After:
Here's an example with the blank <i> elements (converted to <img> so we could see something, as they had no href): Working Demo.

How to highlight the prepend Font Awesome icon in Bootstrap 4 or Bootstrap-vue

I am having something like this:
How do I expand the width that the border it will also cover the icon on the left like this:
My HTML:
.input-group-text {
width: 48px;
border-right: none;
background-color: #ffffff;
}
[class^="fa-"], [class*=" fa-"] {
display: inline-block;
width: 100%;
}
.LoginInput {
border-left: none;
position: relative;
}
<b-input-group>
<b-input-group-prepend>
<span class="input-group-text"><i class="fa fa-user fa-lg"></i></span>
</b-input-group-prepend>
<b-form-input class="LoginInput" size="lg" placeholder="Username">
</b-form-input>
</b-input-group>
<b-input-group>
<b-input-group-prepend>
<span class="input-group-text"><i class="fa fa-lock fa-lg"></i></span>
</b-input-group-prepend>
<b-form-input class="LoginInput" size="lg" type="password" placeholder="Password">
</b-form-input>
</b-input-group>
I found this working demo by James Barnett. He uses font awesome icons with css to implement position: absolute; on the icon and text indent to implement what you are trying to achieve. He places the icon and the input field inside a container div.
HTML
<div class="search">
<span class="fa fa-search"></span>
<input placeholder="Search term">
</div>
CSS
#import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font- awesome.min.css");
body { margin: 30px; }
.search {
position: relative;
color: #aaa;
font-size: 16px;
}
.search input {
width: 250px;
height: 32px;
background: #fcfcfc;
border: 1px solid #aaa;
border-radius: 5px;
box-shadow: 0 0 3px #ccc, 0 10px 15px #ebebeb inset;
}
.search input { text-indent: 32px;}
.search .fa-search {
position: absolute;
top: 10px;
left: 10px;
}
Find the full thread here.
I hope this is of some help.

Insert logo in input

am trying to create a field of research. I want to add a logo in the input bar.
Here is my code:
.display-new-chat-window {
.new-chat-window {
display: block;
text-align: center;
z-index: 2;
input:focus {
outline-color: $blue;
}
.new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
margin-top: 10px;
padding-left: 15px;
width: 200px;
z-index: 1;
}
}
}
<div class="new-chat-window">
<i class="fa fa-search"></i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
Probably something like this, where L is the logo:
.new-chat-window {
position: relative;
width: 200px;
display: block;
margin: 10px auto;
text-align: center;
z-index: 2;
}
.new-chat-window .fa {
position: absolute;
top: 7px;
left: 10px;
font-weight: bold;
font-style: normal;
}
input:focus {
outline-color: $blue;
}
.new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
padding-left: 30px;
width: 100%;
z-index: 1;
}
<div class="new-chat-window">
<i class="fa fa-search">L</i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
You can accomplish this using the background property:
input {
background: url(https://path.to/image);
}
.display-new-chat-window .new-chat-window {
display: block;
text-align: center;
z-index: 2;
}
.display-new-chat-window .new-chat-window input:focus {
outline-color: $blue;
}
.display-new-chat-window .new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
margin-top: 10px;
padding-left: 15px;
width: 200px;
z-index: 1;
background: url(https://unsplash.it/15) no-repeat scroll 0 center;
}
<div class="display-new-chat-window">
<div class="new-chat-window">
<i class="fa fa-search"></i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
</div>
Sorry If I misunderstand your point of your question
In this example, I use my own code
html
<input type="text" class="input-logo" placeholder="Paypal id/email">
css
.input-logo{
background-image:url(https://fx-
rate.net/images/favi_transfer/paypal.com.png);
background-position:right;
background-repeat:no-repeat;
padding-left:1px;
font-size: 16px;
width: 200px;
}
for your code, you add my input-logo class and you can style it from there.
Look at:
https://codepen.io/ronalto7777/pen/rzPjoR

HTML Search element styling

I´m trying to build a search element together with a button, something like:
Except that I need to change the background color of the search icon (blue, gray, whatever...).
Here is my code so far and the result:
.searchWrap {
position: absolute;
border: thin solid #f2f2f2;
border-radius: 5px;
top: 5px;
left: 5px;
}
.searchTerm {
float: left;
border-style: none;
padding: 5px;
height: 20px;
outline: none;
}
.searchButton {
right: -50px;
width: 30px;
height: 20px;
border: 1px solid #f2f2f2;
background: #f2f2f2;
border-radius: 5px;
text-align: center;
color: #ccc;
vertical-align: middle;
cursor: pointer;
}
<div className="searchWrap">
<input type="text" className="searchTerm" placeholder="Search..." />
<button type="submit" className="searchButton">
<Icon name='search' />
</button>
</div>
I'm using React. Here is my result so far:
The external border is rounded, ok, that's what I need, but the separation between the searchTerm and the searchButton is also rounded, and I need a plain separator here, something like:
I'm using font awesome here, so the code isn't spaced like your screenshot, but looks like you have your own library you're using with react for that icon and your spacing is fine.
All you need to do is use border-radius: 0 5px 5px 0 to keep the left side borders from rounding, and assign a border-left on the .searchButton to draw the vertical line. I changed the border color so it's more prominent, but you can use whatever color you want.
*{margin:0;padding:0;}
.searchWrap {
position: absolute;
top: 5px;
left: 5px;
}
.searchTerm {
float: left;
border-style: none;
padding: 5px;
height: 20px;
outline: none;
margin-left: 3px;
border: thin solid #ddd;
border-width: thin 0 thin thin;
border-radius: 5px 0 0 5px;
}
.searchButton {
right: -50px;
width: 30px;
height: 32px;
border: 1px solid #f2f2f2;
background: #f2f2f2;
border-radius: 0 5px 5px 0;
text-align: center;
color: #ccc;
vertical-align: middle;
cursor: pointer;
border: thin solid #ddd;
}
.searchTerm:focus, .searchTerm:focus + .searchButton {
border-color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="searchWrap">
<input type="text" class="searchTerm" placeholder="Search..." />
<button type="submit" class="searchButton">
<i class="fa fa-search"></i>
</button>
</div>
Try this for the search button css instead of border-radius
.searchButton {
...
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
...
}
Can you use bootstrap? Relatively simple, and once you have it, modify the css the way you want it.
https://v4-alpha.getbootstrap.com/components/input-group/#button-addons
Bootstrap is strongly recommended for this. See http://getbootstrap.com/components/#input-groups. Coupled with FontAwesome, you could do something like this:
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="fa fa-search"></span>
<span class="sr-only">Search</span>
</button>
</span>
</div>

Limit number of lines shown in a textbox, but not limiting the user to write

I have a case I am not sure how to figure it out.
I am trying to do a design to put a button over a textbox, to make my layout looks nice, but when users start typing information in textbox, it hides behind the button. I know I have 1 of 2 solutions, but I don't know how to do it:
1- either to find another way to do the layout.
2- limit the number of lines for the user to enter, but this way I am going to have a restriction for long data.
Below is my HTML and CSS:
body{
background: #000;
}
.nl-main{
width: 300px;
border: 1px solid white;
border-radius: 6px;
padding: 10px;
}
.header{
padding: 3px;
}
.header span{
color: white;
}
.nl-txt-main, .nl-btn-main{
display: inline-block;
}
.nl-btn-main .nl-btn{
border-radius: 5px;
background: blue;
color: white;
left: -50px;
position: relative;
}
.nl-txt-main .nl-txt {
width: 200px;
border-radius: 5px;
}
<div class="header">
<span>Search our database</span>
</div>
<div class="nl-controls">
<div class="nl-txt-main">
<input type="text" class="nl-txt"/>
</div>
<div class="nl-btn-main">
<input type="button" value="Send" class="nl-btn"/>
</div>
</div>
I want the button to be like part of the textbox itself, When you try to run the code, and write a long sentence in the textbox, it will hide under the button. How do I solve it?
Thank you.
Remove left:-50px; from you button
body{
background: #000;
}
.nl-main{
width: 300px;
border: 1px solid white;
border-radius: 6px;
padding: 10px;
}
.header{
padding: 3px;
}
.header span{
color: white;
}
.nl-txt-main, .nl-btn-main{
display: inline-block;
margin:0;
}
.nl-btn-main .nl-btn{
background: blue;
color: white;
left: -4px;
position: relative;
border-bottom-right-radius: 5px;
margin:0;
border-top-right-radius: 5px;
}
.nl-txt-main .nl-txt {
width: 200px;
border-bottom-left-radius: 5px;
margin:0;
border-top-left-radius: 5px;
}
<div class="header">
<span>Search our database</span>
</div>
<div class="nl-controls">
<div class="nl-txt-main">
<input type="text" class="nl-txt"/>
</div>
<div class="nl-btn-main">
<input type="button" value="Send" class="nl-btn"/>
</div>
</div>