Tips for wrapping text without breaking the input field onto a new line

I'm struggling to create the following UI design.

[text1] [inputBox1]
[text2] [inputBox2]
[text3] [inputBox3]

The length of text1, text2, and text3 can vary. So, as the length of text increases, their width should also increase, causing the input box to move towards the right. In cases where the text is too long, it should wrap around. Someone suggested using flexbox, but I'm not sure how to get started with it. Can someone please assist me?

Here is the basic structure:

<div>
    <div>text1</div>
    <div>inputBox1</div>
    <div>text2</div>
    <div>inputBox2</div>
    <div>text3</div>
    <div>inputBox3</div>
    .
    .
    .
    .
</div>

Answer №1

To enhance the structure, enclose every input and text within a div marked with the class line. Then specify that each of these divs should have the CSS property display:flex;.

.line{
  display:flex;
}
input{
  margin-left:auto;
}
<div>
  <div class="line">
    <div>This is a lot of repetitive insignificant text. This is a lot of repetitive insignificant text.</div>
    <input>
  </div>
  <div class="line">
    <div>This is a lot of repetitive insignificant text.</div>
    <input>
  </div>
  <div class='line'>
    <div>text3</div>
    <input>
  </div>
</div>

Answer №2

Assign a class or id to each div to distinguish between the container and child in your CSS code, like so:

 <div id="container">
    <div id="wrapper">
        <div class="textChild">text1</div>
        <div class="inputChild">inputBox1</div>        
    </div>
    .
    .
    .
  </div>

Then, use CSS to style every div in your container using the flexbox model. The #wrapper is your flexbox container with display: flex, and .textChild and inputChild are your child elements with the flex property defined as 1 or something else. You can find a helpful example on this answer.

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

Chrome browser hover malfunction issue

The menu plugin I am using on my website opens submenus when hovering over main items. While it works fine on the Firefox browser, on Chrome the submenu does not appear in the desired location (Please see attached screenshot). What's even stranger is ...

Tips for correctly positioning CSS elements:

I am currently working on a slider using noUi Slider and aiming for an elegant solution. To accommodate the large size of the handle, I expanded the base UI with extra values which are not allowed, causing the handle to jump back to the permitted values. T ...

The seamless integration of React.js with HTML

My friend and I are beginners in the world of programming, with a solid grasp of html, CSS, and JavaScript. We're currently collaborating on a small project where we aim to create a chat system. While researching resources for our project, we came acr ...

Restricting Horizontal Scrolling in Dash DataTable with multi-tiered header (without any additional empty gaps)

I'm currently developing a Dash application using Plotly that showcases two tables, specifically dash_table.DataTable, each with multiple columns. The initial table features a multi-level header. For both tables, the first few columns are fixed while ...

Is there any way to have my video begin playing again without manual intervention?

I am looking to enhance my script by adding a function that will automatically start the video once it has finished playing. I believe I need to reset the currentTime property back to 0, but I'm not sure how to implement this in my script. Are there a ...

Does the Sass default compiler have built-in autoprefixing capabilities?

Suppose I have the following sample code: :fullscreen a { display: flex; } Is it possible for the default sass compiler to transform it into this: :-webkit-full-screen a { display: -webkit-box; display: flex; } :-moz-full-screen a { display: fle ...

Tips for managing the creation of dynamic Bootstrap cards using jQuery

I am embarking on the creation of an entertaining game where users can input their name and email address. Upon clicking the "Add" button, a new card will be generated containing a form with checkboxes labeled "One" and "Two". Depending on the selection of ...

Exploring the world of flexbox and experimenting with implementing flex-wrap at a specific breakpoint

I am working on a layout that includes a module containing various content. My goal is to have the progress bar, along with the labels "parts" and "projects," positioned underneath an image and expand to the full width of the module when the window size go ...

When using Javascript to append content to the body, it may not be displayed as HTML on

My current project involves creating an HTML document through JavaScript templates. In the code snippet below, I have a const button which serves as my template. By using the replace method, I am able to update the content within the button template from c ...

Problems with scrolling in Firefox when using Three.JS

Is anyone else experiencing issues with three.js? I have a simple demo of a spinning cube with varying rotational velocity using arrow keys, mouse, or touch input. Everything works perfectly in Chrome, but the textures are spliced and not mapped correctly ...

Finding the right spot to apply CSS styles in a data table can be a tricky task

I need to use angular-ngStyle to apply CSS styles on Table data. The logic is set up: "When the table width is less than 1250px, apply certain CSS styles". Here is the code for that: export class NanoTableComponent { /** * This function checks the table ...

How come the position sticky content vanishes when a z-index is applied?

Can someone assist with the issue I'm having regarding the use of sticky and z-index? Whenever I apply a z-index to a positioned sticky element, its content disappears. Question: How can I utilize z-index for a positioned sticky element without any c ...

Incorporate an external website into HTML5 code

I have a dilemma with embedding one website into another. I am currently utilizing embed code for this purpose. <object data="http://mywebsite.com" width="100%" height="100%"> <embed src="http://mywebsite.com" width="100%" height="100%"> ...

photographs showcasing the datepicker widget of jquery-ui

I have implemented the jquery ui datepicker in my project by simply copying and pasting the necessary css and js files. $("#birth_date").datepicker( { changeMonth: true, changeYear: true, yearRange: "1990:2050", dateFormat: 'yy-mm-dd' }) ...

The buttons in the Bootstrap modal are unresponsive

I'm attempting to create a modal navigation bar for mobile view but encountering an issue. When I click on the icon bar or menu bar in mobile view, none of the buttons inside the modal are responding. I'm quite stuck on this and would appreciate ...

I am having difficulty aligning text horizontally within a <div> element using a combination of <div>, <a>, and <p> tags

I can't seem to figure out why I'm struggling with this. Check out the screenshot below: Here is my current CSS: #tabbase { display : inline-block; width : 230px; height : 173px; border : 1px solid #3e3e3e; background-color : #1b ...

The reliability of jQuery posting varies

My current setup involves using jQuery to send data to an external source with the code snippet provided below. As part of the process, I'm also ensuring that all input fields are filled out correctly. However, there has been a strange issue where the ...

Despite setting the overflow-y property, the website continues to scroll

Take a look at the code snippet in this Fiddle example. Despite setting overflow-y on the DIV of the orange area, the entire website still scrolls. When the list inside the orange area is shorter, it functions correctly with only a scrollbar appearing on ...

How can I resize my image to match the dimensions of the navigation bar?

Is there a way for me to match the width of my navigation bar with that of an image? The issue I'm facing is that the original size of the image is 497 x 298px, and in order to stretch it across the full width of the page while maintaining margins of ...

Assistance required for JavaScript with Image and Hyperlinks

In the provided code snippet, I have included a javascript onclick function to the image tag. After clicking the image and then going back, the page remains on the current page rather than returning to the original page. Is there a way to prevent this beha ...