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 the mobile view, they are supposed to stack on each other.
Can I use "width" and "height" attributes on textarea?
.form{
display: flex;
flex-wrap: wrap;
text-align: center;
justify-content: center;
align-items: center;
width: 100%;
}
.input-flex{
max-width: 600px;
}
input, textarea{
border: 0;
border-radius: 6px;
padding: 2%;
background-color: darkgray;
margin-right: 5%;
margin-bottom: 5%;
flex:1 0 100%;
}
<div class="form">
<div class="input-flex">
<input type="text" name="name" placeholder="Name*"/>
<input type="email" name="email" placeholder="E-mail*"/>
<input type="tel" name="number" placeholder="Phone number*"/>
<textarea cols="55" rows="15" placeholder="Questions"></textarea>
</div>
</div>
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%;
}
<div class="form">
<div class="input-flex">
<input type="text" name="name" placeholder="Name*" />
<input type="email" name="email" placeholder="E-mail*" />
<input type="tel" class="full-width" name="number" placeholder="Phone number*" />
<textarea cols="55" rows="15" class="full-width" placeholder="Questions"></textarea>
</div>
</div>
Related
In my project, I want to design a shipping address design with HTML and css(flexbox). And i want to design "city","zip code","state", box in one line like this
but in my code, I am unable to do like that design so help me to what changes should I have done to get that result?
And my code results shows is like this
So I want "city","zip code","state" box takes same size fit to the "ad
Here is my code
.shipping-containers {
height: 100vh;
width: 100%;
border: 2px solid black;
display: flex;
flex-direction: column;
flex-wrap: wrap;
background: red;
justify-content: center;
align-items: center;
}
.shipping-wrapper {
display: flex;
flex-direction: column;
width: 70%;
background: lightskyblue;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.shipping-wrapper>form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid black;
}
.shipping-div {
display: flex;
flex-direction: row;
margin-right: 15rem;
justify-content: center;
align-items: center;
}
.shipping-div input {
text-align: center;
justify-content: center;
align-items: center;
}
.shipping-wrapper input {
width: 50%;
font-size: 10px;
padding: 15px;
background: #f1f1f1;
margin-bottom: 10px;
}
<div class="shipping-containers">
<div class="shipping-wrapper">
<form>
<input type="text" placeholder=" name" />
<input type="text" placeholder=" address" />
<div class="shipping-div">
<div>
<input type="text" placeholder=" city" class="shipping-input" />
</div>
<div>
<input type="text" placeholder=" zip code " class="shipping-input" />
</div>
<div>
<input type="text" placeholder=" state" class="shipping-input" />
</div>
</div>
<input type="text" placeholder=" Country" class="shipping-input" />
<button>Continue</button>
</form>
</div>
</div>
You have many borders included which are a mess to take into account. The easiest and cleanest solution is to use * { box-sizing: border-box; }. With that property, we don't have to take all the different borders into account.
You nested way too many Flexbox and used unnecessary div's. As such I removed all div's out of your form.
I used flex-wrap: wrap on your form. Then I raised the width from all the inputs to 100% and created the space left and right with padding on the form.
I changed justify-content: center to justify-content: space-between for your form.
I changed the flex-direction: column on the form to default row as otherwise, the flex-wrap will not work.
The width for the 3 small inputs must be calculated (that's why CSS-Grid would have been a better and easier solution). YOu have to take the 2x gaps a 10px each into account. So the width for the 3 elements in total is 100% - 20px. That again must then be divided by 3:
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.shipping-containers {
height: 100vh;
border: 2px solid black;
display: flex;
flex-direction: column;
flex-wrap: wrap;
background: red;
justify-content: center;
align-items: center;
}
.shipping-wrapper {
display: flex;
flex-direction: column;
width: 70%;
background: lightskyblue;
justify-content: center;
align-items: center;
}
.shipping-wrapper > form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
border: 1px solid black;
padding: 0 15%;
}
.shipping-wrapper input {
width: 100%;
font-size: 10px;
padding: 15px;
background: #f1f1f1;
margin-bottom: 10px;
}
.shipping-wrapper input:nth-child(3),
.shipping-wrapper input:nth-child(4),
.shipping-wrapper input:nth-child(5) {
width: calc((100% - 20px) / 3);
}
.shipping-wrapper button {
margin: 0 auto;
}
<div class="shipping-containers">
<div class="shipping-wrapper">
<form>
<input type="text" placeholder="name">
<input type="text" placeholder="address">
<input type="text" placeholder="city">
<input type="text" placeholder="zip code">
<input type="text" placeholder="state">
<input type="text" placeholder="Country">
<button>Continue</button>
</form>
</div>
</div>
Here's my take. Points to note: box-sizing: border-box is a must for the inputs.
.shipping-div has negative margin so children with margin would align to width (this is bootstrap trick). And the rest is trivial.
.shipping-containers {
height: 100vh;
border: 2px solid black;
display: flex;
background: #ff00007f;
justify-content: center;
align-items: center;
}
.shipping-wrapper {
width: 70%;
background: lightskyblue;
}
.shipping-wrapper>form {
border: 1px solid black;
}
.shipping-div {
display: flex;
justify-content: space-between;
margin-left: -5px;
margin-right: -5px;
}
.shipping-div>div {
margin-left: 5px;
margin-right: 5px;
width: 100%;
}
.shipping-wrapper input {
width: 100%;
min-width: 100%;
font-size: 10px;
padding: 15px;
background: #f1f1f1;
margin-bottom: 10px;
position: relative;
display: block;
box-sizing: border-box;
}
<div class="shipping-containers">
<div class="shipping-wrapper">
<form>
<input type="text" placeholder=" name" />
<input type="text" placeholder=" address" />
<div class="shipping-div">
<div>
<input type="text" placeholder=" city" class="shipping-input" />
</div>
<div>
<input type="text" placeholder=" zip code " class="shipping-input" />
</div>
<div>
<input type="text" placeholder=" state" class="shipping-input" />
</div>
</div>
<input type="text" placeholder=" Country" class="shipping-input" />
<button>Continue</button>
</form>
</div>
</div>
I've created a Fiddle here: http://jsfiddle.net/gonw4udf/1/
I have a form that we want to be of a minimum height. Sometimes, the form only has very few fields which means that the "Submit" button immediately follows the last field. However, we want the "Submit" button to always be positioned at the bottom of its container.
I'm wondering if there is a way to do so without having to rely on position: absolute.
To clarify: If the form is taller than the minimum height, it's okay to put the "Submit" button immediately after its last field. However, for forms that are shorter than the minimum height, we always want the "Submit" button at the bottom of the form. There may be multiple valid heights for these form so a solution that doesn't rely on hard coding a pixel value would be best.
.form-wrapper {
max-width: 300px;
width: 300px;
background-color: #D2B4DE;
padding: 20px 30px;
min-height: 300px;
}
.form {
display: flex;
flex-direction: column;
flex-wrap: wrap;
margin: 0 auto;
}
.form-title {
font-weight: bold;
font-size: 28px;
margin-bottom: 8px;
}
.button {
margin-top: 10px;
justify-content: flex-end;
align-items: baseline;
}
<div class="form-wrapper">
<form class="form">
<div class="form-title">
This is a form title.
</div>
<label for="field">Field</label>
<input type="text" id="field" placeholder="Enter a field" />
<button class="button">Submit</button>
</form>
</div>
Your form does not fill its container, you can use either min-height: 100% or set the container as a flex box too (easier way, no need to mind about margins then).
Once this done, the button should go down to the bottom of the form with an auto margin.
Possible example:
.form-wrapper {
max-width: 300px;
width: 300px;
background-color: #D2B4DE;
padding: 20px 30px;
min-height: 300px;
display:flex;/* NEW*/
}
.form {
display: flex;
flex-direction: column;
gap:10px;/*NEW*/
flex-wrap: wrap;
margin: 0 auto;
}
.form-title {
font-weight: bold;
font-size: 28px;
margin-bottom: 8px;
}
.button {
margin-top:auto;/* MODIFIED*/
align-items: baseline;
}
<div class="form-wrapper">
<form class="form">
<div class="form-title">
This is a form title.
</div>
<label for="field">Field</label>
<input type="text" id="field" placeholder="Enter a field" />
<button class="button">Submit</button>
</form>
</div>
Here is the solution with justify-content: space-between. To make this work I've added 1 div wrapping the form content and another div wrapping the button.
.form-wrapper {
max-width: 300px;
width: 300px;
background-color: #D2B4DE;
padding: 20px 30px;
min-height: 300px;
display: flex;
}
.form {
display: flex;
flex-direction: column;
flex-wrap: wrap;
margin: 0 auto;
flex: 1;
justify-content: space-between;
}
.form-content {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.form-action {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.form-title {
font-weight: bold;
font-size: 28px;
margin-bottom: 8px;
}
.button {
margin-top: 10px;
justify-content: flex-end;
align-items: baseline;
}
<div class="form-wrapper">
<form class="form">
<div class="form-content">
<div class="form-title">
This is a form title.
</div>
<label for="field">Field</label>
<input type="text" id="field" placeholder="Enter a field" />
</div>
<div class="form-action">
<button class="button">Submit</button>
</div>
</form>
</div>
I have solved your issue and that is, you need to specify some height to the .form-wrapper and then give height: 100%; to form and then give margin-top: auto to the .button. AND YOU ARE DONE... This is happening because your form is not filling the content-space of the .form-wrapper. Moreover, margin-top: auto; takes the available space of the wrapper. There is another way using position: absolute; but that is very error prone, I don't suggest you doing that. However, If you want I can tell you that too. The solution by Nik is also a good way to deal with this situation
.form-wrapper {
max-width: 300px;
width: 300px;
background-color: #D2B4DE;
padding: 20px 30px;
min-height: 300px;
height: 10vh;
margin:0 auto;
}
.form {
display: flex;
flex-direction: column;
flex-wrap: wrap;
margin: 0 auto;
height: 100%;
}
.form-title {
font-weight: bold;
font-size: 28px;
margin-bottom: 8px;
}
.button {
margin-top: auto;
justify-content: flex-end;
align-items: baseline;
}
<div class="form-wrapper">
<form class="form">
<div class="form-title">
This is a form title.
</div>
<label for="field">Field</label>
<input type="text" id="field" placeholder="Enter a field" />
<button class="button">Submit</button>
</form>
</div>
I am having some issues with formatting of my form - I am only new to web coding so I apologise for what may seem very simple - this is my first form I'm coding.
Essentially what I am trying to do is:
On a screen and tablet: form labels to be right and justified, against form elements
On a phone: form labels to be left aligned and justified above the left aligned and justified elements
Submit button to be right aligned and justified
All of this is being done utilising flexboxes
Here is what I've got so far:
/* Contact Page Styling */
.contact_left {
flex-direction: row;
flex: 1;
align-content: center;
text-align: center;
}
.contact_right {
display: flex;
flex-direction: row;
flex: 1;
justify-content: space-between;
}
.contact_form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
padding: 0;
max-width: 90%;
margin: auto;
}
.contact_form div {
flex: 25%;
}
.contact_form div {
flex: 50%;
}
.form_label {
text-align: right;
}
#media screen and (max-width: 1024px) {
section {
width: 80%;
}
}
#media screen and (max-width: 800px) {
section {
flex-direction: column;
text-align: center;
width: 100%;
margin: 2px;
}
.contact_form {
flex-direction: column;
justify-content: flex-start;
align-content: flex-start;
}
.contact_form div { /* Change div elements to 100% */
flex: 100%;
justify-content: flex-start;
align-content: flex-start;
}
.form_label { /* Align the text left */
text-align: left;
}
.contact_input {
flex-direction: column;
justify-content: flex-start;
align-content: flex-start;
flex: 100%;
}
}
<section>
<div class="contact_right">
<form class="contact_form" id="contact_form">
<div class="form_label">
<label for="contact_name">Full Name:</label>
</div>
<div>
<input class="contact_input" type="text" id="contact_name" name="contact_name" placeholder="Name">
</div>
<div class="form_label">
<label for="contact_email">Email Address:</label>
</div>
<div>
<input type="email" id="contact_email" name="contact_email" placeholder="Email">
</div>
<div class="form_label">
<label for="contact_number">Mobile Number:</label>
</div>
<div>
<input type="tel" id="contact_number" name="contact_number" placeholder="Mobile Number">
</div>
<div class="form_label">
<label for="contact_message">Message:</label>
</div>
<div>
<textarea rows="4" cols="40" id="contact_message" name="contact_message" value=""></textarea>
</div>
<button type="submit">Submit</button>
</form>
</div>
</section>
I noticed in the snippet above the formatting isn't as bad as what it looks like on the web-page: Image of formatting with full website coding
For those that have some spare time and would like to provide some feedback I have uploaded it all here: https://webchopper.000webhostapp.com/contact.html
These are the wireframes of how the website is deemed to look
Thanks so much for your help - any feedback is good feedback :-)
Thanks to some help above:
p {
text-align: center;
padding: 0 0 0 0;
margin: 5px auto;
}
form#contact_form {
display: flex;
flex-direction: column;
text-align: left;
padding: 0;
margin: auto;
}
form#contact_form p {
display: flex;
flex-direction: row;
flex-wrap: wrap;
text-align: left;
justify-content: space-around;
padding: 0;
}
form#contact_form p > label {
display: flex;
padding-right: 2px;
text-align: left;
}
form#contact_form p > input,
form#contact_form p > textarea {
font-family: monospace;
font-size: 1em;
}
button {
display: inline-block;
justify-content: center;
align-content: center;
width: 25%;
margin: 0 auto;
margin-bottom: 5px;
}
<div class="contact_right">
<form id="contact_form">
<p>
<label for="contact_name">Full Name:</label>
<input type="text" id="contact_name" name="contact_name" placeholder="Name">
</p>
<p>
<label for="contact_email">Email Address:</label>
<input type="email" id="contact_email" name="contact_email" placeholder="Email">
</p>
<p>
<label for="contact_number">Mobile Number:</label>
<input type="tel" id="contact_number" name="contact_number" placeholder="Mobile Number">
</p>
<p>
<label for="contact_message">Message:</label>
<textarea rows="4" cols="40" id="contact_message" name="contact_message" placeholder="Message"></textarea>
</p>
<button type="submit">Submit</button>
</form>
</div>
Now I'm just working on the positioning and formatting. As you can see the input boxes are a little off - and I want to align labels to the left.
Thanks for your help!
This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
How can I horizontally center an element?
(133 answers)
Closed 1 year ago.
I am currently doing an assignemnt for my diploma of website development.. I am struggling to get a form to be centred within a flexbox.
<div id="article_right">
<h2>Contact Us!</h2>
<form id="contact_form">
<div class="input-box">
<label for="contact_name">Full name:</label>
<input type="text" id="contact_name" name="contact_name" placeholder="Name">
</div>
<div class="input-box">
<label for="contact_phone">Mobile number:</label>
<input type="tel" id="contact_phone" name="contact_phone" placeholder="Mobile number">
</div>
<div class="input-box">
<label for="contact_email">Email address:</label>
<input type="email" id="contact_email" name="contact_email" placeholder="E-mail address">
</div>
<div class="input-box">
<label for="contact_message">Message:</label>
<textarea rows="4" cols="40" id="contact_message" name="contact+message" style="resize: none"></textarea>
</div>
<div class="button">
<button type="submit">Submit</button>
</div>
</form>
</div>
</article>
/* Article Styling Definitions */
article {
display: flex;
flex: 3;
background-color: transparent;
}
#article_left {
flex: 1;
align-content: center;
margin-right: auto;
background-color: aqua;
}
#article_right {
flex: 1;
align-content: center;
justify-content: center;
padding-bottom: 5px;
background-color: transparent;
margin-left: auto;
}
.cta {
flex: 30;
border: 1px solid black;
border-radius: 5px;
margin: 25px;
padding-left: 5px;
}
form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
margin: 0 auto;
}
.input-box {
padding-right: 5px;
display: flex;
width: 100%;
margin-bottom: 10px;
}
label {
width: 45%;
padding-right: 5px;
text-align: right;
}
input, textarea {
width: 150%;
}
I have tried everything and I just can't seem to get it to fill the right flexbox and for the form elements to be centered. The button and h2 are but the form itself won't
The problem is that you are setting article to display flex but you are setting what is to happen with the flex to its child div.
I am not absolutely sure which you want (perhaps both) but this snippet adds display flex just to the child div to at least demonstrate that something changes:
<style>
body {
height: 100vh;
display: inline-block;
width: 100vh;
}
/* Article Styling Definitions */
article {
height: 100%;
position: relative;
display: flex;
flex: 3;
background-color: transparent;
}
#article_left {
flex: 1;
align-content: center;
margin-right: auto;
background-color: aqua;
}
#article_right {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 5px;
background-color: transparent;
margin-left: auto;
}
.cta {
flex: 30;
border: 1px solid black;
border-radius: 5px;
margin: 25px;
padding-left: 5px;
}
form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
margin: 0 auto;
}
.input-box {
padding-right: 5px;
display: flex;
width: 100%;
margin-bottom: 10px;
}
label {
width: 45%;
padding-right: 5px;
text-align: right;
}
input,
textarea {
width: 150%;
}
</style>
<body>
<article>
<div id="article_right">
<h2>Contact Us!</h2>
<form id="contact_form">
<div class="input-box">
<label for="contact_name">Full name:</label>
<input type="text" id="contact_name" name="contact_name" placeholder="Name">
</div>
<div class="input-box">
<label for="contact_phone">Mobile number:</label>
<input type="tel" id="contact_phone" name="contact_phone" placeholder="Mobile number">
</div>
<div class="input-box">
<label for="contact_email">Email address:</label>
<input type="email" id="contact_email" name="contact_email" placeholder="E-mail address">
</div>
<div class="input-box">
<label for="contact_message">Message:</label>
<textarea rows="4" cols="40" id="contact_message" name="contact+message" style="resize: none"></textarea>
</div>
<div class="button">
<button type="submit">Submit</button>
</div>
</form>
</div>
</article>
</body>
You probably want to set flex-direction to get the contact us centered above the form.
It's true, just set width to <form> for example max-width:600px
What You are doing is ok.
Just try to add some width to the form, example:
https://jsfiddle.net/nk9owjyz/3/
form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin: 0 auto;
width: 50%;
}
Just update your article css
article {
display: flex;
justify-content: center;
align-items: center;
width: 80vw;
background-color: transparent;
}
Try Full Code
/* Article Styling Definitions */
article {
display: flex;
justify-content: center;
align-items: center;
width: 80vw;
background-color: transparent;
}
#article_left {
flex: 1;
align-content: center;
margin-right: auto;
background-color: aqua;
}
#article_right {
flex: 1;
align-content: center;
justify-content: center;
padding-bottom: 5px;
background-color: transparent;
margin-left: auto;
}
.cta {
flex: 30;
border: 1px solid black;
border-radius: 5px;
margin: 25px;
padding-left: 5px;
}
form {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
margin: 0 auto;
}
.input-box {
padding-right: 5px;
display: flex;
width: 100%;
margin-bottom: 10px;
}
label {
width: 45%;
padding-right: 5px;
text-align: right;
}
input, textarea {
width: 150%;
}
<article id="article">
<div id="article_right">
<h2>Contact Us!</h2>
<form id="contact_form">
<div class="input-box">
<label for="contact_name">Full name:</label>
<input type="text" id="contact_name" name="contact_name" placeholder="Name" />
</div>
<div class="input-box">
<label for="contact_phone">Mobile number:</label>
<input type="tel" id="contact_phone" name="contact_phone" placeholder="Mobile number" />
</div>
<div class="input-box">
<label for="contact_email">Email address:</label>
<input type="email" id="contact_email" name="contact_email" placeholder="E-mail address" />
</div>
<div class="input-box">
<label for="contact_message">Message:</label>
<textarea rows="4" cols="40" id="contact_message" name="contact+message"
style="resize: none"></textarea>
</div>
<div class="button">
<button type="submit">Submit</button>
</div>
</form>
</div>
</article>
I'm trying to align this box and the two buttons below it directly in the center of the page [horizontally and vertically]. Whenever, I get the textbox to align center, the buttons always seem stuck on the side. I think it's the way I'm trying use CSS for the body and then move the text and buttons as well. The buttons need to be side by side under the textbox [with everything aligned directly in the center of the page].
Here is what I have so far:
.calc {
display: inline-block;
/* align-items: center; */
padding-top: 200px;
padding-left: 20px;
/* display: flex; */
}
.search_btn {
align-items: center;
width: 200px;
margin: 0 auto;
/* display: flex; */
display: inline-block;
}
.search_txt {
width: 300px;
margin: 0 auto;
display: block;
/* display: flex; */
/* flex-direction: column; */
border-radius: 25px;
}
<form class="calc" action="https://calculator.com">
<input class="search_txt" type="text" name="q">
<input class="search_btn" type="submit" value="value">
<input class="search_btn" type="submit" value="area">
<!-- <input class="search_btn" type="submit" value="perimeter"> -->
</form>
#Katie Melosto. I think that the most important thing to deal with flex box is to know where to apply flex to align items, i.e parent element or child element itself.
You can check this url for detailed information of flex css.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I have changed some part of your code.
Check this url for my chage.
"https://codepen.io/devbluesky111/pen/oNZxBYW"
body {
display: flex;
justify-content: center;
}
.calc {
display: inline-block;
/* align-items: center; */
padding-top: 200px;
padding-left: 20px;
display: flex-column;
}
.search_btn {
align-items: center;
width: 150px;
margin: 0 auto;
/* display: flex; */
display: block;
}
.search_txt {
width: 300px;
margin: 0 auto;
display: block;
border-radius: 25px;
margin-bottom: 10px;
}
.buttons {
display: flex;
/* flex-direction: column; */
}
<form class="calc" action="https://calculator.com">
<input class="search_txt" type="text" name="q">
<div class="buttons">
<input class="search_btn" type="submit" value="value">
<input class="search_btn" type="submit" value="area">
</div>
</form>
I think you need to wrap both your buttons in a container div and let that container have display:flex. Also your main form need to be display:flex as well but its direction would be flex-direction:column. Then to center things , you can just use align-items:center; justify-content:center
.form-buttons {
display: flex;
gap: 10px;
}
.calc {
display: flex;
flex-direction: column;
gap: 10px;
align-items: center;
justify-content: center;
height: 100vh;
}
.search_btn {
width: 200px;
}
.search_txt {
width: 300px;
border-radius: 25px;
}
<form class="calc" action="https://calculator.com">
<input class="search_txt" type="text" name="q">
<div class="form-buttons">
<input class="search_btn" type="submit" value="value">
<input class="search_btn" type="submit" value="area">
</div>
<!-- <input class="search_btn" type="submit" value="perimeter"> -->
</form>
Flex align items based on how many there are within the assigned element. So to do what you want you should wrap you buttons in a div and then set the container to flex with column. That will place the input and buttons in a column. Now set the container for the button to flex row.
.calc {
display: inline-block;
/* align-items: center; */
padding-top: 200px;
padding-left: 20px;
display: flex;
flex-direction: column;
}
#btnContainer {
display: flex;
}
.search_btn {
align-items: center;
width: 200px;
margin: 0 auto;
}
.search_txt {
width: 300px;
margin: 0 auto;
border-radius: 25px;
}
<form class="calc" action="https://calculator.com">
<input class="search_txt" type="text" name="q">
<div id="btnContainer">
<input class="search_btn" type="submit" value="value">
<input class="search_btn" type="submit" value="area">
</div>
<!-- <input class="search_btn" type="submit" value="perimeter"> -->
</form>
You can use display:gird; and place-items:center;
To align content in center
body {
display:grid;
place-items:center;
}
.calc {
display: inline-block;
/* align-items: center; */
padding-top: 200px;
padding-left: 20px;
/* display: flex; */
}
.search_btn {
align-items: center;
width: 200px;
margin: 0 auto;
/* display: flex; */
display: inline-block;
}
.search_txt {
width: 300px;
margin: 0 auto;
display: block;
/* display: flex; */
/* flex-direction: column; */
border-radius: 25px;
}
<form class="calc" action="https://calculator.com">
<input class="search_txt" type="text" name="q">
<input class="search_btn" type="submit" value="value">
<input class="search_btn" type="submit" value="area">
<!-- <input class="search_btn" type="submit" value="perimeter"> -->
</form>