CSS表徵圖文字對齊和表單輸入框文字對齊相容

來源:互聯網
上載者:User

標籤:

張鑫旭的一篇文章,講到20像素表徵圖對齊和表單元素40像素對齊有所收穫,謝謝@張鑫旭 ,很多觀點跟平時的處理方式不謀而合,一般來說,我處理表徵圖如果臨近的話都會使用同樣寬高,然後使用inline-block比較多,表單輸入框和按鈕以line-height:21-22為準。然後超出的用padding來補充。

以下摘錄部分原文中的實踐代碼。

1.表徵圖和文字對齊

一般的表徵圖和文字對齊html代碼:

<p><i class="icon"></i>前端開發部落格</p><p><a href="javascript:" class="icon">刪除</a>前端開發部落格</p>

zxx的CSS代碼:

p{line-height:20px; font-size:14px;}.icon {     display: inline-block;     width:20px; height:20px;     background: ...;     white-space:nowrap;     letter-spacing: -1em;     text-indent: -99em;     color: transparent;    /* IE7 */    *text-indent: 0;    *zoom: expression( this.runtimeStyle[‘zoom‘] = ‘1‘, this.innerHTML = ‘\3000‘);}.icon:before {    /* 虛擬元素插入空格文本 */    content: ‘\3000‘; }

這個代碼主要是通過line-height來控製圖標的文字和臨近的文字同樣行高,實現在同一行中。

2.表單輸入框和內容對齊

簡單的一個文字和文本輸入

<div class="clearfix mt15"><label class="left">手機號<span class="red abs">*</span></label><div class="cell"><input type="tel" class="ui_input" name="tel" required=""></div></div>

CSS代碼:

body{font:14px/1.42858 ‘microsoft yahei‘, arial, sans-serif; -webkit-font-smoothing: antialiased; } /*行高為20像素*/.cell {display: table-cell;*display: inline-block;width: 2000px;*width: auto;}input.ui_input,.ui_input > input {height: 20px;line-height: 20px;padding: 9px 8px;border: 1px solid #d0d0d5;border-radius: 4px;background-color: #fff;font-size: 14px;outline: none;color: #545a6c;-webkit-transition: border-color .15s, background-color .15s;transition: border-color .15s, background-color .15s;}

參考文章:以20像素為基準的CSS網頁布局實踐分享

CSS表徵圖文字對齊和表單輸入框文字對齊相容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.