How do I make the "sign up" text at the top of the form and not at the center with the rest of the forms stuff?
@import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
* {
font-family: "Lato", sans-serif;
box-sizing: border-box;
}
body,html {
margin: 0;
padding: 0;
background-color: #e1e1e1;
height: 100%;
width: 100%;
background-image: url('https://yourimageshare.com/ib/C5pVRCrHGx.webp');
background-size: cover;
}
.form-container {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.form {
display: flex;
justify-content: center;
align-self: center;
flex-direction: column;
background-color: #FFFFFF;
width: 30%;
height: 70%;
}
.title {
font-size: 50px;
text-align: center;
margin: 0;
}
.input-container {
width: 100%;
justify-content: center;
}
.input-name {
display: inline-block;
}
.input {
width: 90%;
}
<div class="form-container">
<form action="" class="form">
<h1 class="title">Sign up</h1>
<div class="input-container">
<input type="text" placeholder="First Name" class="input-name">
<input type="text" placeholder="Last Name" class="input-name">
</div>
<div class="input-container">
<input type="email" placeholder="Email" class="input">
</div>
<div class="input-container">
<input type="password" placeholder="Password" class="input">
</div>
<input type="submit" value="Submit" class="submit-btn">
</form>
</div>
WHAT THE CURRENT RESULT LOOKS LIKE :
Please ask me for any more details that are needed.
5
Answers
I’m not sure if this is what you mean but here you have the "Sign up" text centered above the form.
https://jsfiddle.net/MePhew/3s856e1L/12/
To achieve this you just have to move the title outside of the form element
In the JSFiddle example I also changed the title’s color to white so that it can be seen on top of your background
Structure your code a little more so that you can understand how your question was resolved
So why is your title centered to begin with ?
This is happening because of the
justify-content: center;
property that centers everything including your title.There are a lot of ways to achieve what you want, one of them is to wrap your inputs into a
div
and add thejustify-content: space-between;
to your form like this :If you don’t want your button to be displayed at the bottom of the form you can for example wrap everything but the title inside an element (I chose to use
<div class="main-content">
)And then you can change your form CSS into
justify-content: space-around;
Essentially it’s all to do with how you have structured your code. The heading is inside your form which is using display flex to control it’s position. To make it easier, you should move the
<h1>
outside of it.A copy of the code amended and commented can be seen here. I’ve added in some extra markup to help your code semantically.