繁体   English   中英

将表单与HTML + CSS3上的中心对齐

[英]Align form to the center on HTML + CSS3

为什么此表格不显示居中? JSFIDDLE

<body>

        <div class="text-centered">
          <form name="frmregister" action="<?= $_SERVER['PHP_SELF'] ?>" method="post" >
            <table border="0">
                <tr>
                    <td></td>
                    <td style="color:red;"><?php echo $msg; ?></td>
                </tr>
                <tr>
                    <th><label for="name"><strong>Name:</strong></label></th>
                    <td><input class="inp-text" name="name" id="name" type="text" size="30" /></td>
                </tr>
                <tr>
                    <th><label for="name"><strong>Password:</strong></label></th>
                    <td><input class="inp-text" name="password" id="password" type="password" size="30" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td class="submit-button-right">
                        <input class="send_btn" type="submit" value="Submit" alt="Submit" title="Submit" />
                        <input class="send_btn" type="reset" value="Reset" alt="Reset" title="Reset" />
                    </td>
                </tr>
            </table>
          </form>
        </div>
</body>

text-center不会使div或form元素居中。 ;-)

将此添加到您的CSS中,它将使您的表单居中:

body { text-align: center; }
     /* center all items within body, this property is inherited */
body > * { text-align: left; }
     /* left-align the CONTENTS all items within body, additionally
        you can add this text-align: left property to all elements
        manually */
form { display: inline-block; }
     /* reduces the width of the form to only what is necessary */

更新的小提琴:

http://jsfiddle.net/mLrwq1w6/2/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM