The button is not properly connected to the input

My dilemma involves attaching the clear button to the search input field, resulting in an unexpected outcome:

https://i.sstatic.net/igkpx.jpg

The issue seems to be linked to the "Black Dashboard PRO" theme that I am currently using.

<form>
    <div class="input-group">
        <input id="customer-search" type="text" class="key form-control" placeholder="Search">
        <span class="input-group-addon">
        <div>
            <button class="clear btn btn-default" type="button" title="Clear">
                <span class="tim-icons icon-simple-remove"></span>
            </button>
        </div>
        </span>
    </div>
</form>

This is the button's CSS as defined by the theme:

`.btn:not(:disabled):not(.disabled) {
    cursor: pointer;
}
button, html [type="button"], [type="reset"], [type="submit"] {
    -webkit-appearance: button;
}
.btn {
    cursor: pointer;
}
.btn, .navbar .navbar-nav > a.btn {
    border-width: 2px;
    border: none;
    position: relative;
    overflow: hidden;
    margin: 4px 1px;
    border-radius: 0.4285rem;
    cursor: pointer;
    background: #344675;
    background-image: linear-gradient(to bottom left, #344675, #263148, #344675);
    background-size: 210% 210%;
    background-position: top right;
    background-color: #344675;
    transition: all 0.15s ease;
    box-shadow: none;
    color: #ffffff;
}
.btn-default {
    color: #ffffff;
    background-color: #344675;
    border-color: #344675;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}
.btn {
    display: inline-block;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    border: 1px solid transparent;
    padding: 11px 40px;
    font-size: 0.875rem;
    line-height: 1.35em;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}`

Answer №1

remove the margin of '.btn, .navbar .navbar-nav > a.btn'

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <style>
    .btn:not(:disabled):not(.disabled) {
    cursor: pointer;
}
button, html [type="button"], [type="reset"], [type="submit"] {
    -webkit-appearance: button;
}
.btn {
    cursor: pointer;
}
.btn, .navbar .navbar-nav > a.btn {
    border-width: 2px;
    border: none;
    position: relative;
    overflow: hidden;
    border-radius: 0.4285rem;
    cursor: pointer;
    background: #344675;
    background-image: linear-gradient(to bottom left, #344675, #263148, #344675);
    background-size: 210% 210%;
    background-position: top right;
    background-color: #344675;
    transition: all 0.15s ease;
    box-shadow: none;
    color: #ffffff;
}
.btn-default {
    color: #ffffff;
    background-color: #344675;
    border-color: #344675;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}
.btn {
    display: inline-block;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    border: 1px solid transparent;
    padding: 11px 40px;
    font-size: 0.875rem;
    line-height: 1.35em;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
</style>
</head>

<body>
  <form>
    <div class="input-group">
      <input id="customer-search" type="text" class="key form-control" placeholder="Search">
      <span class="input-group-addon">
        <div>
            <button class="clear btn btn-default" type="button" title="Clear">
                <span class="tim-icons icon-simple-remove">X</span>
      </button>
    </div>
    </span>
    </div>
  </form>
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>

</html>

Answer №2

It seems that the issue can be resolved by simply eliminating the margin from the button, as shown in the demo below:

.btn:not(:disabled):not(.disabled) {
    cursor: pointer;
}
button, html [type="button"], [type="reset"], [type="submit"] {
    -webkit-appearance: button;
}
.btn {
    cursor: pointer;
}
.btn, .navbar .navbar-nav > a.btn {
    border-width: 2px;
    border: none;
    position: relative;
    overflow: hidden;
    margin: 4px 1px;
    border-radius: 0.4285rem;
    cursor: pointer;
    background: #344675;
    background-image: linear-gradient(to bottom left, #344675, #263148, #344675);
    background-size: 210% 210%;
    background-position: top right;
    background-color: #344675;
    transition: all 0.15s ease;
    box-shadow: none;
    color: #ffffff;
}
.btn-default {
    color: #ffffff;
    background-color: #344675;
    border-color: #344675;
    box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}
.btn {
    display: inline-block;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    border: 1px solid transparent;
    padding: 11px 40px;
    font-size: 0.875rem;
    line-height: 1.35em;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.no-margin{
  margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  
<h4>your default code with issue</h4>      
  <form>
    <div class="input-group">
        <input id="customer-search" type="text" class="key form-control" placeholder="Search">
        <span class="input-group-addon">
        <div>
            <button class="clear btn btn-default" type="button" title="Clear">
                <span class="tim-icons icon-simple-remove">X</span>
            </button>
        </div>
        </span>
    </div>

<h4>after removed margin from button</h4>
<div class="input-group">
        <input id="customer-search" type="text" class="key form-control" placeholder="Search">
        <span class="input-group-addon">
        <div>
            <button class="clear btn btn-default no-margin" type="button" title="Clear">
                <span class="tim-icons icon-simple-remove">X</span>
            </button>
        </div>
        </span>
    </div>
</form>
  
  
  
  
</div>

</body>
</html>

Answer №3

Revise HTML Code & Include additional Class in span input-group-append

<div class="input-group">
        <input id="customer-search" type="text" class="key form-control" placeholder="Search">
        <span class="input-group-append new-class">
           <button class="clear btn btn-default" type="button" title="Clear">
              <span class="tim-icons icon-simple-remove">X</span>
           </button>
        </span>
    </div>

https://jsfiddle.net/lalji1051/p7h903wL/4/

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

Preserve input values after form submission in <?php> code block

I would like to retain form values after submission. I have come across some techniques that claim to do just that: However, when I try to run the HTML file, I encounter two issues: firstly, the code does not function as intended and secondly, PHP snippet ...

Having difficulty grasping the concept behind the prepend method's functionality

I encountered an issue with my code, where I successfully created a <th> element initially, but faced problems when trying to create it repeatedly. function createTH(){ var noOfRow = document.getElementById("addItemTable").rows.length; var t ...

Stylish CSS: Jagged 3-dimensional rotated text

Have a look at this Codepen to see the issue. As the text moves into the background, more aliasing appears. A screenshot taken in Chrome on macOS (similar appearance in FF & Safari): https://i.sstatic.net/n746I.png I've experimented with different ...

Python KeyError: Implementing a Strategy for Displaying Two Divs Side by Side Efficiently with Dynamic Data

media.py: http://pastebin.com/r1nxPzTQ This file contains a Python class with methods like __init__ and show_trailer(self). fresh_tomatoes.py: http://pastebin.com/bcdUYiiu It's a Python script that generates an HTML file and populates it using data ...

What are the advantages of using classes versus ids for managing multiple li elements in example 20 with knockout and jQuery? Is one option more efficient and easier to maintain

<ul class="sellerDetails sellerdetailsData " data-bind="attr: { id: 'sellerdetailsData-' + $index()}"> <li><span class="buyerprocess-sprite seller-name"></span> <p class="leftfloat"> <span data-bind=" ...

If a user types in Korean characters in the input field and then clicks away to any other part of the screen, the input field will automatically regain focus

jsfiddle instructions for testing: type Korean characters in the input field scroll down until the input field is no longer visible Click anywhere on the screen Expected result: the input field will come into focus with (Korean text) If the user enters K ...

What is the best way to find information in a multi-page table?

I've implemented a table with pagination and search functionality to look up data within the table. However, currently the search only works within the current page of the table rather than searching the entire dataset. Is there a way to modify the se ...

Hey there! I'm experiencing an issue with the jquery function $(this).childen().val()

Here is my HTML and JS/jQuery code: (function($) { $('.list-group li').click(function(){ console.log("push li"); console.log($(this).attr('class')); console.log($(this).children('.hidden_input&ap ...

Bootstrap 4 and Angular 7 application experiencing issues with toggle button functionality in the navigation bar

I am currently working with Angular7 and Bootstrap4. I am attempting to integrate a navbar into my application, but I am facing an issue where the toggle button does not work when the navbar is collapsed. It is important for me to mention that I do not wa ...

Having trouble getting the JavaScript function to run when clicking a button inside a div or form?

Hey there, so I've got this scenario where I have a button nestled within a div. Take a look at the HTML snippet below: <div class="row"> <button type="button" id="submit">Send</button> </div> Prior to this button, there ...

Tips for showcasing elements individually in JavaScript when a button is clicked and halting on a random element

I have some names stored in h3 tags. I want to highlight one name at a time when I click a button, stopping at a random name. <div class="all-names"> <h3 class="name-one"><span class="line">Name ...

Uncovering classes and selectors in CSS files that match an element with JavaScript

Trying to explain my idea with an example since it's a bit tricky. Imagine we have this HTML code: <ul> <li id="myli" class="myclass">Hello</li> </ul> along with the corresponding CSS: .myclass{ color:red; } li.m ...

Setting up an i18n project in AngularJS

I just embarked on my angularjs journey yesterday with little to no prior knowledge about it. My initial goal is to centralize all the labels for my UI in a file (to facilitate swapping them out for i18n). As far as I know, this can be achieved by importi ...

Utilize Angular 6 [ngClass] to dynamically add a class composed of multiple variables through direct string concatenation within [ngClass]

Currently, I am working with Angular 6 and I have the following variables: var1 = 'my'; var2 = '-'; var3 = 'class'; I am trying to achieve something like this: <div [ngClass]='var1 + var2 + var3'></div> ...

Header that stays fixed at the top within a collapsible accordion layout

I'm experimenting with creating an accordion-style layout that transitions to an accordion on smaller screens, as shown by resizing the snippet attached to this question. I'm using flex to establish a sticky header, which is currently only applie ...

Eliminate the AM and PM options from the input time selection dropdown menu in HTML

https://i.sstatic.net/wKeQk.png Is it possible to eliminate the AM / PM option from the input time format dropdown? The form builder currently uses a 24-hour format that includes the AM / PM field. ...

Adding a new tab on button click with React js and Bootstrap 4 - a step-by-step guide

Is there a way to dynamically add a tab when a button is clicked? I've attempted various examples, but none of them have been successful for me. For instance: Initially, there are 2 bootstrap tabs named Tab1 and Tab2. There is also an "Add Tab" butt ...

Scroll to a new section of the page if the specified id or name cannot be found

Currently, I am dealing with an exceptionally lengthy textual content page. <p class="parahead">401. Heading </p> <p>other html content</p> <p class="c2">some more data</P> ... <p class="parahead">402. Another hea ...

Is it possible to create a dynamic zig-zag design with CSS that

I am looking to design a dynamic snake/zigzag layout that consists of square images and circles, starting from the center of the container and descending in a winding fashion. The number of elements is not fixed and is generated based on data received fro ...

Removing HTML tags from a string while preserving specific tags in JavaScript

Here is a JavaScript string that I am working with: var test = "<p>test</p> FOLER.PRODUCTS<12345><level-2>"; I'm trying to remove the HTML tags from the string because the service I'm using doesn't accept them. Here ...