My HTML form looks so ugly because in last name it has right offset(I don't want that)
image showing what I mean and I could not find any problems,
maybe someone can help? Below I added HTML and SCSS code.
Thank you for help.
.contact{
display: flex;
justify-content: center;
align-items: center;
height: 60vh;
width: 100%;
}
#mixin contact_form_input_style {
width: 100%;
background-color: $img-wrapper-bg-color;
border: none;
border-radius: 10px;
height: 50px;
padding: 10px;
margin: 10px;
}
.contact-form{
display: flex;
width: 60%;
justify-content: center;
align-items: center;
flex-direction: column;
.email{
width: 100%;
input,textarea{
#include contact_form_input_style;
}
textarea{
resize: none;
height: 100px;
}
}
.name{
display: flex;
width: 100%;
input{
#include contact_form_input_style;
}
}
}
<form method="post" action="" class="contact-form">
<div class="name">
<input type="text"/>
<input type="text"/>
</div>
<div class="email">
<input type="email"/>
<textarea></textarea>
</div>
<input type="submit" value="submit" name="submit">
</form>
Change the .contact-form .email div to flex so the children won't go outside the parent space
.contact {
display: flex;
justify-content: center;
align-items: center;
height: 60vh;
width: 100%;
}
.contact-form {
display: flex;
width: 60%;
justify-content: center;
align-items: center;
flex-direction: column;
}
.contact-form .name {
display: flex;
width: 100%;
}
.contact-form .name input {
width: 100%;
background-color: grey;
border: none;
border-radius: 10px;
height: 50px;
padding: 10px;
margin: 10px;
}
.contact-form .email {
display: flex;
flex-direction: column;
width: 100%;
}
.contact-form .email input,
.contact-form .email textarea {
background-color: grey;
border: none;
border-radius: 10px;
height: 50px;
padding: 10px;
margin: 10px;
}
.contact-form .email textarea {
resize: none;
height: 100px;
}
<form method="post" action="" class="contact-form">
<div class="name">
<input type="text" />
<input type="text" />
</div>
<div class="email">
<input type="email" />
<textarea></textarea>
</div>
<input type="submit" value="submit" name="submit">
</form>
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 am designing a simple signup form using Html and CSS. I just want to " already have an account ? Log in" text to left till the border of skyblue border, butI am unable to do that.
But I am getting result
Here is my html code
<div class="register-bg">
<div class="register-container">
<form>
<label for="email"><b>Email</b></label>
<input
type="text"
placeholder="Enter Email"
name="email"
required=""
/>
<label for="password"><b>Password</b></label>
<input
type="password"
placeholder="Enter Password"
name="password"
required=""
/>
<button type="submit" class="signup">Sign Up</button>
<Link>
<h1 class="register-login">
alredy have an account ? Log in
</h1>
</Link>
</form>
</div>
</div>
Here is my css code
.register-bg{
height: 100vh;
background-size: cover;
width: 100%;
background-image: url(../public/images/bg.jpg);
}
.register-container{
margin-top: 100px;
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 70%;
margin-left:27rem;
background: rgb(53, 105, 46);
align-items: center;
justify-content: center;
padding: 50px 0;
}
.register-container > form{
background:skyblue;
display: flex;
flex-wrap: wrap;
flex-direction: column;
width: 70%;
justify-content: center;
align-items: center;
}
.register-container input{
width: 80%;
font-size: 15px;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
text-align: center;
border: none;
background: #f1f1f1;
}
.register-login {
color: black;
font-size: 15px;
}
.signup{
align-items: center;
font-size: 14px;
font-weight: bold;
background-color: rgb(10, 119, 13);
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
opacity: 0.9;
}
Just add this to your CSS:
.register-login {
align-self: flex-start;
}
Wrap your <Link> in a div container
<div class="login-text-container">
<Link>
<h1 class="register-login">
alredy have an account ? Log in
</h1>
</Link>
</div>
Wet its width to 100%
.login-text-container {
width: 100%;
}
Full code:
.register-bg {
height: 100vh;
background-size: cover;
width: 100%;
background-image: url(../public/images/bg.jpg);
}
.register-container {
margin-top: 100px;
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 70%;
margin-left: 27rem;
background: rgb(53, 105, 46);
align-items: center;
justify-content: center;
padding: 50px 0;
}
.register-container>form {
background: skyblue;
display: flex;
flex-wrap: wrap;
flex-direction: column;
width: 70%;
justify-content: center;
align-items: center;
}
.register-container input {
width: 80%;
font-size: 15px;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
text-align: center;
border: none;
background: #f1f1f1;
}
.register-login {
color: black;
font-size: 15px;
}
.signup {
align-items: center;
font-size: 14px;
font-weight: bold;
background-color: rgb(10, 119, 13);
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
opacity: 0.9;
}
.login-text-container {
width: 100%;
}
<div class="register-bg">
<div class="register-container">
<form>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required="" />
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" required="" />
<button type="submit" class="signup">Sign Up</button>
<div class="login-text-container">
<Link>
<h1 class="register-login">
alredy have an account ? Log in
</h1>
</Link>
</div>
</form>
</div>
</div>
add the following code, edit it and you are good to go :)
CSS:
.login-button {
display: block;
padding: 100%;
align-items: left;
}
HTML:
<div class='login-button'>
<h1 class="register-login">
alredy have an account ? Log in
</h1>
</div>
I don't know how to float my button right and I hope someone can help me out here.
The yellow color shows the background of the div. The width of the div is set to 50%.
.faq {
width: 100%;
padding: 12px 20px;
display: block;
box-sizing: border-box;
width: 50%;
margin: auto;
margin-top: 30px;
}
.outerDiv {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin-top: 20px;
background-color: yellow;
}
.save {
float: right;
background-color: red;
}
<div class="outerDiv">
<h2>New FAQ</h2>
<input type="text" class="faq">
<br>
<button class="save" mat-raised-button color="primary">Primary</button>
</div>
What am I doing wrong?
Floats do not work in a flex container
Use align-self:flex-end instead
.faq {
padding: 12px 20px;
display: block;
box-sizing: border-box;
width: 50%;
margin: auto;
margin-top: 30px;
}
.outerDiv {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin-top: 20px;
background-color: yellow;
}
.save {
align-self:flex-end;
background-color: red;
}
<div class="outerDiv">
<h2>New FAQ</h2>
<input type="text" class="faq">
<br>
<button class="save" mat-raised-button color="primary">Primary</button>
</div>
.faq {
width: 100%;
padding: 12px 20px;
display: block;
box-sizing: border-box;
width: 50%;
margin: auto;
margin-top: 30px;
}
.outerDiv {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin-top: 20px;
background-color: yellow;
}
.save {
margin-left:auto;
background-color: red;
}
<div class="outerDiv">
<h2>New FAQ</h2>
<input type="text" class="faq">
<br>
<button class="save" mat-raised-button color="primary">Primary</button>
</div>
Floats do not work with flex.
There are two approaches that you can take here.
Approach #1:
Use align-self: flex-end on the button. This would make the button appear in the rightmost corner of your parent.
Approach #2:
In case you want more control over the position of the button in terms of alignment with the text area, you can wrap the button in a div and keep the float right on the button.
HTML
<div class="button-wrapper">
<button class="save" mat-raised-button color="primary">Primary</button>
</div>
CSS
.button-wrapper {
width: 50%; /* same as the width of your input*/
}
I am trying to place a checkbox below a text input box, but my InputBar is not occupying the full parent width and checkbox is appearing at the end of InputBar.
I am a front-end newbea, can someone suggest what can I change to place the checkbox under the input bar.
My styling code:
.background {
background-image: url("../Back.jpg");
background-repeat: no-repeat;
margin: -11px -16px 0 -16px;
background-size: 100%;
min-height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.inputBar {
padding-left: 30%;
width: 100%;
.enterButton {
background: url("../arrowNext.svg") no-repeat center white;
height: 50px;
width: 35px;
border-top-right-radius: 100px;
border-bottom-right-radius: 100px;
vertical-align: top;
}
.enterText {
color: $primary-text-color-light;
width: 60%;
height: 50px;
border-top-left-radius: 100px;
border-bottom-left-radius: 100px;
display: inline-block;
vertical-align: top;
padding-left: 2%;
}
}
.check {
display: inline-block;
.checkBox {
width: 40px;
height: 20px;
background: #555;
margin: 5px;
border-radius: 3px;
padding-left: 30%;
}
.checkBoxText {
font-weight: bold;
font-size: larger;
color: grey;
background-color: whitesmoke;
}
}
<div class="background">
<div class="inputBar">
<input class="enterText" id="inputBox" type="text" placeholder="Enter something" />
<button class="enterButton">Enter</button>
</div>
<div class="check">
<input class="checkBox" type="checkbox" defaultChecked/>
<span class="checkBoxText">Check this</span>
</div>
</div>
By default, flex sets direction to row.
You can set flex-direction: column to achieve what you want.
.container {
display: flex;
flex-direction: column;
}
<div class="container">
<div>
<input type="text" />
<button>Enter</button>
</div>
<div>
<input type="checkbox" id="check-this" />
<label for="check-this">Check this</label>
</div>
</div>
In my form, the lables/inputsare aligned with floats and fixed widths. Because of this, my labels have empty whitespace which makes it difficult to center the form in the parent div.
How can I center this form?
#Form1Layout {
font-family: Verdana;
font-size: 10pt;
margin-top: 10px;
text-align: center;
padding: 10px;
}
#Form1Layout label {
text-align: right;
padding-right: 10px;
width: 80px;
}
#Form1Layout input {
width: 300px;
}
#Form1Layout label,
#Form1Layout input {
display: block;
float: left;
margin-bottom: 10px;
}
#Form1Layout br {
clear: both;
}
<div>
<div id="Form1Layout">
<label>User name:</label><input type="text" /><br>
<label>Address:</label><input type="text" /><br>
<label>Phone:</label><input type="text" /><br>
<label></label><button class="My_Button">Submit</button>
</div>
</div>
Use flexboxes for that. Here is a quick example.
(I intentionnaly increased the height of the inputs to show you how it works).
#Form1Layout {
font-family: Verdana;
font-size: 10pt;
margin-top: 10px;
text-align: center;
padding: 10px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
}
#Form1Layout > div {
flex: 1 1 auto;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
margin: 6px 0;
}
#Form1Layout label {
text-align: right;
padding-right: 10px;
width: 80px;
}
#Form1Layout input {
width: 300px;
height: 80px;
}
<div>
<div id="Form1Layout">
<div><label>User name:</label><input type="text" /></div>
<div><label>Address:</label><input type="text" /></div>
<div><label>Phone:</label><input type="text" /></div>
<div><label></label><button class="My_Button">Submit</button></div>
</div>
</div>