Heim  >  Artikel  >  Web-Frontend  >  li元素右浮动会出现换行_html/css_WEB-ITnose

li元素右浮动会出现换行_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:31:171250Durchsuche

li元素右浮动会出现换行:
一般情况下想让块级元素在一行显示,可以为元素施加浮动,但是有时候表现却并非如人愿,会出现换行的情况。
看如下代码:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">*{  padding:0;  margin:0;}#box{  width:250px;  list-style:none;}#box li{  width:100px;  height:30px;  background-color:green;}</style></head><body><ul id="box">  <li></li>  <li style="float:right"></li></ul></body></html>

以上代码中,尽管右边的li采用了右浮动,但是还是出现了换行现象,下面就介绍一下解决方案:
解决方案:
在左边的li元素也采用浮动,代码修改如下:

<ul id="box">  <li style="float:left"></li>  <li style="float:right"></li></ul>

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=9738

更多内容可以参阅:http://www.softwhy.com/divcss/

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn