[Beginner] How to create a simple “sign in” frontend using reference
Tags: Begineers, Coding, Frontend, CSS, Tutorial

Step by step guide

Step 1: Quick draft

It is my habit to make a very quick draft on the design I am going to code, in order to better understand what I am dealing with , and have a better understanding on how I should put each of my component.

It is a relatively easy UI, there are only two layer:

Background layer, with all the colorful ball

Card layer, with the login input field and button

The background layer is more free flow, while the card layer is very symmetrical. You can see I draw a center line, which perfectly cut the “register” and “sign in” button. The card also drop a shadow to the background (which I am too lazy to draw)

One more observation on the design is the use of all CAPITAL letter, and a san-serif font type. It add more modern feeling touches to the UI. Also be aware of the color in the design, the font color is in a grey tone instead of black.

Step 2: Prepare resources

The next step is to gather the resources we need to code this piece of UI. As this UI don’t have any images, we only need to figure out the font family and color used in the design.

For color is easy, you can use any graphic software (or chrome plugin) to extract the color code from a picture. To save us some time, I have already prepare the color palette used in the design:

https://coolors.co/e15866-f5a900-06b7aa-cd67cc-e5e6e9-707070-2e3c55

While for font, there is no easy way to identify a font without a specification. I sometime use google font and select the filter I want (for this case, san-serif) and try to locale a font that look similar to the design. I end up choosing Open San (Light 300)

With the resources all set, let start coding!

Step 3: Create the background (Static)

First of all, let set up our project with all the font, color and sizes, also basic style that apply to everything

I highly recommend using a CSS preprocesser (such as SCSS or SASS, tutorial here), as they provide convenience feature like variable, mixin, better layout and e.t.c)

SCSS for basic setup:

Let explain it a little bit, the first line “@import” is for importing the font “open san” to this project. While

*, *:before, *:after { box-sizing: border-box }

set everything to use border-box sizing (as I think it is way easier to layout the design using it) The rest is size and color, we also set the default color and font size in body.

Now let create the basic background. (we will modify it later to make it animated, but for now, let start with the basic) The background is simply grey background color with 4 different sizes ball in different color, overlaying on top of each other. Let try to fill in the basic first. (we won’t get everything right at the first time, but it is a good starting point)

For the CSS:

You may have notice the use of percentage in positioning, it means the position will change on window resize (as the parent div, “background”, is having the same size as the window). It is acceptable for our case as we are going to animate the background later. If you are looking for a static background with no changes on proportion, do not use percentage.

Okay, now we have the basic background, let start working on the card.

Step 4: Create the card layer (container)

Now for the card, let start with the container. Now, since the card container is holding a sign up form, which require enough space to allow user to type in their information, we need to set a minimum width and height for it. While the card is allowed to grow when window size get bigger.

With a combination of min-height/min-width with fixed pixel value, and a height/width with percentage value, we could easily achieve this behaviour.

In addition, let not forget to give our card container a shadow, and rounded corner.

For the HTML, we only need to add one div with class “card” (inside body)

<div class='card' > </div>

In order to make the card center in both x and y axis, we could use the flex property of CSS in the parent of it (body). by adding:

.body {

...

display: flex;

align-items: center;

justify-content: center;

}

We tell all direct children of body to center vertically and horizontally within it. The balls won’t be affected as we defined the top/right/left/bottom position for them.

You can see the rest of the CSS for the card here:

we might change the size later but it is good for now!

I have modified the background a bit

Excellent, let add the detail in the card for next step.

Step 5: Add the card input detail

The next step is ti create the sign in form inside the card. Let start with the title and the input.

The form is very simple, there is a padding on the card surrounding the form, we could use a flex container and each component (title, input, “forgot password”) is a row of the container.

For the input, we will apply a little animation to make it response to user interaction. On user clicking the input, we will change the color of the input border line and the label, also move the label to top left a bit with decreased font size, like so:

In order to achieve this, we will use <label> element and the CSS selector input: focus + label. Be aware this selector only works for label element immediately after input element.

The complete style for the html and scss for the form as follow:

Now we have our login in form and the basic, let add the button to the form to complete it.

The button should always be at the bottom of the form, so we could use absolute positioning. The two buttons each talk up 50% of the “button bar”.

Okay, the static UI is completed now. Let add some animation.

Step 6: Animate the background

To make thing look more interesting, let also make the background moving using some animation.

In order to create some dynamic in the background, I want to make the 4 balls in bounce off the window randomly, and overlapping with one another. In order to make ball “bounce” when it hit the window, we could make use of viewheight and viewwidth property in CSS.

Since the whole screen is 100vh in height and 100vw in width, the total distance each ball need to travel in x and y direction is 100vw - size and 100vh - size respectively:

The only problem is, if we make the ball to travel in that way, the ball always end up in the bottom right corner, then back to top left corner. It is still “bouncing”, but not in an interesting way. Instead, we would need to separate the x and y direction of the translate, and then apply them in two different div, the ball container and actual ball, each with different animation speed.

We would need to modify the ball a bit, as well as adding the animation. I used mixin here to help me create multiple keyframe more effectively.

HTML:

SCSS:

The reason for giving each keyframe an id is because each keyframe should have a unique name.

Step 7: Final polish

Our sign in page is almost completed, let add some more polish to it for better user interaction.

Sign up and register button transition

Forgot password transition

And then bring us back to our demo. Our frontend is ready for further coding (perhaps logic to actually login user?)