Dynamic placeholder and integrated input-group design

I'm currently experimenting with the adaptive placeholder CSS files on my webpage. It seems to work flawlessly for text and select inputs, but I'm encountering an issue when trying to integrate it with Bootstrap's input-group feature.

To better illustrate my problem, I've set up a bootply demo showcasing the discrepancy here (the middle example represents my desired outcome) https://i.sstatic.net/YuqUC.png

The input-group section that struggles with the adaptive placeholder looks like this:

<div class="row">
    <div class="col-sm-6">
        <div id="divSupplierInput2" class="input-group">
            <input class="form-control" type="text" id="Text2" name="txtSupplier" value="" runat="server"
                required="">
            <label for="txtSupplier" placeholder="Supplier">
            </label>
            <span class="input-group-btn">
                <button class="btn btn-secondary btn-sm" type="button">
                    ...</button>
            </span>
        </div>
    </div>
</div>

In contrast, here is an input field where the adaptive placeholder works successfully:

<div class="row">
<div class="col-sm-6">
    <input id="Text1" type="text" class="form-control input-sm" runat="server" required="">
    <label for="txtInvoiceNumber" placeholder="Invoice Number">
    </label>
</div>

I would really appreciate any assistance in resolving this issue. Thank you.

Answer №1

Try utilizing two different divs, col-sm-5 adjust-span-left and col-sm-1 adjust-span-right. Depending on your needs, you can also consider using col-sm-6 to col-sm-11 for varying lengths.

Incorporate the classes adjust-span-left and adjust-span-right into the respective divs and then fine-tune their appearance using CSS:

.adjust-span-right{
  margin-left: -40px;
}
/* For responsiveness on smaller screens */
@media screen and (max-width: 780px) {
  .adjust-span-left{
    float:left;
    width:90%;
    overflow:hidden;
  }
  .adjust-span-right{
    float:left;
    width:10%;
    overflow:hidden;
  } 
}

Next, employ this input structure:

<div class="row">
  <div class="col-sm-5 adjust-span-left">
    <input id="txtInvoiceNumber" type="text" class="form-control input-sm" runat="server" required="">
    <label for="txtInvoiceNumber" placeholder="Invoice Number">
    </label>
  </div>
  <div class="col-sm-1 adjust-span-right">
    <span class="input-group-btn">
        <button class="btn btn-secondary btn-sm" type="button">
            ...
        </button>
    </span> 
  </div>
</div>

UPDATE: Upon inspection, it was observed that the placeholder text does not display correctly on smaller screens when focused. Consequently, adjustments should be made to the responsive CSS for this scenario as well.

Consider implementing something like the following:

@media screen and (max-width: 780px) {
 input[type="text"][required]:focus + label[placeholder]:before,
 input[type="text"][required]:valid + label[placeholder]:before {
   /* Customize the CSS attributes accordingly */
  -webkit-transform: translate(6px, -10px);
  -ms-transform: translate(6px, -10px);
  transform: translate(8px, -10px);
 }
}

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

"Apply a class to a span element using the onClick event handler in JavaScript

After tirelessly searching for a solution, I came across some answers that didn't quite fit my needs. I have multiple <span id="same-id-for-all-spans"></span> elements, each containing an <img> element. Now, I want to create a print ...

Sending Data Between Web Applications in JavaScript

Currently developing a take-away application using AppLab, which uses JavaScript. Due to the limitations of modifying HTML code in AppLab, I had to utilize an external web app for the checkout process (unable to integrate PayPal buttons in AppLab). When th ...

Navigate through the options on the left menu by sliding your

I'm attempting to create a menu that slides in a submenu from the left on hover, but the issue is that with this code, all submenus open instead of just the one related to the hovered link. Here is my HTML code: <ul id="NavMenu"> ...

Various HTML tables display varying column widths even when utilizing the same colgroup settings

I'm facing an issue with multiple HTML tables on a single page, each following this structure: H2 Header Table H2 Header Table H2 Header Table My requirement is to have all tables occupy 100% width, with columns set at widths of 50%, 30%, and 20%. I ...

Should header and footer be incorporated as part of a template design?

Is it considered advisable to include tags such as etc from another page? For example: <?php include_once("header.php")?> Content specific to each individual page <?php include_once("footer.php")?> The header.php file includes: <!DOCTYP ...

Is it possible to dynamically set the body id in React?

I'm currently working on implementing a dark mode feature in my app. The plan is to insert the following code into the root element: <div id="dark"> Afterwards, add the following CSS: #dark { background-color: #1A1A2E; } Subseq ...

What is the best way to align the text below the image using two columns defined in Bootstrap, one for the image and the other for the text?

I am currently working on a web page that has two columns - one for images and one for text. I want the text column to fill in the empty space beside the image. Can someone assist me with this? Thank you. Existing Page: https://i.sstatic.net/qTBPH.png D ...

Bootstrap table issue: server side call fails to trigger

I'm in the process of familiarizing myself with the bootstrap table plugin, which can be found at this link: The specific example I'm attempting to replicate is located here: Here's my HTML code: http://jsfiddle.net/6h5sqs9d/ Within my cg ...

Is injecting href using JavaScript causing issues with MSIE?

Is it considered poor practice to dynamically add href attributes via JavaScript, as shown in the code snippet below? I am experiencing a loading issue in IE8's status bar where it appears to continuously load even after the page has been updated. I s ...

Tips for extracting text from HTML attributes

I attempted to extract text from a webpage, specifically an element within a select tag, but I am struggling to retrieve the text accurately. For instance, in the HTML snippet provided, there is data-initial-rating="4" and title="Members who rated this th ...

What is the best way to delete a dynamically generated div element through JavaScript?

function addDiv { var content = document.getElementById('area1').value; var newDivElement = document.createElement("div"); newDivElement.id = "myNewDiv"; newDivElement.className = "newDivClass"; newDivElement.innerHTML = cont ...

The input field is stretching beyond its intended length

My issue arises from having a div containing a listbox (select), textbox (input text), and button (input submit) inside it, with width:250px set for the entire div and width:100% for each element within. Logically, this should fill the space inside the div ...

Move Picture with Click (like the action on Google Maps)

Currently on the lookout for some code that will enable me to manipulate a floor plan in a manner reminiscent of the one showcased at whitehouse.gov I am in the process of coding a website that would benefit from integrating a similar function with their ...

Displaying PHP errors in input fields

I have noticed that this particular code is functioning correctly. However, I am wondering why I receive an error when I remove the foreach loop ($rows as $row). Is there a method to display the data without utilizing it? <?php require("coneccion.php ...

Refreshing Your WordPress Post Automatically

Can someone assist me with setting up an autorefresh feature for a specific div that has the ID of "blue"? I want the div to automatically update whenever I make changes to a post with that same ID. var auto_refresh = setInterval( function () { $('#b ...

"Exploring ways to retrieve the selected option value in HTML by utilizing the find() function in a Node.js Express application that is

I am currently facing an issue with retrieving a specific document from MongoDB using the find() method. I'm encountering a problem where the result returned is not what I expect in the HTML file. For example, I select MALE and XL, which I know exist ...

Using jQuery and JavaScript to swap images depending on the option chosen in a dropdown menu

On my existing ecommerce website, I have a dropdown menu with the following code: <select data-optgroup="10201" class="prodoption detailprodoption" onchange="updateoptimage(0,0)" name="optn0" id="optn0x0" size="1"><option value="">Please Selec ...

Ways to navigate a div within an iframe that has been loaded

As I load a page(A) inside an iframe, the HTML structure of the embedded content is as follows: <html><body> <div id="div1"></div> <div id="div2"><button>Hello</button></div> </body></html> The ...

I am interested in combining Bootstrap classes with Next.js modules in an inline manner

https://i.sstatic.net/tOTCu.png Is it possible to seamlessly integrate bootstrap classes and custom styles in next.js modules? How can this be achieved? https://i.sstatic.net/ELs3O.png ...