標籤:
HTML:
<div class="title-wrapper"> <span class="title"> <span class="icon sp-index sp-index-tag-bg"> <i class="mood2 sp-base"></i> </span> <span class="txt"> <span class="occupy">吳奇隆機場推行李車 劉詩詩走其身側秀美腿</span> <a href="/" target="_blank">吳奇隆機場推行李車 劉詩詩走其身側秀美腿</a> </span> </span> </div>
CSS:
.focus-r{width:480px;}.focus-r-base{width:480px;height:270px;position:relative;overflow:hidden;}.focus-r-base .title-wrapper{width: 100%;height: 50px;position: absolute;bottom: 12px;text-align: center;}.focus-r-base .title-wrapper .title{display: inline-block; }.focus-r-base .title-wrapper .icon{width: 50px;height: 50px; float: left;}.focus-r-base .title-wrapper .icon i{display: inline-block;width: 33px;height: 33px; margin-top: 8px; text-indent: 0;}.focus-r-base .title-wrapper .txt{float: left; height:34px;line-height:34px; padding-top: 8px; color:#fff;font-size: 14px; word-spacing: 0;}.focus-r-base .title-wrapper .txt .occupy{position: absolute; top: 8px; background: #000; filter:Alpha(opacity=60); opacity:.6; padding-right: 10px; border-radius:0 15px 15px 0;}.focus-r-base .title-wrapper .txt a{color:#fff; padding-right: 10px; position: relative; z-index: 1;}
以上是主要的代碼,有幾點需要注意:
- 利用rgba實現有相容性的問題,所以採用兩層覆蓋的方法
- float元素與position:absolute元素平級時,當絕對位置沒有指定top/left時,float會在絕對位置元素前面出現
- 絕對位置元素當不指定top/left時,則相對於offsetParent內容區定位(不同瀏覽器有差異);當指定top/left時,則相對於offsetParent的margin負邊距定位
- inline-block元素間空隙問題,除了可以刪除html中的空格外,也可以設定其word-spacing為負數
- z-index只適用新的層疊上下文,建立新的層疊內容相關的屬性有絕對/相對定位及一些css3屬性。故本文在用z-index時,把元素設為了相對定位
css實現純文字內容元素透明背景(相容IE6)