How to align text boxes in multiple forms in HTML

How to align text boxes in multiple forms in HTML

The form code is as shown in the figure. The style sheet has not been added yet, so the form is not aligned and looks ugly. However, HTML does not provide any tags or functions for form alignment.

HTML source code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>massage-board</title>
</head>
<body>
    <form action="board.php">
        <fieldset>
        <p>
            <label for="title" >title:</label>
            <input type="text" id="title" name="title" align="left">
        </p>
        <p>
            <label for="username">username:</label>
            <input type="text" id="username" name="username" align="left">
        </p>
        <p>
            <label for="messageContent">message content:</label>
            <textarea id="messageContent" name="messageContent" cols="40" rows="5" align="left"></textarea>
        </p>
        <p>
            <input type="submit">
        </p>
        </fieldset>
    </form>
</body>
</html>

Form display effect picture:

To align the form, add the following CSS code to the HTML, and the form will be aligned:

<style>
        fieldset{
            background-color: #f1f1f1;
            border: none;
            border-radius: 2px;
            margin-bottom: 12px;
            overflow: hidden;
            padding: 0.625em;
        }

        label{
            cursor: pointer;
            display: inline-block;
            padding: 3px 6px;
            text-align: right;
            width: 150px;
            vertical-align: top;
        }

        input{
            font-size: inherit;
        }
    </style>

The form display effect after adding the style sheet

The CSS code snippet to achieve form alignment is as follows:

        label{
            cursor: pointer;
            display: inline-block;
            padding: 3px 6px;
            text-align: right;
            width: 150px;
            vertical-align: top;
        }

Assume that the parent element of each form is the <p> tag, <label> tag is the description of the form, that is, the text on the left side of the text box, and <input> tag is the text box. To align the labels, you only need to set the width of the label tag to a certain value, such as 150px in this example. Because the label tag and the input tag belong to the same p tag, they are displayed from left to right. By specifying the length of the label tag, the text boxes of the form can be aligned.

This is the end of this article about how to align text boxes in multiple forms in HTML. For more information about aligning text boxes in multiple forms in HTML, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Payment function implementation in vue project (WeChat payment and Alipay payment)

>>:  Share the 15 best HTML/CSS design and development frameworks

Recommend

HTML markup language - reference

Click here to return to the 123WORDPRESS.COM HTML ...

Web Design Tutorial (4): About Materials and Expressions

<br />Previous Web Design Tutorial: Web Desi...

MySQL table return causes index invalidation case explanation

Introduction When the MySQL InnoDB engine queries...

How to prevent users from copying web page content using pure CSS

Preface When I was typing my own personal blog, I...

Detailed analysis of matching rules when Nginx processes requests

When nginx receives a request, it will first matc...

How to use Tencent slider verification code in Vue3+Vue-cli4 project

Introduction: Compared with traditional image ver...

MySQL latest version 8.0.17 decompression version installation tutorial

Personally, I think the decompressed version is e...

Detailed explanation of using MySQL where

Table of contents 1. Introduction 2. Main text 2....

Mini Program to Implement Simple List Function

This article example shares the specific code of ...

How to build Jenkins+Maven+Git continuous integration environment on CentOS7

This article takes the deployment of Spring boot ...

Share 20 excellent web form design cases

Sophie Hardach Clyde Quay Wharf 37 East Soapbox Rx...

HTML iframe usage summary collection

Detailed Analysis of Iframe Usage <iframe frame...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

MySQL foreign key (FOREIGN KEY) usage case detailed explanation

Introduction: The disadvantages of storing all da...