CSS讓同一行文字和輸入框對齊

來源:互聯網
上載者:User

大家都知道有時候一個文本輸入框和一段文字在同一行上顯示,然而它們總不是垂直置中,看上去不美觀,這段CSS代碼就是解決這一問題的,上邊一行是沒有定義,下邊一行是定義過的,可以看出有明顯的差別。

 

<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dt-->
<html>
<head>
<title>CSS讓同一行文字和輸入框對齊</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#a {
 height:30px;
 border:1px solid #ccc;
 }
#b {
 margin-top:20px;
 height:30px;
 border:1px solid #ccc;
 }

#a input {
 width:200px;
 height:30px;
 border:1px solid red;
 }
#b input {
 width:200px;
 height:30px;
 border:1px solid red;
 vertical-align:middle;
 }
</style>
</head>
<body>
<div id="a"><input />Text1</div>
<div id="b"><input />Text2</div>
</body>
</html>

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.