解决CSS margin-top在火狐下失效问题

开发 前端
这里向大家描述一下CSS margin-top在火狐下失效的解决方法,margin-top属性在火狐及IE下面的表现有的时候是不一样的,在火狐下面可以实现自己定义的效果但是到了IE下面却成了双倍的像素。

margin-top属性在火狐及IE下面的表现有的时候是不一样的,这里和大家分享一下CSS margin-top在火狐下失效的方法,在火狐下margin-top很多时候都会失效,解决这个问题的办法就是在CSS里面加入:float:left;display:inline;请看下文详细介绍。

解决CSS margin-top在火狐下失效的方法

margin-top属性在火狐及IE下面的表现有的时候是不一样的,在火狐下面可以实现自己定义的效果但是到了IE下面却成了双倍的像素,在火狐下margin-top很多时候都会失效,解决这个问题的办法就是在CSS里面加入:float:left;display:inline;

例子:

  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"  
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <metahttp-equivmetahttp-equiv="Content-Type"
  6. content="text/html;charset=gb2312"/> 
  7. <title>无标题文档</title> 
  8. <styletypestyletype="text/CSS"> 
  9. <!--  
  10. .w{  
  11. background-color:#000099;  
  12. padding:0px;  
  13. height:100px;  
  14. width:200px;  
  15. margin-top:20px;  
  16. margin-left:30px;  
  17. }  
  18. --> 
  19. </style> 
  20. </head> 
  21. <body> 
  22. <divstyledivstyle="background-color:#006666;
  23. width:400px;height:200px;clear:both;"> 
  24. <divclassdivclass="w"></div> 
  25. </div> 
  26. </body> 
  27. </html> 
  28.  

 解决后:

  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"  
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5.  
  6. <metahttp-equivmetahttp-equiv="Content-Type"
  7. content="text/html;charset=gb2312"/> 
  8. <title>无标题文档</title> 
  9. <styletypestyletype="text/CSS"> 
  10. <!--  
  11. .w{  
  12. background-color:#000099;  
  13. padding:0px;  
  14. height:100px;  
  15. width:200px;  
  16. margin-top:20px;  
  17. margin-left:30px;  
  18. float:left;display:inline;  
  19. }  
  20. --> 
  21. </style> 
  22. </head> 
  23. <body> 
  24. <divstyledivstyle="background-color:#006666;
  25. width:400px;height:200px;clear:both;"> 
  26. <divclassdivclass="w"></div> 
  27. </div> 
  28. </body> 
  29. </html> 
  30.  

 原文出处:http://hi.baidu.com/yimeng3025/modify/blog/5267ce3095970211eac4af16

【编辑推荐】

  1. Chroma属性实现CSS滤镜透明效果
  2. CSS Sprites图片切割术与图片优化
  3. CSS中DIV弹出层问题解决方案
  4. CSS规范化命名通用命名规则
  5. CSS分栏布局的两种方法:绝对定位和浮动
责任编辑:佚名 来源: hi.baidu.com
相关推荐

2010-08-26 13:54:33

Firefoxmargin-top

2010-09-13 17:15:59

margin-top

2010-08-31 09:19:46

margin-topFirefox

2010-08-31 09:13:00

margin-top

2010-08-31 09:06:25

Firefox margin-top

2010-08-25 10:46:53

margin-topCSS

2010-08-25 09:48:25

CSSmargin

2010-08-25 10:05:03

margin-top

2010-08-30 16:53:14

FirefoxIE8margin-top

2010-09-02 15:18:42

CSSASP.NET

2010-08-26 14:00:28

CSSmargin

2010-08-26 12:59:29

marginCSS

2010-08-25 11:23:31

IE6margin

2010-08-25 10:21:49

CSSmargin

2010-08-25 09:30:56

marginCSS

2010-08-30 12:54:59

CSSmargin

2010-08-26 10:08:50

CSSmargin

2023-03-06 21:43:29

token失效服务器

2010-08-20 13:46:10

IEFirefoxCSS

2010-09-08 08:49:56

margin:0autCSS
点赞
收藏

51CTO技术栈公众号