簡體   English   中英

使文本框對齊

[英]Making Text Boxes Aligned

我現在有一個問題。 當我加載網頁時,所有的框/詞都笨拙地對齊,我想知道是否可以得到一些幫助將框對齊在同一行上。

單擊此處獲取jsfiddle演示

<table bgcolor="#bbbbbb" width="100%" border="0" cellspacing="0" cellpadding="0" valign="center">
    <tr>
    <td width="10%" valign="top" align="center">
        <form name="form1" method="post" action="checklogin.php">
        <font size="5"><strong>Account Login</strong></font><br />
        Username :
        <input name="myusername" type="text" id="myusername"><br />
        Password :
        <input name="mypassword" type="password" id="mypassword"> <br />
        &nbsp;
        &nbsp;
        <input style="width:75px; font-size:14px; height:25px;" type="submit" name="Submit" value="Login">
        </form>
    </td>
    <td width="10%" valign="top" align="center">
        <form id="form1" name="form1" method="post" action="registration_script.php">
        <font size="5"><strong>Account Register</strong></font><br />
        Username :
        <input type="text" name="txtUser" id="txtUser" /> <br />
        Repeat :
        <input name="myusername" type="text" id="myusername"><br />
        Password :
        <input type="password" name="txtPassword" id="txtPassword" /> <br />
        Repeat :
        <input name="myusername" type="text" id="myusername"><br />
        <input style="width:75px; font-size:14px; height:25px;" type="submit" name="btnRegister" id="btnRegister" value="Register" />
    </td>
    </tr>
    </form>
</table>

嘗試檢查這一點: 編輯

希望這能給出想法(以我自己的方式:))。

 <table bgcolor="#bbbbbb" width="100%" border="0" cellspacing="0" cellpadding="0" valign="center">
<tr>
<td width="10%" valign="top" align="center">
    <form name="form1" method="post" action="checklogin.php">
    <table>
        <thead align="center">Account Login</thead>
        <tr>
            <td>Username :</td>
            <td><input name="myusername" type="text" id="myusername"></td>
        </tr>
        <tr>
            <td>Password :</td>
            <td><input name="mypassword" type="password" id="mypassword"></td>
        </tr>
        <tr>
            <td></td>
            <td colspan="1"><input style="width:75px; font-size:14px; height:25px;" type="submit" name="Submit" value="Login"></td>
        </tr>
    </table>
    </form>
</td>
<td width="10%" valign="top" align="center">
    <form id="form1" name="form1" method="post" action="registration_script.php">
    <table>
        <thead align="center">Account Register</thead>
        <tr>
            <td>Username :</td>
            <td> <input type="text" name="txtUser" id="txtUser" /></td>
        </tr>
        <tr>
            <td>Repeat :</td>
            <td><input name="myusername" type="text" id="myusername"></td>
        </tr>
        <tr>
            <td>Password :</td>
            <td><input type="password" name="txtPassword" id="txtPassword" /></td>
        </tr>
        <tr>
            <td>Repeat :</td>
            <td><input name="myusername" type="text" id="myusername"></td>
        </tr>
        <tr>
            <td></td>
            <td colspan="1"><input style="width:75px; font-size:14px; height:25px;" type="submit" name="btnRegister" id="btnRegister" value="Register" /></td>
        </tr>
    </table>
    </form>
</td>
</tr>

您可以定義自己的CSS來定義對齊方式

例如:

<style>
 selector{
  float:left;
 }
</style>

如果您不介意沒有餐桌:

<style>
    .pseudo-table, form p {
        display: table;
        background-color: #bbbbbb;
    }

    .pseudo-cell, form p label {
        display: table-cell;
        vertical-align: top;
    }

    form p label {
        width: 100px;
    }
</style>

<div class='pseudo-table'>
    <div class='pseudo-cell'>
        <form name='form1' method='post' action='checklogin.php'>
        <h2>Account Login</h2>
        <p>
            <label>Username</label>
            : <input name='myusername' type='text' id='myusername'>
        </p>
        <p>
            <label>Password</label>
            : <input name='mypassword' type='password' id='mypassword'>
        </p>
        <button>Login</button>
        </form>
    </div>
    <div class='pseudo-cell'>
        <form name='form2' method='post' action='registration_script.php'>
        <h2>Account Register</h2>
        <p>
            <label>Username</label>
            : <input type='text' name='txtUser' id='txtUser'>
        </p>
        <p>
            <label>Repeat</label>
            : <input name='myusername' type='text' id='myusername'>
        </label>
        <p>
            <label>Password</label>
            : <input type='password' name='txtPassword' id='txtPassword'>
        </p>
        <p>
            <label>Repeat</label>
            : <input name='myusername' type='text' id='myusername'>
        </p>
        <button>Login</button>
        </form>
    </div>
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM