Flexbox properties are being ignored by input fields

Hey there, I'm currently working on a product calculator and need to create 9 input fields organized in 3 rows of three columns. However, when I try to use display: flex and flex-direction: row on the parent div, it doesn't seem to be working as expected. All the input fields end up in a single column and input sizing is not applying properly.

Any ideas on what might be causing this issue?

Thank you!

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.survery-questions {
    display: flex;
    flex-direction: row;
}

.home-price-footer {
    width: 25%;
    height: 45px;
    margin-bottom: 3em;
}


#input {
    background: #ffffff;
    border: 1px solid #eaeaea;
}
<html>
<head>
</head>
<body>
<div class="survery-questions">
        <form action="">
            <div class="price-form">
                <input name="price-1" type="text" placeholder="price 1" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-2" type="text" placeholder="price 2" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-3" placeholder="price 3" class="home-price-footer" id="input" required>
            </div>
            
                   <div class="price-form">
                <input name="price-4" type="text" placeholder="price 4" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-5" type="text" placeholder="price 5" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-6" placeholder="price 6" class="home-price-footer" id="input" required>
            </div>
                   <div class="price-form">
                <input name="price-7" type="text" placeholder="price 7" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-8" type="text" placeholder="price 8" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-9" placeholder="price 9" class="home-price-footer" id="input" required>
            </div>
        
                </form>
       </div>
       
        </form>
       </div>
       
      </body>
      </html>

Answer №1

In order to keep your HTML structure intact, I made a slight adjustment where you had used display:flex. The display:flex property only applies to immediate children and not sub-children, so since the immediate child of .survey-questions was a <form>, and <div> elements were children of the <form>, I added "form" to your existing selector and included the additional attribute flex-wrap:wrap to maintain the desired row and column layout.

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
/* Minor modification here */
.survery-questions form {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
}
form > div{
    width: 33.3%;
}

.home-price-footer {
    width: 25%;
    height: 45px;
    margin-bottom: 3em;
}


#input {
    background: #ffffff;
    border: 1px solid #eaeaea;
}
<html>
<head>
</head>
<body>
<div class="survery-questions">
        <form action="">
            <div class="price-form">
                <input name="price-1" type="text" placeholder="price 1" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-2" type="text" placeholder="price 2" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-3" placeholder="price 3" class="home-price-footer" id="input" required>
            </div>
            
                   <div class="price-form">
                <input name="price-4" type="text" placeholder="price 4" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-5" type="text" placeholder="price 5" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-6" placeholder="price 6" class="home-price-footer" id="input" required>
            </div>
                   <div class="price-form">
                <input name="price-7" type="text" placeholder="price 7" class="home-price-footer" id="input" required>

            </div>
        
            <div class="phone-form">
                <input name="price-8" type="text" placeholder="price 8" class="home-price-footer" id="input" required>
            </div>
        
            <div class="email-form">
                <input type="price-9" placeholder="price 9" class="home-price-footer" id="input" required>
            </div>
        
                </form>
       </div>
       
        </body>
        </html>

Answer №2

When the <form> element is the only child of your flex container, it becomes the only element affected by the flex properties. To achieve the desired behavior, consider moving the form outside the flex container.

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.survey-questions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap; /* added */
}

.survey-questions > div {
    width: 33.33%; /* added */
    padding: 0 10px; /* added */
}

.home-price-footer {
    width: 100%; /* updated */

    height: 45px;
    margin-bottom: 3em;
}

#input {
    background: #ffffff;
    border: 1px solid #eaeaea;
}
<form action="">
    <div class="survey-questions">
        <div class="price-form">
            <input name="price-1" type="text" placeholder="price 1" class="home-price-footer" id="input" required>
        </div>

        <div class="phone-form">
            <input name="price-2" type="text" placeholder="price 2" class="home-price-footer" id="input" required>
        </div>

        <div class="email-form">
            <input type="price-3" placeholder="price 3" class="home-price-footer" id="input" required>
        </div>

        <div class="price-form">
            <input name="price-4" type="text" placeholder="price 4" class="home-price-footer" id="input" required>
        </div>

        <div class="phone-form">
            <input name="price-5" type="text" placeholder="price 5" class="home-price-footer" id="input" required>
        </div>

        <div class="email-form">
            <input type="price-6" placeholder="price 6" class="home-price-footer" id="input" required>
        </div>

        <div class="price-form">
            <input name="price-7" type="text" placeholder="price 7" class="home-price-footer" id="input" required>
        </div>

        <div class="phone-form">
            <input name="price-8" type="text" placeholder="price 8" class="home-price-footer" id="input" required>
        </div>

        <div class="email-form">
            <input type="price-9" placeholder="price 9" class="home-price-footer" id="input" required>
        </div>
    </div>
</form>

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

The filter search feature fails to return any results when data is inputted into the tables

I have implemented a filter search feature within two tables on my website. My goal is to retrieve the search results for a specific drink while keeping the table headings fixed in their positions. For instance, if I type "Corona" into the search box, I ...

Continuous Playback of Sound

Is there a way to autoplay an audio in loop without being blocked by browsers? Code : <audio id="audio1" src="assest/sound/1.mp3" autoplay="" /> <script> a = document.getElementById('audio1&apo ...

The lines intersecting with the ethereal image in the background

I'm trying to achieve button links with an image overlay, but so far I've only been able to do it using CSS: section a:link, section a:visited { width: 150px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: ...

Every time I use formsubmit.co on my Github pages, I encounter a 404 error

Currently, I'm in the process of constructing a website with Bootstrap 5 and have integrated a form that is intended to be completed and forwarded to my email address. I've chosen to utilize formsubmit.co for this purpose. However, when I attempt ...

Using HTML nested lists in Wordpress sites

Working on nested, ordered lists using ol types and encountering an issue where the code appears correctly in Wordpress preview but displays incorrectly in Firefox and IE. The lists are showing as numbered instead of the specified types in the code provide ...

I tried moving the onchange(this) function from HTML to JavaScript, but I seem to have missed a parameter. The code ends

I'm currently building a website for a fictional ice cream shop to enhance my JavaScript skills. function hideAAndB() { var pickupDiv = document.getElementById("pickupDiv"); var deliveryDiv = document.getElementById("deliveryDiv"); pickupDi ...

Tips on modifying the content of an element located within two iframes using the Chrome console

I'm trying to modify an element that is nested within two iframes. The issue I'm facing is that the Chrome console seems unable to locate the element. Is there a specific method to identify and target elements within nested iframes? document.quer ...

I'm having trouble getting my modal to work and display properly; I need to send it to the code behind for further assistance

I'm having trouble with my modal. I'm trying to create a sign-up modal and send it to my code behind page. I've incorporated bootstrap lumen and jquery, but I could use some assistance. Any help would be greatly appreciated. Thank you in adv ...

Using jQuery to access the value of the CSS property "margin-left"

I created a JavaScript game with moving divs that have different transition times. The game includes a function that is called every 1/100 seconds, which checks the position of the divs using: $("class1").css("margin-left") Here's the strange part: ...

CSS: element misplaced at the top instead of the bottom where it belongs

The component with the ID of "#bottom-nav" actually appears at the top. I just designed this on CSS-board, so feel free to review the HTML and CSS code Take a look at it on CSS-desk here It is positioned at the very end of the page and includes a ' ...

Struggling to integrate buttons into an h2 element with the use of createElement() and appendChild() in HTML/CSS/JS

As I work on developing a website, one of the features I've been implementing is the ability for users to add books to a list and then review or delete them. The process was smooth sailing until I reached the point of adding buttons for these actions. ...

Guide on triggering CSS @keyframes animations upon element visibility while scrolling

I'm struggling with controlling CSS animations that I want to start only when the element becomes visible on the screen. The issue arises because I have a website with a total height of around 8000px and the element with the animation is located far d ...

Make sure your website design is responsive by setting the body to the device's

I'm struggling to make the body of my page responsive for mobile users. Whenever I try using this line of code, it just creates a messy layout. Any advice on how to fix this? <meta name="viewport" content="width=device-width" ...

Is it possible to achieve a height transition using CSS instead of relying on JavaScript

I created these custom cards using a combination of HTML, CSS, and JavaScript. However, I've noticed that the height transition animation is not as smooth as I'd like it to be, especially on certain pages. Is there a way to achieve this animation ...

The CSS layout is not positioning elements correctly

Here is a preview of how I want my final design to appear: I am facing difficulty in properly aligning the two columns using my CSS code. Whenever I apply the float: left; property, the columns end up stacking on top of each other. /*------ Code st ...

Error in compiling: Incompatibility between oncommand and CommandArgument attributes within LinkButton

I'm facing an issue with a LinkButton in a repeater on my aspx page. I am trying to call a function oncommand and pass a parameter via CommandArgument, but it keeps giving me a compilation error. Can someone help me figure out what I am missing here a ...

Surprising Results when Using getBoundingClientRect()

Check out this code on CodePen In my current project, I'm attempting to position the footer div at the bottom of the page in such a way that it aligns with the maximum value of the bottom coordinates of both the menu and content divs (Math.max(menu, ...

Adjust the select box size to be in line with the text box dimensions

I'm struggling to understand why there are two boxes visible in my navigation bar. For example, when looking at the Home link, I notice that there are actually two boxes; one containing the text "Home" and another one that extends outwards to the rig ...

Having trouble with button alignment in the header with Bootstrap 3?

Using Bootstrap 3 and looking to adjust the alignment of a star icon with the title in my HTML page. Here is the current setup: <p class="pull-right visible-xs"> <h3><center>2000 Cadillac Eldorado Esc (Prospect heights) $3500 ...

Issues with Disabling the Browser's Back Button with jquery

I have been attempting to prevent the back button from functioning in a specific Browser, Microsoft Bing. Interestingly, my code works only if I click somewhere in the window first. If I don't click anywhere and try to go back directly, it still allow ...