Home > Web Front-end > HTML Tutorial > How to center the form in html

How to center the form in html

coldplay.xixi
Release: 2023-01-03 09:24:08
Original
25477 people have browsed it

htmlHow to center the form: First add a parent tag fa outside the form; then add a class centered to the form, the code is [

How to center the form in html

The operating environment of this tutorial: windows7 system, html5 version, DELL G3 computer, this method is suitable for All brands of computers.

htmlMethods to center the form:

When the width and height of the form are not fixed, add a parent tag fa outside the form, and add a class centered to the form

<body>   
<div class="fa">
    <form name="search" method="post" action="#" class="centered">
       <input value="请输入关键词" type="text" name="q" />
       <input type="submit" value="搜索"/>
    </form>
</div>
</body>
Copy after login

After clearing the default style of the page (margin padding)

<style type="text/css"> 
html,body{width: 100%;height: 100%;}
.fa {text-align: center;height: 100%;}
.fa:before {content: &#39;&#39;;display: inline-block;height: 100%;vertical-align: middle;}
.centered {display: inline-block;vertical-align: middle;background: red;width: auto;}
</style>
Copy after login

Related learning recommendations: html tutorial

The above is the detailed content of How to center the form in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template