Adding an image to the right side of an input form to act as a search button: A step-by-step guide

I have been attempting to customize one of the navigation bars from a Bootstrap website. I would like to create a custom input form with a button that includes an external image. I have tried adjusting the CSS, but the code I was referencing was different and did not yield the desired result.

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />

    <title>Hello, world!</title>
  </head>
  <body>
    <!-- NAVBAR -->
   <div>
         <nav class="navbar navbar-expand-lg navbar-light bg-light">
              <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav mr-auto">
                          <li class="nav-item">
                                <a class="nav-link" href="#">Home</a>
                          </li>
                          <li class="nav-item">
                                <a class="nav-link" href="#">Post layout</a>
                          </li>
                          <li class="nav-item">
                                <a class="nav-link" href="#" >Pages</a>
                          </li>
                          <li class="nav-item">
                                <a class="nav-link" href="#">Shortcodes</a>
                          </li>
                          <li class="nav-item">
                                <a class="nav-link" href="#">Contact</a>
                          </li>
                    </ul>
                    <div class="search-bar">
                        <form class="form-inline my-2 my-lg-0">
                              <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                              <button class="btn btn-outline-success my-2 my-sm-0" type="submit"><img src="\searchicon.png"></button>
                        </form>
                    </div>
              </div>
         </nav>   
   </div>
    <!-- /NAVBAR -->
    
    
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

Answer №1

Here's an example of how you could achieve this:

<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<style>
.container {
position: relative;
}
.image {
position: absolute;
top: 20px;
left: 50px;
}
.input-field {
height: 30px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" class="input-field">
<button class="image"><img src="icon.png" alt="Icon" style="width: 20px;"></button>
</div>
</body>
</html>

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

The button must stay deactivated even if the page is refreshed

When I click on the submit button, it disables for 15 seconds before getting enabled again. However, if I refresh the page, the button becomes immediately enabled without waiting the disable time. Can someone please assist me with this issue? $(window). ...

Any ideas on how to align the links in the navbar at the center of the image instead of having them at the top?

<!DOCTYPE html> <html> <head> <title>Funky Munky Arcade</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha ...

Challenge encountered in handling AJAX response data for presentation

Currently, I am immersed in a project and decided to implement AJAX for smoother form submissions. My initial attempt was trying to display text from a .txt file below the "submit" button, but unfortunately, that approach didn't yield the desired resu ...

Prevent content from occupying unnecessary space below a sticky div

When the "link" on the sticky header is clicked in this scenario, how can I ensure that the linked content item (#mypara) appears below the sticky div rather than directly underneath it where it may be hidden? $(document).ready(function() { $(window ...

JavaScript code to dynamically change the minimum value of an input field when the page

How can I use JavaScript to change the minimum value onload? I tried the following code but it didn't work: <script type="text/javascript">$(document).ready(function(){ $("#quantity_5c27c535d66fc").min('10'); });</script> ...

Rapache and R team up for dynamic leaflet design

I'm currently working on creating a webpage using Rapache and "Leaflet for R". My main goal is to integrate R into an html page using brew. However, I am facing difficulties in displaying my map within the html page without having to save it as an ext ...

Issue with Submit Button Functionality in Django Form Submission

I'm currently facing an issue with an HTML template I built using Bootstrap. My problem lies in the fact that I have a JavaScript function that dynamically adds rows to a Django form with specific fields whenever I need to. However, when I add a row, ...

"Concealing specific choices in Autocomplete with reactjs: A step-by-step guide

I am looking for a way to hide the selected option in a Dropdown menu so that it does not appear in the next dropdown. For example, if "Hockey" is selected in the first dropdown, it should not be displayed in the second dropdown; only "Baseball and badmint ...

What is the most effective method for incorporating CSS using Javascript to target a specific aria-label attribute?

Is there a way to add a CSS property to a specific tag with a particular aria-label on document load? My goal is to change the flex order of a section to 2. I need help using JavaScript to target the aria-label 'block 1' so I can set the order t ...

Is it possible to trigger an AJAX request twice?

<table><form action="/roulette.php" name="ismForm" method="get"> <select id="selez3c" name="bet3c" size="1" class="selezionev" > <option value="0.50">$0.50</option> <option value="0.75"& ...

Arrange the "See More" button in the Mat Card to overlap the card underneath

I'm currently working on a project that involves displaying cards in the following layout: https://i.stack.imgur.com/VGbNr.png My goal is to have the ability to click 'See More' and display the cards like this: https://i.stack.imgur.com/j8b ...

What is the best way to create horizontal lines that span multiple Bootstrap columns?

I am working with a Bootstrap grid that consists of three columns in a row. My goal is to add a line across all columns under every row of content written in the columns. <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.boo ...

Tips for concealing a div upon reaching a specific scroll point, even with varying content sizes

Hey there! I am completely new to web programming and currently working on a landing page. The challenge I'm facing is that the content in the first column is dynamic, meaning it can vary in length. I'm looking for a way to hide my call-to-actio ...

Is there a way to center the text at 0% using text-align in Bootstrap?

My progress bar, designed with Bootstrap, currently displays the text in a way that is not centered as desired. The issue I am experiencing is that the "0/0" text shifts to the left and using text-align: center; does not seem to resolve this alignment pro ...

Utilize Laravel's session messages for stylish toastr notifications

Is there a way to easily convert session messages into Toastr message format without making any changes to the controller code? I'm looking for a solution where Toastr can be used for all session messages seamlessly. @if (session('status')) ...

"Discrepancies Found: React app behaves differently between localhost and live

Lately, I've been working on updating my web portfolio and just launched it on my website. I noticed that the CSS is displaying differently on the live site compared to my localhost preview. The text appears smaller, colors are less vibrant, and the s ...

The getElementById function is unable to locate any matching results

Currently, I am attempting to extract data from an XML file based on the ID of each tag listed within. Below is an example of the XML structure: <?xml version="1.0" encoding="UTF-8"?> <zones> <bedroom id="0"> <fan i ...

iOS exhibits a flashy display of Material Select lighting up

In my attempt to develop a website using Material Design, I encountered an issue with the Material Select component. Whether I utilize MDB (Material Design for Bootstrap) or the Materialize CSS framework, both function well on Windows/OSX/Android devices. ...

Aligning a bootstrap button group at the center of a container

Looking for suggestions on how to center a Bootstrap button group (btn-group) within an element? For instance, consider the following structure: <div id='toolbar'> <div class="btn-group"> <button type="button" class="b ...

column with medium width of 4 is displaying oversized content

Hi there, I'm new to the forum and also to bootstrap. I have a problem with my layout that I can't quite describe (I am thinking in Spanish). Here's what's going on: I have three col-md-4 columns: the first column contains only text, w ...