Home > Web Front-end > HTML Tutorial > The style is still wrong after the html is cleared of floats. . How to break, solve_html/css_WEB-ITnose

The style is still wrong after the html is cleared of floats. . How to break, solve_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-24 12:23:38
Original
1426 people have browsed it

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的哪个图片的。。

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><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></head><body><div class="right clearfix">    	<div class="top">        	<ul class="clearfix">            	<li>夜空中最亮的星 |</li>                <li>送别 |</li>                <li>没有什么不同 |</li>                        </ul>                        </div>        <div class="bott">        	<ul>        	<li><img src="img/1.jpg" alt="tup1"></li>            <li><img src="img/2.jpg" alt="tup2"></li>            <li><img src="img/3.jpg" alt="tup3"></li>            <li><img src="img/4.jpg" alt="tup4"></li>            <li><img src="img/5.jpg" alt="tup5"></li>            <li><img src="img/6.jpg" alt="tup6"></li>            <li><img src="img/7.jpg" alt="tup7"></li>            <li><img src="img/10.jpg" alt="tup10"></li>            <li><img src="img/15.jpg" alt="tup15"></li>        	</ul>        </div></div></body></html>
Copy after login
Copy after login

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><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></head><body><div class="right clearfix">    	<div class="top">        	<ul class="clearfix">            	<li>夜空中最亮的星 |</li>                <li>送别 |</li>                <li>没有什么不同 |</li>                        </ul>                        </div>        <div class="bott">        	<ul>        	<li><img src="img/1.jpg" alt="tup1"></li>            <li><img src="img/2.jpg" alt="tup2"></li>            <li><img src="img/3.jpg" alt="tup3"></li>            <li><img src="img/4.jpg" alt="tup4"></li>            <li><img src="img/5.jpg" alt="tup5"></li>            <li><img src="img/6.jpg" alt="tup6"></li>            <li><img src="img/7.jpg" alt="tup7"></li>            <li><img src="img/10.jpg" alt="tup10"></li>            <li><img src="img/15.jpg" alt="tup15"></li>        	</ul>        </div></div></body></html>
Copy after login
Copy after login


我粘贴楼主的代码,显示了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

  •             

 
            

  



I have also tried this, no change. .

When you want the child box to float, it is best to set the parent box to float so that they are at the same level, so that the size of the parent box will change accordingly.

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

It’s you Is the post incomplete, or is this what you wrote?
Let me say two things about this
One is irrelevant }
Two, your content is wrong
content: ".";
I tried it and it worked fine. You can try again.
The code is yours.

No: What editor is yours? I don’t want to highlight such low-level errors.

No: What editor do you have? You don’t even highlight such low-level errors

It’s just me being careless. . I use Dreamweaver

When you want the child box to float, it is best to set the parent box to float so that they are at the same level, so that the size of the parent box will change accordingly,

That makes sense. . . I learned a trick, thank you very much

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template