Is there a way to automatically adjust the size of an input field after dynamic spans have been

I am looking to replicate the tagging functionality found on StackOverflow when posting a new question.

In this case, spans are dynamically added using an input field located next to them.

Here is an example:

<div>
    <div id="multiple-span">
       <span>Item 1<span>
       <span>Item 2<span>
       ...
       <span>Item n<span>
    </div>
    <div id="input-auto-fit">
       <input type="text">
    </div>
</div>

Is there a way to achieve this using just CSS?

I have attempted using display:table-cell for both the inner divs, but the input field is not properly auto-fitting within the outer div.

Answer №1

To achieve the desired layout, I recommend using a combination of table and table-cell properties with some minor adjustments. Here's how you can do it:

#container {
    display: table;
    width: 100%;
    white-space: nowrap;
}
#left-column, #right-column {
    display: table-cell;
}
#left-column span {
    background: gold;
    padding: 4px;
}
#right-column {
    width: 100%;
    padding-left: 4px;
}
#right-column input {
    width: 100%;
    box-sizing: border-box;
}
<div id="container">
    <div id="left-column">
        <span>Item 1</span>
        <span>Item 2</span>
        <span>Item n</span>
    </div>
    <div id="right-column">
        <input type="text"/>
    </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

Error: The 'length' property cannot be searched for using the 'in' operator

Hmm, I keep getting an error that says "Uncaught TypeError: Cannot use 'in' operator to search for 'length' in" Every time I attempt a $.each on this JSON object: {"type":"Anuncio","textos":["Probando ...

Sending information from one Angular 2 component to another

As a newcomer to Angular 2, I am still in the process of understanding its functionalities. Currently, I have two components: 1) List Component This component is responsible for displaying all the products in a store and performing various functions. @C ...

Can this JSON object be created? If so, what is the process to do so?

Is it possible to create a JSON array with integers like the examples below? "data" : [ "1000": "1000", "1200": "1200", "1400": "1400", "1600": "1600", "1800": "1800", ] or "data" : [ 1000: 1000, 1 ...

Evaluation of Library (VueJS) - Displaying various components in an individual test case

Just starting out with testing and have a simple question: I am working on testing a checkbox component. I understand the basics, but how can I render multiple components within one it block? Here is my current code. I am stuck on the second test where I ...

Limit the display of an element to a single occurrence by utilizing jQuery cookies

I have a unique piece of HTML and JS code that showcases an eye-catching modal box. This remarkable feature is present on every page of my website. However, to enhance the user experience, I would like to ensure that this div element is displayed only once ...

Styling a layout with two columns, centered with an offset

I have created a layout with two columns - one on the left and one on the right, with the left column containing two rows. However, I am looking to offset the center point of the column to the right so that the left column occupies about 60% of the space ...

Sometimes the Navbar options fail to show up consistently on the Navbar bar

I recently launched my website at campusconnect.cc Unfortunately, I've noticed that when resizing the window, the navbar options are shifting up and down. Can anyone help me identify the issue and provide guidance on how to resolve it? ...

Retrieving Checkbox Values in PHP: A Step-by-Step Guide

Question: Retrieving values from a checkbox I am facing an issue with the script below where I am only able to retrieve the last selected value of the checkbox. How can I modify the code to fetch all the selected values for validation purposes? Here ...

Issue with Ajax sending data to PHP to delete specific SQL row is hindering success

I am struggling to implement a feature where my users can delete a listing by filling out an HTML form that triggers an AJAX function to send the data to a PHP script. Additionally, I want to include a confirmation message before the deletion process start ...

Sliding a div out from the right using jQuery

I am attempting to create a sliding effect from the right on a div using jQuery. I have managed to accomplish part of it, but not exactly as I would like. You can view my code on this JSFiddle. While the div slides out smoothly, the text inside wraps when ...

Implementing CSRF token for the current window's location

Is there a way to add a CSRF token to all instances where window.location.href is used in my Javascript code? It's not possible to override the window.location object and its properties like window.location.href. Creating a universal function to inc ...

Using PHP, eliminate all hyperlinks from the DOM HTML

I have a string called $processhtml that contains some HTML. My goal is to remove all link tags and their contents from the HTML using PHP. For example: "This is some text with <a href="#">link</a>" should become: "This is some text with" ...

Removing a key from an index signature in Typescript - a step-by-step guide

In my web application built with Angular, we encountered a need for a data type to store translations of strings in different languages. To address this requirement, a team member defined the following type: export class TranslatedString { [language: str ...

Applying jQuery to deactivate blank categories within a sorted directory

I'm in the early stages of learning Javascript/jQuery. I have a list of items (specifically, course offerings) arranged in a UL. Each "course" is represented by an LI element. The list is filtered by categories using jQuery, which controls the visibil ...

I am receiving a success message from webpack indicating that the compilation was successful, but I am encountering a blank page in the

My app.js looks like this: import Home from "./pages/home/Home"; import Login from "./pages/login/Login"; import Profile from "./pages/profile/Profile"; import Register from "./pages/register/Register"; import { Brow ...

Navigating with hashtags in Angular2 and anchors does not change the page position

I recently came across a helpful post that showed me how to append a fragment to the URL. Angular2 Routing with Hashtag to page anchor Although the fragment is successfully added, I'm encountering an issue where the page does not scroll to the speci ...

Converting a JavaScript object into HTML output

I have received the following JSON data: [    {       "fields": {          "url": "http://www.domain_name.co.uk/MP3/SF560783-01-01-01.mp3\n",          "track_name": "Lion City ",          "release_id": 560783,    ...

Is there a method for redirecting my page to a specific href link without triggering a page reload?

This is my HTML code. <a href="http://127.1.1.0:8001/gembead/emstones.html?car=36">Car</a> I am trying to redirect to a specific page with parameters without fully reloading the current page. Is there a way to achieve this task? I believe the ...

Forcing Reload of HTML5 Video to Avoid Caching Issues

Is there a way to instruct the HTML5 Video tag to stream the video chunks on demand/load without caching them on the client side? Essentially, how can I prevent the browser from storing the HTML5 video in its cache? My main objective is to have the video ...

Incorporate a smooth transition effect to a dynamically resizing div button

In my current setup, I have 3 buttons that can toggle between different visible divs. In the future, I may add more buttons to switch between additional divs. At the moment, the first div is active (display set to block), while all other divs are hidden ( ...