Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS input field does not respect flexbox layout

Hello there!

I need help! Why is the input growing so much that it overflows the flex container?
However, if you comment the input and remove the comment on the '.div-grow' element, this one respects the flexbox layout.

In fact, if the 'flex-grow:1' is removed form the input, it still grows so much.

Code:
<html>
    <head>
        <style>
            .flex-container {
                width: 400px;
                height: 200px;
                border: 1px solid black;
                display: flex;
                align-items: start;
            }
            
            .input-grow, .div-grow {
                flex-grow: 1;
                border: 1px solid red;
                font-size: 29px;
            }
            
            .div-no-grow {
                border: 1px solid blue;
            }
            
        </style>
    </head>
    <body>
        <div class="flex-container">
            <input class="input-grow" type="text" placeholder="Type text..." />
            <!--<div class="div-grow">I grow</div>-->
            <div class="div-no-grow">I do not grow</div>
        </div>
    </body>
</html>

Thank you!!
 
Give a width to your input.
Hello BGB...
I am kind of shocked...

If I set a width to the '.input-grow' element now it works...

Code:
<html>
    <head>
        <style>
            .flex-container {
                width: 400px;
                height: 200px;
                border: 1px solid black;
                display: flex;
                align-items: start;
            }
            
            .input-grow, .div-grow {
                flex-grow: 1;
                border: 1px solid red;
                font-size: 29px;
                width: 1px; /*why is this working????*/
            }
            
            .div-no-grow {
                border: 1px solid blue;
            }
            
        </style>
    </head>
    <body>
        <div class="flex-container">
            <input class="input-grow" type="text" placeholder="Type text..." />
            <!--<div class="div-grow">I grow</div>-->
            <div class="div-no-grow">I do not grow</div>
        </div>
    </body>
</html>

It works even setting a width of 1px!! Why??

Anyway, thanks a lot!!!!
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom