What is the best way to ensure the proper formatting of my initial form?

Hello, I am encountering some challenges with formatting my form. As a beginner in web coding, I apologize for what may seem like a simple issue - this is the first form I am attempting to code.

My objective is as follows:

  • On screens and tablets: have form labels aligned right and justified next to form elements
  • On phones: align form labels left and justified above the left-aligned and justified elements
  • Ensure the submit button is right-aligned and justified

I am using flexboxes to achieve all of these requirements.

Here is the progress I've made 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>

In the snippet provided above, the formatting appears better than what it looks like on the actual webpage: Link to image showing full website coding with formatting issues

If you have some free time and would like to give feedback, I have uploaded everything here: Link to contact form webpage

Wireframes depicting the intended look of the website

Thank you for your assistance—any feedback is greatly appreciated!

Answer №1

With the assistance provided above, I have implemented the following CSS code:

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>

I am currently fine-tuning the positioning and formatting of the elements. The input boxes may need some adjustments, and I aim to have the labels aligned to the left.

Thank you for your guidance!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic Navbar that Adapts to Your Scroll

I'm experiencing an issue with my navbar. I want it to stay at the top of the page when I scroll, but whenever I apply the "position: fixed;" property, the navbar disappears. Below is my HTML and CSS code: <nav> <div class="navbar"> <b ...

Chosen Dropdown selection - Retrieve/Receive information

One of the challenges I'm facing involves a dropdown list on my web form that contains various dates. My main query is: How can I retrieve data for the selected date from a MySQL database and present it to the user? Additionally, if the chosen date do ...

Tips on changing an image with a button click

I am currently working on a project where I have a div tag containing an image that is selected randomly from different arrays based on topics. However, I am facing some challenges in making the image change when the "go" button is clicked. I want the if ...

Clicking on the checkbox will trigger an AJAX request to cache the

Encountering a problem with an old system I am currently updating: In the <div id='list'>, there is a checkbox list. Upon clicking a checkbox, it triggers an ajax request that returns JavaScript to execute. The JavaScript in the Ajax requ ...

javascript, issues with floating and displaying elements

I am currently working on creating a JavaScript menu that has a click function to smoothly slide up and down. Although the JavaScript code appears to be functioning correctly, it seems that there is some interference with the CSS. Despite attempting vario ...

Tips for customizing the appearance of path elements within an external SVG file being utilized as a background image

How can I change the color of the paths in an SVG background image assigned to a div using CSS? ...

`Can Beautiful Soup extract data (text) from elements that share the same class identifier?`

Currently working on a personal project focused on web scraping, using beautiful soup to extract data from a website. Encountered an issue where data with the same class but different attributes is present. For instance: <div class="pi--secondary-price ...

Technique for updating URL when submitting a form on a webpage

I'm a newcomer to the world of coding and I have a simple issue that needs fixing. I want to create a form field where users can input the last segment of a URL provided to them. After entering this segment, I want the page to refresh automatically a ...

Rotating arrows enhance the functionality of the accordion menu

I have successfully implemented a basic accordion with rotating arrows on click. Everything is working smoothly except for one issue: When I collapse one item and then try to collapse another, the previous arrow does not return to its default state. Is ...

"Strategically placing elements on an HTML grid

My current project involves creating a grid layout in HTML using CSS. The goal is to use this layout for various elements such as images, text, and links. What I envision is a visually appealing grid where each object fits together seamlessly with no gaps ...

Exploring the World of Bootstrap 4 Cards

Just starting out in UI/UX, I played around with some gallery transitions featuring hover effects, and incorporated Bootstrap cards into the mix. When I hover over the image (which was blank at first), it now displays an overlay with the intended text, alo ...

Making modifications to the CSS within an embedded iframe webpage

Assigned with the task of implementing a specific method on a SharePoint 2013 site. Let's dive in. Situation: - Within a page on a SharePoint 2013 site, there is a "content editor" web part that displays a page from the same domain/site collection. T ...

Discover the secrets of extracting the ID from a MenuItem within a Menu

Table Ui with menu Struggling with fetching the correct user ID in the edit button The edit button for all users is only displaying the last user's ID If the edit button is not nested inside the Menu, it works fine. However, within the Menu, it onl ...

I am working on an HTML form that is designed vertically, but I am unsure of how to arrange two text fields side by side on the same line

I'm struggling with formatting my HTML form to have two text fields on the same line instead of stacked vertically. In the example below, I want the Size, Width, and Height fields to be aligned horizontally rather than one below the other. <form c ...

Obtaining the width of a scrollbar using JavaScript in the most recent version of Chrome

Looking for a way to determine the width of the scrollbar using JavaScript for CSS purposes. I attempted the following: document.documentElement.style.setProperty('--scrollbar-width', (document.offsetWidth - document.clientWidth) + "px" ...

How come there is such a large space for clicking between my logo and the navigation bar, and what can be done to eliminate it?

* { box-sizing: border-box; padding: 0; margin: 0; } ul { list-style-type: none; } .nav-links, .logo { text-decoration: none; color: #000; } .logo { max-width: 80%; width: 20%; height: 20%; } .navbar img { width: 10%; height: auto; di ...

Creating a CSS animation to mimic the fading in and out effect of the Mac scrollbar when scrolling begins

My journey begins with this: *::-webkit-scrollbar { } *::-webkit-scrollbar-button { } *::-webkit-scrollbar-track { } *::-webkit-scrollbar-track-piece { } *::-webkit-scrollbar-thumb:active { width: 6px; background-color: red; } *::-webkit-scr ...

Can you suggest the best HTML5 structure for a multi-chapter novel?

In the process of creating a small HTML5 book with chapters and sections, I encountered a dilemma when it comes to structuring my documents like this: chapter1.html - introduction to chapter 1 chapter1section1.html - section 1.1 chapter1section2.ht ...

The progress bar is visually enhanced with a border style that doubles as a background color

While experimenting with a jsfiddle to create an animated progress bar, I stumbled upon something peculiar. I had a single CSS rule applied to the progress tag: progress { border:2px solid #ccc; } Prior to adding this CSS rule, the progress bar looke ...

Attempting to display a brief description when hovering over a particular project image

My goal on is to display a description when hovering over a portfolio image by setting the opacity to 1. However, this functionality seems to not be working. .description { display: block; opacity: 0; text-align: left; height: 130px; padding- ...