What could be causing my CSS Grid to misbehave?

I am diving into the world of CSS Grid and attempting to create a sign-up page similar to that of Facebook.

The layout I have in mind involves placing the first name and last name on one line, the email address on another line, and a submit button on a third line. The challenge is to make the email field span across columns.

Here's a snippet of my HTML and CSS code:

<!DOCTYPE HTML>
<title> Crafting JavaScript Form Validation with a Hint of CSS Grid </title>

<style>
    html,body{
        height : 100%;
    }
    body{
        display : flex;
        display : -webkit-flex;
        display : -moz-flex;
        justify-content : center;
        align-items : center;
    }

    form{
        display : grid;
        grid-columns : 200px 1% 200px;
        grid-rows : auto 1% auto 1% auto;
        border : 1px solid black;
    }
    #fname{
        grid-column : 1;
        grid-row : 1;
    }

    #lname{
        grid-column : 3;
        grid-row : 1;
    }

    #email{
        grid-row : 2;
        grid-column-span : 3;
    }

    #submit{
        grid-row : 3;
        grid-column-span : 3;
    }

</style>
<body>
        <form>
            <input type="text" name="fname" id="fname" required="true" placeholder="First Name"/>
            <input type="text" name="lname" id="lname" required="true" placeholder="Last Name"/>
            <input type="email" name="email" id="email" required="true" placeholder="Email"/>
            <button id="submit">Submit</button>
        </form>
</body>  

This setup yields an output of:

I'm open to constructive criticism!:What improvements can be made?

Answer №1

Here is the desired outcome you are aiming for.

VIEW FIDDLE

This demonstration utilizes CSS properties like floats and box-sizing:border-box; (compatible with IE 8 and newer versions)

CSS :

html, body {
    height: 100%;
}
body {
}
form {
    border: 1px solid black;
}
input {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    margin: 0.3%;
    padding: 0.3%;
    float: left;
}
#fname, #lname {
    width: 49.4%;
}
#email {
    width: 99.4%;
}
#submit {
    display: block;
    clear: both;
}

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

Utilize HTML layout with Express.js framework

Recently delving into NodeJs, I managed to craft a single HTML page complete with Header and Footer. My next task is to utilize this as the main layout for other HTML pages without resorting to Jade. Is it possible to define and implement layouts using H ...

What is the method to restrict the selection of only one option for specific values in a multiple-selection dropdown menu?

Is there a way to create a dropdown menu with the following functionalities: I want to allow multiple selections for options A, B, and C, but disable multiple selection if option D is selected. Any tips on how to achieve this? Thank you. <label>Ch ...

JavaScript accordions failing to open

I've encountered an issue with my website that includes JS accordions. Strangely, they are not opening on the live site, but they function properly on Codepen. I checked the console in Chrome and found no error messages, however, when I looked at the ...

Interact with various contenteditable sections by navigating with the arrow keys

I have a challenge with multiple <p contenteditable="true"></p> elements on my page. I am seeking a solution to enable the use of arrow keys to navigate seamlessly across these separate elements as if they were one cohesive editable element. F ...

Ajax is updating the information stored in the Data variable

Recently, I reached out to tech support for help with an issue related to Ajax not executing properly due to Access-Control-Allow-Origin problems. Fortunately, the technician was able to resolve the issue by adding a file named .htaccess with the code Head ...

Tips for centering an image vertically in a table's cell

I'm looking to vertically center the text, but I'm not sure how to do it. Check out my attempt on the fiddle link below: http://jsfiddle.net/jTW4d/ ...

Customizing Row Background Color in Bootstrap

Currently working on a project www.codepen.io/anon/pen/yMmjZb The problem I am facing is with my 3rd row (the one with the 3 columns) where the background color is bleeding beyond the intended boundary. My suspicion is that it's due to the row span ...

The index.html file is not displaying correctly on a servlet 3.0 configuration with Tomcat

I am currently working on a basic web application using Servlet 3.0 with Tomcat 7.0.25, and deploying the application as a war file named mywebapp.war. The structure of the war file is as follows: mywebapp/index.html mywebapp/META-INF/MANIFEST.MF myweba ...

Retrieve the scope object using angular.element and the $ID parameter

In order to transfer data from an angular application to scripts that operate outside of angular, I am seeking a solution since I cannot modify the code of the angular app. By utilizing Angular Batarang and NG-Inspector extensions in Chrome, I have identi ...

placing an image within a frame

I am having trouble aligning two divs side by side. I want to create a white background box with the date displayed in the top right corner, and I want the image to be at the same height as the date. Below is the code I have written: #boxx { background-c ...

Adding a background behind the currency symbol before the textbox field

I need to customize a text field like the one shown in the image below: https://i.sstatic.net/gu3JA.png After making some quick adjustments, I ended up with the following result. My main concern is now the background of the currency symbol. https://i.ss ...

Styling does not affect an Angular component that is injected into an iframe

I am facing an issue with styling in an iframe when trying to append my own angular component. Despite various attempts, I have been unsuccessful in getting the styling to apply to the component within the iframe. Upon loading the iframe, I use JavaScript ...

Managing cookies using JavaScript functions

Is there a way to set a cookie based on the CSS file selected in my HTML? I have a form with a list of options, each representing a different CSS file. I want to save the selected file to a cookie that lasts for a week, so the next time the HTML file is op ...

How come an absolutely positioned element does not disregard its sibling's position and appears after it?

<div> is styled flexibly, while <section> is inserted within it and formatted statically. However, <section> shows up underneath the lower right corner of the image, rather than at the upper left corner of its flexible parent. I am strugg ...

Customize JqGrid Edit/Delete button CSS style

Within my JQGrid, I have successfully implemented Edit and Delete buttons that redirect users to another page for editing or deleting specific records. However, I am facing a CSS issue with the styling of these buttons. How can I override the current style ...

Finding the filename using the event object in JavaScript: A step-by-step guide

Picture this scenario: an HTML file named page1.html includes a script tag for base.js. Within base.js (an external JavaScript file), I assign an onclick listener to a button that exists in page1.html. This base.js file is also included in script tags on o ...

What are the steps to adjust image size using CSS in an email signature?

Having trouble with my email signature. It appears fine on my end, but when the recipient replies, the images are oversized and the css is not rendering correctly in their response. I'm puzzled as to why this is happening. Here's the code snippe ...

Sharing a codepen.io project on a GitHub page

After completing the courses on free code camp, I successfully created a tribute page project on codepen.io. However, when attempting to display the finished website on GitHub using GitHub pages, I have encountered issues. No matter what steps I take, the ...

The search function on my blog is not displaying the blogs that have been filtered

I have encountered an issue with my code as I am unable to get any search results from the search bar. const RecentBlogs = ({recentBlogs}) => { const [query, setQuery] = useState("") const filteredItems = (() => { if(!query) return rec ...

What steps can I take to make my search button work with this JavaScript code?

I am struggling with integrating my custom search bar with a JavaScript code to make it functional. Here is the code snippet for the Search Button: document.getElementById('searchform').onsubmit = function() { window.location = 'http:/ ...