当前位置:Gxlcms > html代码 > html清除浮动后样式依旧错误。。怎么破,求解_html/css_WEB-ITnose

html清除浮动后样式依旧错误。。怎么破,求解_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:43人阅读

html代码如下:



  • 夜空中最亮的星 |

  • 送别 |

  • 没有什么不同 |








  • tup1

  • tup2

  • tup3

  • tup4

  • tup5

  • tup6

  • tup7

  • tup10

  • tup15












css样式代码如下:

.right{
float:right;

}

.right .top{
width:750px;
height:60px;
line-height:60px;
border:2px solid #F66;
margin-bottom:15px;

}

.top ul{
padding-left:15px;

}

.top ul li{
float:left;
width:240px;
margin-bottom:15px;
border:1px solid #3CC;



}

.right .bott{

width:750px;
border:2px dashed #F3C;
padding-top:20px;

}
.bott ul{
margin-bottom:20px;
}

.bott ul li{
float:left;

margin-bottom:20px;
margin-left:20px;

height:220px;
width:220px;

}
.bott ul li img{

width:220px;
height:220px;

}

.footer{
margin:auto 30px;
background:#3F6;


}


.clearfix:after{
content".";
display:block;
height:0px;
clear:both;
visibility:hidden;

显示的结果是我右边部分的框压根就没有框住所有的li。。。图片传不上。。郁闷


回复讨论(解决方案)



图片如下。。红色的部分是我right部分的边框,本来是要套住所有li的哪个图片的。。

我觉得应该是清除浮动的关系,可是我都清浮动了,,为什么还是没有效果呢。。坐等解决啊

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><style type="text/css">.right{float:right;}.right .top{width:750px;height:60px;line-height:60px;border:2px solid #F66;margin-bottom:15px;}.top ul{padding-left:15px;}.top ul li{float:left;width:240px;margin-bottom:15px;border:1px solid #3CC;}.bott{float:left;width:750px;border:2px dashed #F3C;}.bott ul{float:left;margin:0;padding:0;list-style:none;background-color:#f00;}.bott li{float:left;margin:0;padding:10px;height:220px;width:220px;background-color:#ddd;}.bott li img{width:220px;height:220px;background-color:#fff;border:1px solid #ccc;display:block;}.footer{margin:auto 30px;background:#3F6;}.clearfix:after{content".";display:block;height:0px;clear:both;visibility:hidden;}</style><div class="right clearfix">
  2. <div class="top">
  3. <ul class="clearfix">
  4. <li>夜空中最亮的星 |</li> <li>送别 |</li> <li>没有什么不同 |</li> </ul> </div> <div class="bott">
  5. <ul>
  6. <li><img src="https://www.gxlcms.com/img/1.jpg" alt="tup1"></li> <li><img src="https://www.gxlcms.com/img/2.jpg" alt="tup2"></li> <li><img src="https://www.gxlcms.com/img/3.jpg" alt="tup3"></li> <li><img src="https://www.gxlcms.com/img/4.jpg" alt="tup4"></li> <li><img src="https://www.gxlcms.com/img/5.jpg" alt="tup5"></li> <li><img src="https://www.gxlcms.com/img/6.jpg" alt="tup6"></li> <li><img src="https://www.gxlcms.com/img/7.jpg" alt="tup7"></li> <li><img src="https://www.gxlcms.com/img/10.jpg" alt="tup10"></li> <li><img src="https://www.gxlcms.com/img/15.jpg" alt="tup15"></li>
  7. </ul> </div></div>

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><style type="text/css">.right{float:right;}.right .top{width:750px;height:60px;line-height:60px;border:2px solid #F66;margin-bottom:15px;}.top ul{padding-left:15px;}.top ul li{float:left;width:240px;margin-bottom:15px;border:1px solid #3CC;}.bott{float:left;width:750px;border:2px dashed #F3C;}.bott ul{float:left;margin:0;padding:0;list-style:none;background-color:#f00;}.bott li{float:left;margin:0;padding:10px;height:220px;width:220px;background-color:#ddd;}.bott li img{width:220px;height:220px;background-color:#fff;border:1px solid #ccc;display:block;}.footer{margin:auto 30px;background:#3F6;}.clearfix:after{content".";display:block;height:0px;clear:both;visibility:hidden;}</style><div class="right clearfix">
  2. <div class="top">
  3. <ul class="clearfix">
  4. <li>夜空中最亮的星 |</li> <li>送别 |</li> <li>没有什么不同 |</li> </ul> </div> <div class="bott">
  5. <ul>
  6. <li><img src="https://www.gxlcms.com/img/1.jpg" alt="tup1"></li> <li><img src="https://www.gxlcms.com/img/2.jpg" alt="tup2"></li> <li><img src="https://www.gxlcms.com/img/3.jpg" alt="tup3"></li> <li><img src="https://www.gxlcms.com/img/4.jpg" alt="tup4"></li> <li><img src="https://www.gxlcms.com/img/5.jpg" alt="tup5"></li> <li><img src="https://www.gxlcms.com/img/6.jpg" alt="tup6"></li> <li><img src="https://www.gxlcms.com/img/7.jpg" alt="tup7"></li> <li><img src="https://www.gxlcms.com/img/10.jpg" alt="tup10"></li> <li><img src="https://www.gxlcms.com/img/15.jpg" alt="tup15"></li>
  7. </ul> </div></div>


我粘贴楼主的代码,显示了li都在right的边框里。。。。仔细看了下代码,没有发现有什么大的变动啊,求赐教。。。

你装个代码比较软件看一看,我改动的css挺多的,删除了元素上的clearfix

你装个代码比较软件看一看,我改动的css挺多的,删除了元素上的clearfix

我试试。。能说下你发现我这代码的主要问题是哪些呢。。clearfix用的地方不对吗


你装个代码比较软件看一看,我改动的css挺多的,删除了元素上的clearfix

我试试。。能说下你发现我这代码的主要问题是哪些呢。。clearfix用的地方不对吗
不要在ul,上用margin,padding



  • tup1

  • tup2

  • tup3

  • tup4

  • tup5

  • tup6

  • tup7

  • tup10

  • tup15




何时用clear:看一看这篇: CSS浮动属性Float详解

何时用clear:看一看这篇: CSS浮动属性Float详解

3q,我去认真看下。。



  • tup1

  • tup2

  • tup3

  • tup4

  • tup5

  • tup6

  • tup7

  • tup10

  • tup15







这个我也试过的,没改变。。

当你想子盒子浮动时,最好也设置父盒子浮动,让它们在同一层次上,,父盒子的大小才会跟着改变,

.clearfix:after{
content".";
display:block;
height:0px;
clear:both;
visibility:hidden;

是你贴的不全呢,还是你写的就这样
针对这个说两点
一没有关的 }
二 你的content 这块写的不对
content:".";
我试了下就没问题了,你可以再试试,
代码 就是你的

是没有:个号 你的是什么编辑器呀这样低级的 错误都不高亮一下

是没有:个号 你的是什么编辑器呀这样低级的 错误都不高亮一下

是我粗心了。。我用的是dreamweaver啊

当你想子盒子浮动时,最好也设置父盒子浮动,让它们在同一层次上,,父盒子的大小才会跟着改变,

很有道理啊。。。学了一招,非常感谢

人气教程排行