Skip to content Skip to sidebar Skip to footer

Input Field Wrapping Using Flexbox

I'm new to the flexbox, and I tried to create an input form like in the picture below. First, two fields are supposed to be 50% of the width of div, other two are 100% width. In th

Solution 1:

Please note that you defined .form as the flex parent, even though your elements were inside .input-flex - so I just copied the style to this element.

Regarding your question: by using a dedicated class, you can specify which elements should have 100% width.

Other than that, I changed the margin to be constant all around the elements, so the result better matches the design.

.form {
  width: 100%;
}

.input-flex {
  max-width: 600px;
  display: flex;
  flex-wrap: wrap;
  text-align: center;
  justify-content: center;
  align-items: center;
}

input,
textarea {
  border: 0;
  border-radius: 6px;
  padding: 2%;
  background-color: darkgray;
  margin: 10px;
  box-sizing: border-box;
  flex-grow: 1;
}

.full-width {
  width: 100%;
}
<divclass="form"><divclass="input-flex"><inputtype="text"name="name"placeholder="Name*" /><inputtype="email"name="email"placeholder="E-mail*" /><inputtype="tel"class="full-width"name="number"placeholder="Phone number*" /><textareacols="55"rows="15"class="full-width"placeholder="Questions"></textarea></div></div>

Post a Comment for "Input Field Wrapping Using Flexbox"