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

Native JS encapsulation vue Tab switching effect

This article example shares the specific code of ...

Public free STUN servers

Public free STUN servers When the SIP terminal us...

Summary of pitfalls in importing ova files into vmware

Source of the problem As we all know, all network...

How to visualize sketched charts in Vue.js using RoughViz

introduce A chart is a graphical representation o...

Example of converting webpack images to base64

Download url-loader yarn add -D url-loader module...

Native js implements custom scroll bar component

This article example shares the specific code of ...

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...

Practical method of deleting a row in a MySql table

First, you need to determine which fields or fiel...

Detailed tutorial on how to automatically install CentOS7.6 using PXE

1. Demand The base has 300 new servers, and needs...

How to adjust the log level of nginx in Docker

Table of contents Intro Nginx Dockerfile New conf...