表單不該用 <table> 排版。語意化做法:<form> + <label> + <input> + <span> 輔助說明,配合 CSS Float/Flex 佈局,結構清晰、無障礙友好、易於響應式調整。
<div id="stylized" class="myform">
<form id="form" method="post" action="#">
<h1>Sign-up form</h1>
<p>This is the basic look of my form without table</p>
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name" id="name" />
<label>Email
<span class="small">Add a valid address</span>
</label>
<input type="text" name="email" id="email" />
<label>Password
<span class="small">Min. size 6 chars</span>
</label>
<input type="password" name="password" id="password" />
<button type="submit">Sign-up</button>
<div class="spacer"></div>
</form>
</div>
label, input { float: left; } 讓標籤與輸入框同行。label { display:block; width:140px; text-align:right; } 固定標籤寬度右對齊。.small { display:block; font-size:11px; color:#666; } 輔助說明另起一行。.spacer { clear:both; height:1px; } 清除浮動。.myform { margin:0 auto; width:400px; } 置中限寬。
.form-group { display:flex; align-items:center; margin-bottom:1rem; }
.form-group label { flex:0 0 140px; text-align:right; padding-right:1rem; }
.form-group input { flex:1; }
Flex 版本更簡潔、無需 clearfix、響應式天然支援。語意化 HTML 不變,CSS 升級零負擔。