How does altering the flex direction impact the height of the child elements?

I am currently attempting to create a media query using Flexbox in order to display an input element below another one instead of side by side. However, the issue I am facing is that when I set the flex-direction to column, the width of the input is not as expected. Here is the current output:

https://i.sstatic.net/M4dep.png

On the other hand, if I change the flex-direction to column, the input width does not remain the same. This results in the following layout:

https://i.sstatic.net/xrWQo.png

Below is the HTML code snippet:

<div id="mc_embed_signup">
  <form action="//eliasgarcia.us8.list-manage.com/subscribe/post?u=55cf7078733f0b62eb97733e3&amp;id=ace40b1824" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
      <label for="mce-EMAIL">Don't miss any article</label>
      <div class="mc-wrapper">
        <input type="email" value="" name="EMAIL" id="mce-EMAIL" placeholder="Email Address" required>
        <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true">
          <input type="text" name="b_55cf7078733f0b62eb97733e3_ace40b1824" tabindex="1" value="">
        </div>
        <div>
          <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
        </div>
      </div>
      <div class="mc-error">
      </div>
    </div>
  </form>
</div>

Below is the CSS code snippet:

#mc_embed_signup {
  label {
    font-size: 2em;
    font-weight: bold;
    display: block;
    text-align: center;
  }
  .mc-wrapper {
    display: flex;
    justify-content: space-between;
    padding: 30px 0px 0px 0px;
  }
  #mce-EMAIL {
    width: 100%;
    margin: 0px 30px 0px 0px;
    border: 2px solid $medium-grey;
    border-radius: 4px;
    text-indent: 20px;
  }
  .button {
    margin: 0px auto;
    cursor: pointer;
  }
}

Can anyone help me understand why this issue is occurring?

NOTE: Unfortunately, I am unable to provide a Fiddle for demonstration purposes as this involves integration with MailChimp, which utilizes a JavaScript script. The script does not add any additional classes, only the ones mentioned above.

Answer â„–1

When a flex parent has a `flex-direction: row` (the default for `display: flex`), the flex children will have equal heights. This means that if your left `input` is a direct child of `.mc-wrapper`, its height will be the same as the item beside it. As a result, the `input`'s height will increase if the flex child on the right is taller.

However, if you switch to a `flex-direction: column`, the children are no longer adjacent in a row, and flexbox will not attempt to match the heights. Therefore, the `input` will retain its natural height in this layout.

Answer â„–2

CRUCIAL There is a CSS property known as align-items that typically has a default value of stretch. This property is responsible for adjusting the width/height of elements to match their parent containers based on the value of flex-direction.

For those who have reached this point, you may find this link helpful: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Answer â„–3

Include

flex-direction: wrap;

By doing this, the height will be preserved as is. visibility: hidden; will not impact it

Answer â„–4

To achieve the desired outcome, only modify the "align-items" property. Consider the following scenario in HTML:

<section>
    <hgroup>
        <h1>Our Products</h1>
        <h3>We build all kind of containers</h3>
        <p>Lorem Ipsum is simply dummy text of the printing..</p>
    </hgroup>
    <button class="full-color pull-right">View All Products</button>
</section>

...and the CSS styling is as follows:

section {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

The current height matches the hgroup's height. However, by adding the following to the section: align-items: baseline; the input height will align as intended. Be sure to avoid using:

align-items: inherit/unset/stretch/initial/normal

Answer â„–5

To achieve the desired layout, simply include the flex-flow: wrap-reverse property in the flex parent container. This will help align the elements as intended :)

For instance:

.container {
  display: flex;
  flex-direction: row-reverse;
  flex-flow: wrap-reverse;
}

Best wishes!

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

Creating a user-friendly navigation menu: A step-by-step guide

I need help creating a navigation menu for my website that isn't functioning properly. Here is the code I am currently using: body{ margin: 0px; padding: 0px; } nav > ul{ margin: 0px; padding: 0px; } nav > ul > li{ fl ...

The grid columns are not utilizing the entire space of the rows and are extending beyond to the next line

I'm currently designing a card layout with images and aiming for uniformity in size. The plan is to have 4 columns in each row, with one card per column. Each subsequent row will also contain 4 cards. However, there seems to be an issue where the ca ...

Is the table not displaying properly in the print preview with a messy

I have a large table with multiple rows. Due to its length, I have provided a link to the jsfiddle where you can view it: jsfiddle. The table is structured in HTML and contains many rows with various attributes. <table> <thead>text here!</t ...

Struggling to properly align a div on top of an image

view image description herei need assistance with centering the div over the background image. I attempted to use relative positioning for the container and absolute positioning for the elements, but it did not yield the desired result. The code snippet be ...

Maximizing the Potential of Bootstrap 5's Grid System

I'm struggling a bit with the Bootstrap grid system. I want to create 6 divs or containers that span the full width on smaller devices like mobiles, use 25% of the width on medium devices like tablets, and display all 6 in a single row on large deskto ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

Activate unresponsive state when clicked

Struggling to implement a mobile responsive menu, my primary issue is the navigation buttons not toggling upon clicking. Here's what I have so far in terms of HTML and JQuery: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery. ...

Unable to render JSON data using AJAX

I have a JSON file filled with various data and I'm trying to use AJAX to display it. Despite my efforts, I couldn't get it to work and after extensive research online, I decided to reach out for your assistance: $(document).ready(function ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...

Leveraging the CSS-Element-Queries Library for emulating the functionality of CSS media queries

Recently, I used a nifty CSS-Element-Queries tool to perform basic element manipulations that trigger whenever the window is resized. In simple terms, my goal was to dynamically adjust an element's attribute based on the current width of the window â ...

CSS positioning with absolute value + determine the number of elements positioned above

Is it feasible to adjust the position of an absolutely positioned element based on the height of the element above it? The objective is to align elements with the class "pgafu-post-categories" one line above an H2 heading, even when the lengths v ...

Reverse the color of H1 text within a vertical div

Is it feasible to reverse the coloring of a segment within an h1 element using a div, horizontally? Refer to the illustration shown in the image below. https://i.sstatic.net/QAKwD.jpg ...

SwipeJS is not compatible with a JQuery-Mobile web application

I am currently attempting to integrate SwipeJS (www.swipejs.com) into my JQuery-Mobile website. <script src="bin/js/swipe.js"></script> <style> /* Swipe 2 required styles */ .swipe { overflow: hidden; ...

Stretching of images in Safari and Chrome

Having trouble with image display on different browsers? Look at my code snippet below: <style> #globalpsa { width:100%; height:100%; border:3px double #fff; margin:2% auto; } #globalpsa input[type="image"] { wid ...

What steps do I need to take to design a menu?

I need assistance in organizing my menu with submenus. The code I currently have successfully retrieves all the submenus, but I would like to categorize them accordingly: For instance: Main Menu - Submenu 1, Submenu 2, Submenu 3 How can I go about categ ...

I have found that I can load a CSS file using Node Express, however, it seems to be malfunctioning. On the other hand, some

I have added app.use(express.static(path.join(__dirname, 'public'))); to my app.js file. Now I am using bootstrap.css along with my custom CSS file main.css. index.html: ┊ <meta http-equiv="Content-Type" content="text/html; charset=UTF- ...

What is the current importance of CSS3 vendor prefixes?

I've been pondering the importance of specifying vendor prefixes like 'webkit', 'moz', 'ms' or 'o' in modern CSS. It seems that Opera has switched to Webkit, meaning we may no longer need '-o-'. IE10 e ...

"Is there a way to modify the color of the button once it's been clicked, but only for the specific button that was

Looking to create a Quiz App using React and facing an issue where all buttons change color when clicked, instead of just the one that was clicked. Any solutions on how to make only the clicked button change its color in React.js? App.js import Main from ...

`asp:button displaying without any CSS applied`

asp:Button does not respond to CSS styling. CSS: .TabButton { border: none; background-size: cover; background-repeat: no-repeat; width: 100%; height: 100%; } HTML5: <asp:Button runat="server" Text="Events" CssClass ="TabButton" ...

Thundercss and @personalized media

After installing lightningcss and configuring the vite config, I defined lightningcss and customMedia as true. import browserslist from "browserslist"; import { browserslistToTargets } from "lightningcss"; return defineConfig({ ...