"Implementing a search bar feature using HTML, CSS, and

My attempt to implement a search bar CSS from CodePen is not working properly in React. Even though I used the exact code provided, the search bar seems to be buggy.

If you want to take a look at the code sandbox for better reference, you can visit: https://codesandbox.io/s/sad-moser-mdxmd?file=/src/Dashboard.js

Below is 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 aim to make the search bar resemble this image description:

For more details on the code I tried to utilize, you can refer to this link: https://codepen.io/huange/pen/rbqsD

Answer №1

If you are using simple HTML, you will need to use JSX here. You can utilize online tools like "https://magic.reactjs.net/htmltojsx.htm" to convert your HTML to JSX code. Here's an example of how you can do this:

<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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React Hook useEffect is throwing an error due to missing dependencies: 'dispatch' and 'logout'. To resolve this, make sure to include them in the dependency array or remove the array altogether

I'm struggling to understand what the issue is with this code. It seems like I keep encountering this problem and haven't been able to fix it yet. const signOut = () => { dispatch({ type: "LOGOUT" }); dispatch({ type: & ...

Toggling jQuery to show or hide content depending on the selector

I am looking to implement a jQuery-based animation and here is the code I have so far: >items=document.querySelectorAll("#customers td span"); [<span alt=​" 02,Counter,11,2013-04-06 14:​59:​16">​ 02​</span>​, <span>​11 ...

The scrollHeight property for a textarea element that is set as

Currently, I am working on enhancing a form results page by implementing a readonly textarea to showcase the submitted email address. My main goal is to allow the textarea to dynamically adjust its height in order to display the full email instead of trunc ...

Implementing Event Handlers for Multiple Textareas Using Jquery on a Webpage

The functionality of my script is exactly how I want it to be, but I am facing an issue when trying to replicate it on a page. The jQuery code manipulates textarea boxes based on button clicks, however, I now need each textarea box to have its own set of b ...

Switching icon images using JQuery based on state changes

I'm attempting to switch the background image of my webpage's "body" element when the user toggles between playing and pausing music icons. This is what the CSS for the "body" element looks like: body { background: url('https://s3-us-wes ...

How can I style the inner div by adding a class to the first div?

In my project, I have a list of elements that are generated dynamically, all styled the same way but with different content. The first element has a specific styling, and if it doesn't render, I want the second element to inherit that styling. < ...

What is the best way to maintain the selected row during pagination in Yii?

Currently, I am facing an issue with pagination while viewing table rows. My requirement is to select different rows from various pages and then submit the form. The problem occurs when I select rows from one page, navigate to another page to make more se ...

Ways to resolve the issue of incompatible parameters 'action' types in JavaScript

I'm encountering a common problem, but I can't figure out why this error is happening. After updating redux, I encountered the following error message: TS2322: Type '(state: ILanguage | undefined, action: PayloadAction<ILanguage>) =&g ...

Guide on showcasing all entries in the database within the body section of an HTML table

Looking to showcase data from a table inside the body section of an html page This is the code I've been working on: <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="vi ...

Tips on how to toggle the class of one specific element without affecting others

Whenever I click on a div, it expands. However, if I click on a collapsed one, both collapse and the first one returns to an inactive state. At this point, the last two are in both active and inactive states. And if at this time I click on the first one, t ...

Linking Redux to the highest level of my application is not functioning as expected

I have been attempting to troubleshoot this code for quite some time now, but I am struggling to identify the issue at hand. My main goal is to establish a connection between my top-level application and the redux store. However, every time I try, the stor ...

Challenges with Type Aliases when Using Typescript with MaterialUI Icons

I am searching for a way to dynamically incorporate Material UI icons into my code based on specific strings found in a configuration file. I have come across an approach that seems promising: https://medium.com/@Carmichaelize/dynamic-tag-names-in-react-a ...

Loading all the content and scripts from one page into another

Are you looking for a seamless way to view and book our scuba diving programmes without having to navigate away from the main page? If so, we understand your desire for convenience. Instead of redirecting you to separate pages when you click on buttons li ...

Customize a React image carousel for NextJS integrations

Here's the image slider code in React that is functioning properly: import React, { useState, useEffect } from "react"; import item1 from "./../assets/images/items/1.jpg"; import item2 from "./../assets/images/items/2.gif" ...

Implementing the rotation of an element using 'Transform: rotate' upon loading a webpage with the help of Jquery, Javascript, and

A div element designed to showcase a speedometer; <div class="outer"> <div class="needle" ></div> </div> The speedometer animates smoothly on hover; .outer:hover .needle { transform: rotate(313deg); transform-origin: ce ...

tips for creating a mobile-friendly responsive button

I have been scouring the internet for a solution to this issue. Essentially, I am trying to position the button on the right side in desktop view. Here is an example: chrome view However, when the site is resized or viewed on mobile devices, the button sh ...

The function .classList.remove() is effective when applied to one element, but fails to work on a different element

I am facing an issue where only one element is getting affected when trying to remove classes from multiple elements if certain email input requirements are met. Can someone help me understand why this is happening? Here is the code snippet: const emailI ...

Effortless Table Extraction using PHP's Simple HTML DOM Parser

I am in the process of extracting HTML data from a local weather channel's website in order to gather closing information for schools, businesses, and churches in my area. However, I am facing an issue as the information is housed within tables that ...

Remove the blue outline in Fancybox when clicked

Does anyone know how to remove the default blue outline that appears after opening and closing an image or video in Fancybox 3? It disappears when clicked next to, but I would like to get rid of it completely. Any help is appreciated. https://i.stack.imgu ...

Eliminate the cushioning on a single item

I'm currently working on a website and running into a small issue. The main page has a background with a white body in the center, containing padding for the text to prevent it from being right at the border. #content { width: 900px; overflow: h ...