The inline-block element has overflowed the body section

I'm struggling with a similar issue to the one discussed in this post, where I can't seem to get my input text to display as inline-block properly --> inline-block overflowing outside container

My goal is to have 5 input texts displayed like so:

"Item 1"

"Item 2" "Item 3"

"Item 4" "Item 5"

This is what my HTML looks like:

<div class="form">
    <div id="inputs">
        <label> Email </label>
        <div>
            <input type="text" [(ngModel)]="email" maxlength="100">
        </div>
        <label> Address </label>
        <div>
            <input type="text" [(ngModel)]="address" maxlength="50">
        </div>
             .....
    </div>
</div>

And here's what my CSS looks like:

#inputs { 
    display: inline-block; 
    vertical-align: top;
    label {
      ....
    }

    div {
     width: 100%;
       ....
    }
}

I've experimented with display: table, position: absolute, and display: inline-flex but haven't found a solution that meets my requirements.

Answer №1

If you want to achieve this layout, follow these steps:

#inputs .frmField{ 
  float: left;
  vertical-align: top;
}
#inputs .frmField:nth-child(2), #inputs .frmField:nth-child(4){
  clear: both
}
label {
  display: block;
}
div {
  /*width: 100%;*/
}
<div class="form">
    <div id="inputs">
        <div class="frmField">
        <label> Email 1</label>
            <input type="text" [(ngModel)]="email" maxlength="100">
        </div>
        <div class="frmField">
        <label> Address 2</label>
            <input type="text" [(ngModel)]="address" maxlength="50">
        </div>
        <div class="frmField">
        <label> Address 3</label>
            <input type="text" [(ngModel)]="address" maxlength="50">
        </div>
        <div class="frmField">
        <label> Address 4</label>
            <input type="text" [(ngModel)]="address" maxlength="50">
        </div>
        <div class="frmField">
        <label> Address 5</label>
            <input type="text" [(ngModel)]="address" maxlength="50">
        </div>
    </div>
</div>

Answer №2

I find that utilizing tables for form creation works best for me

SNIPPET

<h1>A FORM</h1>
<table class="form">
    <tbody id="inputs">
        <tr>
            <td><label> Email </label><td>
            <td><input type="text" [(ngModel)]="email" maxlength="100"></td>
        </tr>
        <tr>
            <td><label> Address </label><td>
            <td><input type="text" [(ngModel)]="email" maxlength="100"></td>
        </tr>
        <tr>
            <td><label> Address </label><td>
            <td><input type="text" [(ngModel)]="email" maxlength="100"></td>
        </tr>
        <tr>
            <td><label> Address </label><td>
            <td><input type="text" [(ngModel)]="email" maxlength="100"></td>
        </tr>
        <tr>
            <td><label> Address </label><td>
            <td><input type="text" [(ngModel)]="email" maxlength="100"></td>
        </tr>
    </tbody>
</table>

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

Avoid using <input oninput="this.value = this.value.toUpperCase()" /> as it should not convert the text displayed on the "UI", rather it should send the uppercase value

<input oninput="this.value = this.value.toUpperCase()" type="text" id="roleName" name="roleName" class="form-control width200px" [(ngModel)]="role.roleName"> Even though the UI is changing ...

Submit file in Cypress while hiding input[type="file"] from DOM

Currently, I am conducting end-to-end testing on an Angular project that utilizes Ant Design (NG-ZORRO). In this project, there is a button with the class nz-button that, when clicked, opens the file explorer just like an input type="file" element would. W ...

Classic design of the shadow element

I have main.js and index.html below class CustomTagA extends HTMLElement { constructor() { super(); const shadow = this.attachShadow({mode: 'open'}); const wrapper = document.createElement('h1'); ...

The JQuery script is not producing any results

After integrating a script into my website template, it is not functioning as expected. I suspect there may be a conflict with JavaScript, but upon inspecting with firebug, I am unable to identify any abnormalities. Here is the link for reference: Link ...

Tips for customizing a jQuery themeHere are some strategies for

I have been working with the Smoothness theme and Jquery tabs, and I am looking to customize the appearance of a few specific tabs. I have attempted the following approach: $('#tab-id').css('background', '-moz-linear-gradient(cent ...

A search form utilizing prepared statements in mysqli

Well met again, everyone. I recently reached out for help on improving some messy code I had put together, and the response was swift. Thank you for that! You can find the original question thread here: PHP - Search database and return results on the sam ...

Tips for implementing multiple buttons with ngfor

My question is as follows: I have a set of three buttons that are displayed in either yellow, red or green next to each other. I want to display them 20 times in random color order. However, my current code only displays the buttons in the order of my st ...

Pause the counter based on the data attribute containing multiple values

I have a collection of div elements, each with a unique data-attribute value. My goal is to display these values in the divs using JavaScript by incrementing a counter. const numbers = document.querySelectorAll(".number"); console.log(numbers); let c ...

Adjust the width of individual columns in Bootstrap 4 responsive tables to ensure they have specific widths

I am currently working on setting up a table where specific columns require a fixed width and do not adjust automatically. Despite attempting a method to achieve this, I have encountered issues as the width still adjusts based on the length of the text. ...

The JavaScript-rendered HTML button is unresponsive

I have a JavaScript function that controls the display of a popup window based on its visibility. The function used to work perfectly, with the close button effectively hiding the window when clicked. However, after making some changes to the code, the clo ...

Create a rounded border around the inner corner of the active menu

I have been struggling to create a curved border for an active/selected menu. Despite trying various solutions from Google, I can't seem to eliminate the square corners. Any help or suggestions would be greatly appreciated! Thank you in advance! Chec ...

What is the best way to adjust the height of my website to properly display on all screen sizes

Is there a way to make my web page fit perfectly on the screen in terms of both width and height? I'm familiar with using Media Queries for adjusting widths, but how can I also control the height? Any suggestions on setting the height? I would great ...

Dividing an unordered list into two parts using HTML and CSS

Hey there, I've been struggling with this issue for two weeks now and I finally decided to ask for help. My goal is to create a new line in an unordered list inside a div. Here's what I want: Home Contact Us Education FAQ Stores Services Howev ...

Using a combination of CSS, Ajax, and jQuery, dynamically insert new rows into a table generated within a div

Apologies for the awkward question. I am currently working on a solution to create a table using div tags, which is functioning properly. However, I am facing an issue with adding or removing a row using jQuery. The problem lies in the fact that when a new ...

Video on Youtube keeps playing even after the overlay is closed

I successfully created an overlay with an embedded YouTube video that automatically opens when the page loads. Everything was going smoothly until I encountered a problem - when I close the overlay while the video is playing, the audio continues to play in ...

Tips for naming multiple select options for form submission---Different ways to name

Struggling with multiple selects in a form? Find out how to name them correctly here. Take a look at this example: <form action="/product/create" method="post"> <table> <tr> <td> <input type="text" na ...

Keep Variable-Height Element Corners Rounded to Perfection

I am facing a challenge with creating buttons that have perfectly rounded corners. The button is 50px high and the border radius is set to 25px, resulting in a perfect half-circle on each side of the button: It's pretty straightforward to achieve thi ...

Add rows to the table dynamically and then execute the script

My table dynamically creates rows when a button is clicked, and there is an input box with an auto suggest script. The auto complete works fine on the default first box, but not on the dynamically added row. How can I make the auto complete script work o ...

Is there a way for me to manage the appearance of the printed document's layout?

I have successfully added 3 print buttons to my website, each one designed to print a specific portion (div) of the webpage. Here is the code snippet for this functionality: function printPage(id) { var html="<html>"; //html+="<link rel="st ...

Place the Share and Like buttons on a single line

I need help aligning my Facebook share button with the FB like button on my WordPress post. Despite adding both buttons on the same line, the Like button keeps appearing below the share button. I've checked in Firefox's inspector and confirmed t ...