css中清除浮動的例子

來源:互聯網
上載者:User

左圖右文形式,這是手機頁面經常碰到的一種情況,記得第一次寫的時候,好糾結,因為不會,排版的時候,老是寫不出和效果圖一樣的效果,最近發現,原來是使用了float元素,導致這個頁面最外層的標籤撐不起來(手機頁面一般不將寬度和高度定死),這個時候,突然想起可以清除浮動  clear:both;

下面放出代碼

css:

.cell-content {display: block;margin-bottom: 10px;background: #eee;}
.cell-content:hover,.cell-footer ul li a:hover {color: red}
.cell-content img {width: 20%;float: left;padding: 3% 3% 0 3%;}
.cell-title {width: 71%;padding-top: 4%;font-size: 16px;cursor: pointer;}
.ellipsis {overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}
.more-ellipsis {display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;}
.cell-content-del {float: right; margin-right: 3%;width: 71%;margin-top: 2%;font-size: 14px;color: #333;line-height: 1.5;}
.clh {padding-bottom: 3%;clear: both;}

html:

<a href="javascript:;" class="cell-content">
 <img src="images/product_pic2.png" alt="">
 <p class="cell-title ellipsis">浙江衢州橘子浙江衢州橘子浙江衢州橘子浙江衢州橘子浙江衢州橘子</p>
 <div class="cell-content-del more-ellipsis">浙江味美味美味美味美味美味美味美味美味美味美味美味美味美味美味味美味美味州橘子</div>
 <p class="clh"></p>
 </a>
在使用float的標籤下方,添加一個標籤,清除之前浮動的影響(最外層標標籤無法撐開)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.