Tips for aligning label and input text on a single line with the input text occupying the remaining space

I'm attempting to have the label and input text appear in the same line. I would like the output to look like this: https://i.sstatic.net/LRFiW.png

The input box should occupy all available space after the label has taken its place. In order to achieve this, I am utilizing flexbox in my HTML:

.abc{
                display: flex;
                flex-direction: row;
                flex-wrap: nowrap;
            }
         
         #some-input {
               margin : 10px;
               display: inline-block;
               vertical-align: middle;
               width: 100%;
               height: 20px;
               font-size:15px;
               border: 2px solid #7e7e7e;
               flex-grow : 30;
            }
         
         #label{
               margin : 10px;
               font-size:15px;
            }
        
      
<div class="abc">
               <div id="label"><b>labelxyz<b></div>
               <input id="some-input" name= "some-input" placeholder="Enter input"/>
            </div>
         
      

However, the input text is not taking up the remaining space as intended. Currently, the output looks like this: https://i.sstatic.net/BEWKp.png

Any assistance on this matter would be greatly appreciated.

Answer №1

Make sure to double-check your tag closures, as some are not properly closed. For example, the <b> tag is left open and the quotation marks are inconsistent throughout.

.abc{
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    
}

#some-input {
    margin : 10px;
    display: inline-block;
    vertical-align: middle;
    width: 100%;
    height: 20px;
    font-size:15px;
    border: 2px solid #7e7e7e;
    flex-grow : 30;
}

#label{
    margin : 10px;
    font-size:15px;
}
<div class="abc">
    <div id="label"><b>labelxyz</b></div>
    <input id="some-input" name= "some-input" placeholder="Enter input"/>
</div>

Answer №2

It appears that the issue lies in not properly closing the <b> tag, which is preventing your input from occupying the remaining space. This results in the unclosed tag being added as a parent element above your input, leading to the problem you are facing.

Below is an updated version with this issue resolved and put into action-

.abc{
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
    }
    
    #some-input {
        margin : 10px;
        display: inline-block;
        vertical-align: middle;
        width: 100%;
        height: 20px;
        font-size:15px;
        border: 2px solid #7e7e7e;
        flex-grow : 30;
    }
    
    #label{
        margin : 10px;
        font-size:15px;
    }
<div class="abc">
        <div id="label"><b>labelxyz</b></div>
        <input id="some-input" name= ”some-input" placeholder="Enter input"/>
    </div>

Answer №3

You've encountered an HTML error where you failed to properly close a tag.

<div class="abc">
    <div id="label"><b>labelxyz</b></div>
    <input id="some-input" name= ”some-input" placeholder="Enter input"/>
</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

Ways to stop Content from Showing below a div container

Hey, I just created a login panel using CSS and HTML. After applying some floats, all the content ended up displaying under the panel. I attempted to use clear: both, but that didn't resolve the issue. My goal is to have all other contents displayed a ...

Guide for adding an OnClick event to a MatTable row:

I am looking to add functionality for clicking on a specific row to view details of that user. For instance, when I click on the row for "user1", I want to be able to see all the information related to "user1". Here is the HTML code snippet: <table ma ...

Troubleshooting my CSS navigation bar - What am I missing?

I've been developing a navigation bar using a combination of HTML, CSS, and JavaScript. After writing the code and setting the display of the bar to fixed, I encountered an issue where the content of the page was overlapping the nav bar. Below you&ap ...

Tips for modifying the default settings of a CSS framework like Material UI

Exploring the realm of CSS for the first time and feeling a bit lost. I am working with material ui alongside react and redux. My goal is to customize certain properties of a specific component, such as TextField with the disabled attribute. Upon inspectin ...

Increasing the height of a vertical division to reach its maximum vertical capacity

Looking for ways to make my html page more visually appealing. It is divided into 4 sections: Header, menu, content, and footer. The header is positioned at the top of the page, while the footer is located at the bottom. In between these sections are the m ...

Ensuring the mobile menu button is always visible on Bootstrap 4, regardless of screen size

Is there a way to consistently display the mobile menu button regardless of screen size? I want the links to only appear when someone clicks on the mobile button. Thank you! I am aware of a solution for Bootstrap 3, but it does not seem to work with Boots ...

Tips for ensuring an image fits perfectly within a MUI grid

I am currently working on an application that involves a collection of cards. My tech stack includes React and MUI v5. One issue I've been facing is with the grid layout, specifically in trying to keep the image size consistent within the grid item. ...

When displaying a SELECT tag in Meteor JS with Blaze, remember to apply the class "ian:accounts-ui-bootstrap-3" to the element

Currently, my project is running on Meteor version 1.6.1.1. Instead of using the accounts-ui package, I have opted for ian:accounts-ui-bootstrap-3. As part of customization, I have included a custom field as a <select> element in the code. Here&apos ...

Unusual occurrences observed with table cell padding in CSS

When I include a TD padding in my CSS like this: #maincontent table td, #maincontent table th { padding: .333em 0 .333em .25em; } In Safari and IE, the padding is applied correctly to the TD, but not in Firefox. If I apply the TD padding only to th ...

Issue with Ajax request failing to successfully send and retrieve raw HTML data

Utilizing an Ajax call to trigger a C# method that is responsible for processing user paste input by eliminating unwanted html tags and attributes. Encountering an issue where my Ajax call fails when I paste in content with html formatting (containing tag ...

What is the best way to ensure only one item is being selected at a time?

In the initial state, I want 'ALL' to be automatically selected. Clicking on another item should change the classes so that only 'this' has the class and the others do not. However, I am facing an issue where 'ALL' cannot be r ...

Determine the product of the total value entered in a textbox and the percentage entered in another textbox to

I've been searching high and low to crack this puzzle, attempting to create a simple calculation on change event using 3 textbox inputs Textbox for Item Cost Manually entered Discount Percentage value e.g. 29 Total: which will be the result ...

Intrusive JQuery Code Incorporating Itself into SharePoint 2010's HTML Markup

There seems to be an issue with my content editor web part wherein the menu, which is clickable and hoverable due to the jQuery installed, is causing some unexpected behavior. Whenever the menu is clicked or hovered over, it changes the content in the adja ...

Custom dropdown selection using solely JavaScript for hidden/unhidden options

I'm trying to simplify things here. I want to create a form that, when completed, will print the page. The form should have 3-4 drop-down lists with yes or no options. Some of the drop-downs will reveal the next hidden div on the form regardless of th ...

Is there still a need to preload dynamic images in the background?

Imagine you have HTML code that includes an image with a placeholder: <img class="lazy-load" src="http://via.placeholder.com/150/?text=placeholder" data-src="http://via.placeholder.com/150/?text=real%20image"/> At some stage, you want to implem ...

If the value stored in $_SESSION['uname'] is not "teacher", redirect back to the homepage

I am currently working on a webpage and I want to restrict access to only users with the username "teacher". I came across this code snippet: <?php session_start(); if(!isset($_SESSION['uname'])){ header('location:(main p ...

Capture cached images stored in the browser memory without relying on the source attribute of the <img> tag

Imagine you're managing a website, samplewebsite.com and you find that the images on it have been resized to very low quality. When you click on an image, you are directed to a 'view_image' page, for example samplewebsite.com/view?image=u ...

Dynamic Image Grid Created Using JavaScript Glitches

My dilemma involves using JQuery to create an HTML grid of images styled with Flex Boxes. The setup works perfectly on desktop, but when viewing it on mobile devices, the images begin to act strangely - jumping, overlapping, and even repeating themselves i ...

The inputs are not responding to the margin-left: auto and margin-right: auto properties as expected

I'm having trouble aligning an input in a form to the center. Even though I have included display: block in the CSS, using margin-left:auto and margin-right: auto is not yielding the desired result. To illustrate the issue more clearly, I've cre ...

Modify the appearance of a nested div using CSS hover on the main JSX container

Within the material-ui table component, I am dynamically mapping rows and columns. The className is set to clickableRow. The TableRow also includes a hover options div on the right side: const generateTableHoverOptions = () => { if (selected) { ...