What is the best way to place an input box inside a td element so that it occupies the majority of the available space

My code snippet showcases an issue where the input box is not fitting properly inside the table. Running the snippet will provide a clearer understanding. I am attempting to make the input box take up the entire space of the td element within the table. How can this be achieved?

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>

    <title>How to properly fit input box inside td tag within a table?</title>
  </head>
  <body>
     <div class="table-responsive">
                    <h3 class="text-center">Experience/Skills *</h3>
                    <table class="table table-hover table-bordered" id="employeeStatusTable">
                      <thead>
                        <tr>
                          <th style="max-width: 10%">#</th>
                          <th style="max-width: 30%">Technology Category</th>
                          <th style="max-width: 60%">Names</th>
                        </tr>
                      </thead>
                      <tbody>
                       
                            <tr>
                                <td>1</td>
                                <td>Category 1</td>
                                <td>                                 
                                        <select data-placeholder="Begin typing a name to filter..." multiple  name="select1" class="chosen-select" >
                                            <option value=""></option>
                                            <option>Option1</option>
                                            <option>Option2</option>
                                            <option>Option3</option>
                                            <option>Option4</option>
                                            <option>Option5</option>
                                        </select>                                  
                                </td>
                            </tr>
                            
                            <tr>
                                <td>2</td>
                                <td>Category 2</td>
                                <td>                                  
                                        <select data-placeholder="Begin typing a name to filter..." multiple  name="select2" class="chosen-select" >
                                            <option value=""></option>
                                            <option>Option1</option>
                                            <option>Option2</option>
                                            <option>Option3</option>
                                            <option>Option4</option>
                                            <option>Option5</option>
                                        </select>                                  
                                </td>
                            </tr>
                      </tbody>
                    </table>
                  </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  <script>
$(".chosen-select").chosen({
  no_results_text: "Oops, nothing found!"
})
</script>
  </body>
</html>

Bootstrap 5 and jQuery 2 are utilized in this scenario. How can the input box be properly embedded inside the table, as intended?

Answer №1

Simply include width: "100%" in your chosen JS as shown below

$(".chosen-select").chosen({
  no_results_text: "Oops, nothing found!",
  width: "100%"
});

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

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2924243f383f392a3b0b7e657b6579">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>

    <title>How to fit input box inside td tag in my way?</title>
  </head>
  <body>
     <div class="table-responsive">
                    <h3 class="text-center">Experties/Skills *</h3>
                    <table class="table table-hover table-bordered" id="employeeStatusTable">
                      <thead>
                        <tr>
                          <th style="max-width: 10%">#</th>
                          <th style="max-width: 30%">Technology Category</th>
                          <th style="max-width: 60%">Names</th>
                        </tr>
                      </thead>
                      <tbody>
                       
                            <tr>
                                <td>1</td>
                                <td>Category 1</td>
                                <td>                                 
                                        <select data-placeholder="Begin typing a name to filter..." multiple  name="select1" class="chosen-select" >
                                            <option value=""></option>
                                            <option>Option1</option>
                                            <option>Option2</option>
                                            <option>Option3</option>
                                            <option>Option4</option>
                                            <option>Option5</option>
                                        </select>                                  
                                </td>
                            </tr>
                            
                            <tr>
                                <td>2</td>
                                <td>Category 2</td>
                                <td>                                  
                                        <select data-placeholder="Begin typing a name to filter..." multiple  name="select2" class="chosen-select" >
                                            <option value=""></option>
                                            <option>Option1</option>
                                            <option>Option2</option>
                                            <option>Option3</option>
                                            <option>Option4</option>
                                            <option>Option5</option>
                                        </select>                                  
                                </td>
                            </tr>
                      </tbody>
                    </table>
                  </div>

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fbf6f6edeaedebf8e9d9acb7a9b7ab">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  <script>
$(".chosen-select").chosen({
  no_results_text: "Oops, nothing found!",
  width: "100%"
});
</script>
  </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

Using jQuery to Send a POST Request and Delete a File when a Button is

Seeking assistance for a project I'm working on. I have created this page where users can access an image gallery. Currently, I am adding a feature to allow users to delete images. Following advice from the community here here, I am exploring the jQ ...

Showcasing distinct signs in a Span within reactJS is simple by utilizing the appropriate syntax

In ReactJS, I am trying to display the following special characters within a span: <span class='child tm'> <img src={tick} class='tick'/>A special character !"#$%&'()*+,-./:;<>=?@[\]^_`|{}~ </span ...

Pinterest Style Card Layout using React-Semantic-UI

Utilizing semantic-ui-react in React, I am working on displaying cards with varying heights based on the amount of text. I am aiming for a pinterest style layout where each card's height adjusts according to the content it contains. .... <Card.Co ...

Some devices experiencing website update issues while others are successful

My website is functioning properly on my laptop and phone, but not on my school iPad (managed by the district). I have already cleared the cache, but the site does not update. It was working fine earlier, and I need to present it next Monday. Please help a ...

emulating an android device to test html5 applications

Recently, I embarked on developing an HTML5 game with the help of VS Code. I envision it being predominantly accessed from PCs and laptops. I successfully configured the Chrome debugger to facilitate debugging the webpage in Chrome. However, I am eager to ...

Ways to effectively conceal an HTML div element with CSS or JavaScript

Is there a way to hide the div element that is nested inside a bootstraps radio or checkbox container using jquery? I'm unable to upload an image, but here is a preview: http://prntscr.com/6wrk2m <style> .my-radio{ border: 1px solid #F0F; } &l ...

What is the best way to trigger two separate JavaScript/jQuery functions on a single HTML control, specifically a text field, in response to

Here is the HTML code I have for a text field where functions are implemented: <input type="text" class="form-control" size="20" onblur="GetLocation();" id="zip_code" name="zip_code" value=""> <input type="text" class="form-control" size="20" r ...

Android failing to adapt to font size changes set by media queries in HTML code

Recently, I've been facing an unusual issue on a Nexus 7 where changing the font-size on the HTML element seems to be ignored. Removing the smaller font size resolves the problem but creates new issues for phone displays. CSS: html { font-size: 10px ...

Why does CSS work on Localhost but not on the server in IE?

I recently faced a bizarre issue. After designing a website using CSS3, I uploaded it to the server only to discover that most of the features are not supported by IE8, making the site layout unrecognizable. Even more strange was the fact that IE8 display ...

What is the process for layering one image on top of another in HTML?

Don't miss checking out the amazing website wplayout.com. On the homepage, there is a stunning gallery that I want to enhance by adding a "premium" tag image on top of each picture. Currently, the premium image is displayed in the top right corner of ...

When the browser is zoomed out, the panes do not undergo any changes in size

I'm having trouble with my HTML code causing the jquery-ui-layout library to malfunction. Specifically, when I zoom out in my browser (Chrome/Firefox), the library fails to recalculate the widths/heights of containers. In my HTML, all white panes are ...

Accessing information from a json response using an ajax request

Currently, I am making an ajax call to fetch the longitude and latitude based on a pin code. Here is how I approached it: $(document).ready(function () { $.ajax({ type: "GET", url: "http://maps.googleapis.com/ma ...

There seems to be a white space problem located beneath the header photo and the initial

I'm a beginner at coding and working on this project for fun. I'm almost done, but I can't get rid of a white space that's dividing my header from the first section. See the screenshot below: https://i.stack.imgur.com/a1flt.png Even af ...

JSONP Error - "SyntaxError: Unexpected token caught"

Just to start off, I want to mention that I'm new to working with jsonp. This is my first time diving into the world of JSONP. Currently, I'm using a jQuery ajax call to retrieve data from a website. Here's a snippet of my jQuery code: $. ...

Enhance user experience with AngularJS Bootstrap autocomplete feature by automatically filling input box when hovering over dropdown options

I am currently implementing the AngularJs Bootstrap typeahead functionality. Typically, when we enter text that matches an option, the dropdown list appears. https://i.stack.imgur.com/395Ec.png What I aim for is to automatically fill the textbox with the ...

Troubleshooting the problem of keyframes chaining animation in React animations

Hey there! I am new to CSS animation and currently working on a project where I need to slide in a div element and then slide it out of the screen using keyframes in Next.js. The sliding in part is working perfectly fine, but I'm facing some issues wi ...

Fetching data from ExpressionEngine using AJAX

Looking to display ExpressionEngine entries in a popup modal using jQuery and ajax. When the user clicks on an entry title, the full entry should be displayed in the modal. Additionally, next and previous buttons within the modal are desired for navigation ...

Display two columns side by side using Bootstrap on all screen sizes

I'm attempting to have two column divisions appear on the same line. Take a look at my code: <div class="col-md-12"> <div class="row"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> Left Division </div> ...

Trouble is brewing between jQuery AJAX and PHP's collaboration

After following a tutorial on jQuery AJAX (found here) and the official one from jQuery's documentation (available here), I was unable to get it to work. Surprisingly, switching to an XML file instead of a PHP file for pulling data using jQuery worked ...

Avoiding jQuery selector

What is the reason for the selector working in the first example but failing in the second one? Check out jsfiddle. <div id="hello[1][2]_world">&nbsp;</div> <textarea id="console"></textarea> <script> $(document).re ...