DEV Community

Maasa Kono
Maasa Kono

Posted on

1

Updating React Form Layout, and Simple CSS Spacing Solution

There are a lot of features I want to add to my final portfolio project, "MOODetails". The purpose of this app is to take note of prompts to certain moods, and to differentiate between those that are and are not within your control.

Updating Form Layout

Before working on the additional features, I really wanted to update how the form looked because I found it too bland:

Alt Text

Here is what the original code looked like for the form portion of the above image:

Alt Text

I decided to put the form into React-Bootstrap's Card component, as well as Col (columns). Things were beginning to get jumbled with the additions, so I modified the spacing as well for better readability. Now, the code looks like this:

Alt Text

Though the code looks a bit longer and taking up more lines, I still think this looks much cleaner.

Spacing

The next thing I want to fix here is the spacing between the mood image and the form:

Alt Text

So originally, I was using break (<br>) tags to deal with the spacing issue, but this definitely made my code look clunky:

Alt Text

To solve this problem, I simply added class names to the components where I wanted to add a padding to the bottom so that I could manipulate them in the CSS file:

Mood.js
Alt Text

CSS file
Alt Text

Aaaaaaand voila! I've got the appropriate spacing between mood name, mood image, and form:

Alt Text

Helpful Links

React Bootstrap documentation on forms

Use Carbon to embed code snippets in a blog
There were some inconsistencies in the coloring here, but it still looks pretty nice!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay