Enhance your input text form with a stylish button using Bootstrap

This is the code snippet I am currently working on:

        <h2>Workout Selector</h1>
        <div class="form-group">
            <label for="workout-name">Search by Keywords (Comma Separated):</label>
            <input type="text" class="form-control" id="workout-keywords">
        </div>

When rendered, it looks like this: https://i.sstatic.net/WKHDK.jpg

However, I would like to replace the red box with a button instead: https://i.sstatic.net/Cbplv.jpg

(What steps should I take to make this adjustment?)

Edit: It should not be the submit button

Answer №1

check out this code and customize the color scheme to your liking.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="col-lg-6">
<div class="input-group">     
  <input type="text" class="form-control" placeholder="Search for...">
   <span class="input-group-btn">
    <button class="btn btn-secondary" type="button">Go!</button>
  </span>
</div>
</div>

ref :

Answer №2

One way to approach this could be using columns, like so:

    <div class="form-group">
        <div class="col-md-12">
          <label for="workout-name">Search by Keywords (Comma Separated):</label>
        </div>
        <div class="col-md-8">
          <input type="text" class="form-control" id="workout-keywords">
        </div>
        <div class="col-md 4">
          <span class="btn btn-default">Button</span>
        </div>
    </div>

Answer №3

To ensure the button is positioned above the input field and prevent the text from being hidden by the button, you can utilize the CSS property position:absolute along with padding-right for the input field. Here's an example of how you can achieve this:

<h2>Exercise Finder</h2>
<div class="input-group">
   <label for="exercise-search">Search Exercises (Separated by Commas):</label>
   <input type="text" class="form-control" id="exercise-input">
    <button type="submit">Search</button>
 </div>

.input-group {
  position: relative;
  padding: 0;
  
  input {
    padding-right: 70px;
    height: 30px;
    line-height: 30px;
    width: 100%;
  }
  
  button {
    position: absolute;
    right: 0;
    top: 0;
    width: 70px;
    line-height: 30px;
    text-align: center;
    z-index: 500;
  }
}

Answer №4

If you're looking to achieve a specific layout with display flex and input-group, there's a neat trick you can use with the input-group-addon class/element. Here's how you can do it:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form class="form-inline" style="width:300px;margin:10px;">
  <div class="form-group">
    <label class="sr-only" for="test">input here something</label>
    <div class="input-group" style="display:flex;">
      <input type="text" class="form-control" id="test" placeholder="input here something">
        <button type="button" class="input-group-addon btn btn-primary" style="width:50px;">go</button>
    </div>
  </div>
</form>

Give this a try and see if it helps!

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

Can you have two navigation bars and a picture all in one Bootstrap layout?

I have a requirement to use a single image on two different Bootstrap navbars. However, the issue is that the image appears split between the two navbars.https://i.stack.imgur.com/jUnIL.png My goal is to display the full image without it being divided bet ...

Make sure to load the gif image before any other images are loaded from the css

Hey there, I'm attempting to display a GIF image before the actual image loads. I found a great example to accomplish this: Example: Java Script function loadimage(imgsrc, change){ var loadimage = new Image(); loadimage.onload = changesrc(imgsrc, c ...

The DIV element fails to encompass all of its content

There seems to be an issue with the only div element on my page. It's covering the middle of the page, but I managed to make it extend all the way down using CSS tweaks. However, there is a problem - the video inside the div is overflowing: Below is ...

Tips for creating a mobile-friendly Bootstrap carousel that is both scalable and zoomable while maintaining the default slide functionality

I have a website using Bootstrap 4.x carousel. The layout is user-scalable with the following viewport meta tag: <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2, shrink-to-fit=no">. Currently, users can pinch to z ...

How can you resolve redefinition warnings detected by the CSS Validator?

After running my site through the W3C CSS Validator, I was surprised to see that it returned a total of 3146 warnings. The majority of these warnings are redefinition alerts, such as: .fa.fa-check Redefinition of color .fa.fa-check Redefinition of ...

Incorporating Masonry-inspired images into a website's design section

I have been working on incorporating a masonry layout of images into my website, but I am facing alignment issues. The images are simply stacking on top of each other instead of creating the desired masonry effect. Are there any tips on how to create a mas ...

How can I use CSS to make a child element in a grid layout stretch horizontally to full width?

I am currently working on designing a grid layout that will display a child element when clicked. Here is what I have in mind: [ link1 ] [ link2 ] [ link3 ] [ link4 ] [ link4 ] [ link4 ] When clicked, it will turn into: [ link1 ] [ link2 ] ...

Displaying divs of varying heights in a line

I'm facing a challenge in creating floating divs, just like illustrated in the image provided in the link below. Currently, I am employing the float left property to align all the divs next to each other. The first picture displays the default layout ...

Combine two columns into a single table column using HTML/CSS and JavaScript with the help of Datatables

I utilize the DataTables library from https://datatables.net/ to create sortable and searchable tables on my website. However, my table becomes too wide due to the numerous columns it contains. I am looking for a way to condense the width by merging relate ...

The clash between the position:fixed and overflow:visible styles in CSS

I'm working on a webpage layout that includes an image positioned on the right side of the page. I want to create horizontal scroll bars when the browser window is resized, so I added the overflow: visible property. Additionally, I want the image to b ...

Interested in customizing the hover color of the header links in WordPress?

I'm currently working on customizing the hover color of the links in my WordPress header created with Elementor Page Builder. I tried several CSS solutions by inspecting elements and adding them to the custom CSS section in WordPress, but none seemed ...

Make sure that the two rows in my Bootstrap table are consistently positioned next to each other, regardless of the length of the text

When working with a Bootstrap panel containing text inside a table, I've encountered a challenge. One side features links while the other displays descriptions. At times, I find myself having to artificially lengthen the text to ensure it aligns corre ...

Switch effortlessly between one animation and another with Angular.js

I have two animations named "prev" and "next". Upon clicking the prev button, the "prev" animation should play. Similarly, when you click on the "next" button, the "next" animation should be triggered. I am using ng-class to achieve this behavior. How can ...

What is the reason behind IE's decision to reduce the size of password boxes compared to text

Take a look at the uncomplicated form right below. You'll notice that it consists of a text box positioned above a password box. In older versions of Internet Explorer like 7 and 8, as well as possibly in other browsers, you might observe that the tex ...

Personalized animated Reactflow Connection Lines

My goal is to develop a personalized animated connection lines in reactflow, rather than using the default dashed line that appears when the animated: true prop is applied. I am aware that we can customize the styling by using the following code snippet: ...

Nextjs Image Optimization: Accelerating Web Performance with Images

Encountering an issue when trying to display multiple images in nextjs. I noticed that without setting position: relative for the parent element and position: absolute for the child element, along with specific height and width values for the Image itself, ...

Adjusting the background color of <tr> depending on the number of <tr> elements in the HTML using CSS

When working on my HTML page, I have utilized multiple <tr> tags with different bgcolor values such as: <tr bgcolor="#000000"> <tr bgcolor="#E5F1CC"> <tr bgcolor="#D30A0A"> <tr bgcolor="#656766"> I am aiming to assign unique ...

Why isn't Bootstrap validation functioning properly in my Modal?

I am attempting to implement client-side validation using bootstrap, as outlined here: https://getbootstrap.com/docs/4.0/components/forms/#custom-styles The challenge I'm facing is that my form is within a modal. When I click the submit button, nothi ...

Is there a way to ensure that the images in the slider all remain consistent in size?

I recently created a slider using bootstrap and encountered an issue with image display on mobile screens compared to laptop screens. On a Laptop screen: On a Mobile screen: The images on the mobile screen are not fitting properly within the slider, and ...

What is the best way to navigate from a button in NextJS to another page that I have built within the same application?

As I work on developing a website for a pet rescue charity using Next.js, I am facing an issue with getting my button or link to function correctly. Every time I try to navigate to another page within my Next.js app, I encounter a 404 error stating "This p ...