Home  >  Article  >  Web Front-end  >  Common browser compatibility issues in html and css

Common browser compatibility issues in html and css

小云云
小云云Original
2017-11-16 17:01:163533browse

We will definitely use css in html development, but sometimes development is not as smooth as we thought. For example, common browser compatibility issues in html and css, then for this browser compatibility In this section, we will teach you how to solve the problem.

1. Centering problem

The content in the div is centered by IE by default, and left-aligned by FF by default. You can try adding code:

margin: 0 auto;

2. Height problem

For two divs arranged one above the other or nested, the height of the div above is set. If the actual content in the div is greater than the set height, the two divs will overlap in FF; but In IE, the div below will automatically make space for the div above. So in order to avoid overlapping layers, the height must be controlled appropriately, or you may simply not write the height and let it adjust automatically. A better method is height:100%. ;But when the first-level elements in this div are all floated, you need to add an empty div with a sunken bottom at the end of the div block and before closing. The corresponding CSS is:

float_bottom {clear:both;height:0px;font-size:0px;padding:0;margin:0;border:0;line-height:0px;overflow:hidden;}

3. clear: both;

If you don’t want to be affected by float, just write clear: both;

4. Double distance generated by IE floating margin

01#box {
 float:left;
width:100px;
 margin:0 0 0 100px; //这种情况之下IE会产生200px的距离
display:inline; //使浮动忽略
}

5. Padding problem

After FF sets padding, div will increase height and width, but IE will not (* standard XHTML1.0 definition dtd seems to be consistent) height control Appropriate, or try to use height:100%; use padding to reduce the width. But according to actual experience, generally the padding of FF and IE will not be much different. The actual width of the div = width + padding, so write the full width and padding, width of the div. Define padding as the actual desired width.

6. Problems with padding and marign on the y-axis when divs are nested

The distance from the child div to the parent div on the y-axis in FF is parent padding + child marign

In IE, the distance between the child div on the y-axis and the parent div is the larger of the parent padding and the child margin

In FF, when the parent padding=0 and border=0 on the y-axis, the child div The distance to the parent div is 0, and the child margin acts outside the parent div

7. Foolish solution techniques for padding, margin, height, width

Note that this is a technique , not a method:

Write the standard header

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=” 
高尽量用padding,慎用margin,height尽量补上100%,父级height有定值子级height不用100%,子级全为浮动时底部补个空clear:both的div宽尽量用margin,慎用padding,width算准实际要的减去padding

8. List class

1. The ul tag has a padding value by default in FF, but in In IE, only margin has a value

First define ul {margin:0;padding:0;}

2. Indentation problem of ul and ol lists When eliminating the indentation of ul, ol and other lists , the style should be written as: {list-style:none;margin:0px;padding:0px;}

9. Display class (display:block,inline)

1. Two elements, display:block and inline

display:block; //Inline elements can be simulated as block elements

display:inline; //Achieve the effect of being arranged in the same line

display:table; //for FF, simulate the effect of table

display:block block element, the characteristics of the element are:

Always start on a new line; Height, line height, and top and bottom margins are all controllable; the width defaults to 100% of its container, unless a width is set

dc6dce4a544fdca2df29d5ac0ea9906b, e388a4556c0f65e1904146cc1a846bee, 4a249f0d628e2318394fd9b75b4636b1 , ff9c23ada1bcecdd1a0fb5d5a0f18437, ff6d136ddc5fdfeffaf53ff6ee95f185 and 25edfb22a4f469ecb59f1190150159c6 are examples of block elements

display:inline is to display the element as an inline element. The characteristics of the element are: it is on the same line as other elements; The height, line height and top and bottom margins cannot be changed; the width is the width of its text or image and cannot be changed. 45a2772a6b6107b401db3c9b82c049c2, 3499910bf9dac5ae3c52d5ede7383485, 2e1cf0710519d5598b1f0f14c36ba674, d5fd7aea971a85678ba271703566ebfd, a1f02c36ba31691bcfe87b2722de723b, 8e99a69fbe029cd4e2b854e244eab143 and 907fae80ddef53131f3292ee4f81644b are examples of inline elements

2. Mouse finger shape Display

all use standard writing cursor: pointer;

10, background, picture category

1. Background display problem

Pay attention to all the width and height attributes

2. Background transparency problem

IE: filter: progid: DXImageTransform.Microsoft.Alpha(style=0,opacity=60);

IE: filter: alpha(opacity=10);

FF: opacity:0.6;

FF: -moz-opacity:0.10;

The best two Write all of them, and put the opacity attribute below

11. Implementation of min-height minimum height (compatible with IE6, IE7, FF)

The function is: when When the content of the container is small, a minimum height can be maintained to avoid damaging the layout or UI design effect. When the content in the container increases, the container can automatically stretch to adapt to the changes in content.

#mrjin {
               background:#ccc;
               min-height:100px;
               height:auto !important;
                height:100px;
               overflow:visible;
}

12. The famous Meyer Reset (reset)

html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6,p, blockquote, pre,a, abbr,
 acronym, address, big, cite, code,del, dfn, em, font, img, ins, kbd, q, s, samp,small, strike, 
strong, sub, sup, tt, var,dl, dt, dd, ol, ul, li,fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td
{ 
  margin: 0; 
  padding: 0; 
  border: 0; 
  outline: 0; 
  font-weight: inherit; 
  font-style: inherit; 
  font-size: 100%; 
  font-family: inherit; 
  vertical-align: baseline; 
  } 
  :focus { 
   outline: 0; 
  } 
  body { 
   line-height: 1; 
   color: black; 
   background: white; 
  } 
  ol, ul { 
   list-style: none; 
  } 
  table { 
   border-collapse: separate; 
   border-spacing: 0; 
  } 
  caption, th, td { 
   text-align: left; 
   font-weight: normal; 
  } 
blockquote:before, blockquote:after, 
q:before, q:after { 
  content: ""; 
} 
blockquote, q { 
  quotes: "" ""; 
}

13. Cross-browser CSS transparency

.transparent { 
  opacity: 0.7; 
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
  filter: alpha(opacity=70); 
  -moz-opacity: 0.7; 
  -khtml-opacity: 0.7;

14. Text shadow ( CSS3)

.text { text-shadow: 1px 1px 1px #666; filter: Shadow(Color=#666666, Direction=135, Strength=5); }

15, Box shadow (CSS3)

box { box-shadow: 5px 5px 5px #666;  -moz-box-shadow: 5px 5px 5px #666;  -webkit-box-shadow: 5px 5px 5px #666; }

16, Sticky Footer (let the footer always dock at the bottom of the page, rather than based on the absolute position)

<div id="wrap"> 

 <div id="main" class="clearfix"></div> 

</div> 

  <div id="footer"> </div>

CSS:

 * { margin:0; padding:0; }  

 html, body, #wrap { height: 100%; } 

 body > #wrap {height: auto; min-height: 100%;} 

 #main { padding-bottom: 150px; }   

 #footer { 

  position: relative; 

     margin-top: -150px;  

     height: 150px; 

   clear:both;}  

  .clearfix:after {content: "."; 

     display: block; 

         height: 0; 

         clear: both; 

         visibility: hidden;} 

  .clearfix {display: inline-block;} 

* html .clearfix { height: 1%;} 

 .clearfix {display: block;}

17. How to remove the inherited html and body background color/background image from the iframe element embedded page

iframe元素的功能是在一个文档里内嵌一个文档,创建一个浮动的帧。内嵌文档时一个完整的页面,有HTML,BODY等属性。这样遇到了一个问题,如果样式表中对BODY定义过背景色/背景图片,那么内嵌文档将全部继承过来。所以如何去掉背景色和背景图片:

【1】去掉背景色:filter:Chroma(Color=white);

举例:

<iframe width="100%" height="400" marginwidth="0" marginheight="0"
 scrolling="no" frameborder="0" leftmargin="0" topmargin="0" style="filter:Chroma(Color=white);" ></iframe>

【2】去掉背景图片:

举例:

<iframe width="100%" height="400" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" leftmargin="0"
 topmargin="0" style="filter:Chroma(Color=white);" allowTransparency="true" ></iframe>

注意:内嵌页面同时也要增加BODY属性:

<body bgcolor="transparent" style=&#39;background:transparent&#39;>

18、为什么web标准中无法设置IE浏览器滚动条颜色了?

原来样式设置:

body{2scrollbar-face-color:#f6f6f6; 3scrollbar-highlight-color:#fff;
 4scrollbar-shadow-color:#eeeeee; 5scrollbar-3dlight-color:#eeeeee;
  6scrollbar-arrow-color:#000; 7scrollbar-track-color:#fff; 8scrollbar-darkshadow-color:#fff; }

解决办法是将body换成html。

19、为什么中火狐浏览器下文本无法撑开容器的高度?

标准浏览器中固定高度值的容器是不会象IE6里那样被撑开的,那我又想固定高度,又想能被撑开需要怎样设置呢?办法就是去掉height设置min-height:200px; 这里为了照顾不认识min-height的IE6 可以这样定义:

div { height:auto!important; height:200px; min-height:200px; }

20、如何定义1px左右高度的容器?
 

IE6下这个问题是因为默认的行高造成的,解决的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px
 

21、怎么样才能让层显示在FLASH之上呢?
 

解决的办法是给FLASH设置透明:

<a href="http://www.chinaz.com/">:</a>
<pre line="1">
<param name="wmode" value="transparent" />

22、怎样使一个div层居中于浏览器中?

div {
position:absolute;
top:50%;
left:50%;
margin:-100px 0 0 -100px;
width:200px;
height:200px;
border:1px solid red;
}

23、怎样使div背景透明?

首先,需要这两个层都是兄弟关系,其次,这两个层都需要绝对定位。举个例子:

 body {
              font:normal 12px/30px Verdana;   }
       #test {
              position:relative;
              width:400px;
              height:50px;
                     }
       #inner {
              z-index:2;
              position:absolute;
              top:10px;
              left:10px;
              width:380px;
              height:30px;
              color:#003;
       font-weight:bold;
              text-align:center;
       }
       #transbox {
              z-index:1;
              position:absolute;
              top:0px;
              left:0px;
              width:400px;
              height:50px;
        background:#eef;
border:1px solid #a00;
              filter:alpha(opacity=40);
              -moz-opacity:0.4;
        opacity:0.4;
       }

e388a4556c0f65e1904146cc1a846bee这里很多的文字,这里很多的文字,这里很多的文字,这里很多的文字,94b3e26ee717c64999d7867364b1b4a3

24、怎样去掉选中时的虚线框?

利用onfocus="this.blur();"例如:dd8b186726c0b45d7b00732cf0e1fe3e测试5db79b134e9f6b82c0b36e0489ee08ed

25、ie6下png背景显示问题?

针对ie6下png背景显示问题,CSS中可以这样解决:

_background:none;_filter:progid
:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=crop, src=’http://www.0351zhuangxiu.com/uploads/images/bj.jpg’);

26、文字与表单对齐方法?
 

设置表单元素第一字体为Tahoma(Verdana系列也可),并设置vertical-align:middle.建设大家把这个约定写入CSS RESET中,能减小很多麻烦:

body,button,input,select,textarea{font:12px/1.5 tahoma,arial,sans-serif; vertical-align:middle}


27、optgroup标签的用法?

optgroup标签,鲜为人知,它对提升选择表单用户体验很有帮助。就是可以在有很多选项时,对这些选项分组:例子:

<select id="selectId">
<optgroup label="GROUP ONE">
<option value="1">one select</option>
<option value="2">two select</option>
</optgroup>
<optgroup label="GROUP TWO">
<option value="3">three select</option>
<option value="4">four select</option>
</optgroup>
</select>

28、文字与图片垂直居中对齐方法?

为图片与文字的共同父元素所有的后代元素定义*{vertical-align:middle};例如:

<p>我要的坚强<img src="i/image.gif" /></p>

只需定义p*{vertical-align:middle}即可使文字与图片同行垂直居中.

29、文章标题列表中日期居右显示的两种方法?

方法A相对方法B省资源,但比方法B要多写两句代码,使用时请视情况而定:

方法A:

<p>这是文章标题<span>2010-10-10</span></p>

然后定义p和span的样式:

p{ position:relative}
p span{ position:absolute; right:0}

方法B:

<p><span>2010-10-10</span>这是文章标题</p>

然后定义span右浮动:

p span{float:right}

30、ie6下max/min-width/height实现?
 

ie6下max/min-width/height实现,_width: expression_r(this.width >600 ? “600px” : true);,height同理.
 

31、空白外边距互相叠加的问题?

一般通过添加透明边框或者1px的内边距避免;

其一,为外围元素定义透明边框.具体到本例,即在样式div中加入border:1px solid transparent;

其二,为外围元素定义内边距填充..具体到本例,即在样式div中加入padding:1px;

例如:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>空白边距叠加demo@Mr.Think</title>
<style>
body{width:300px; font-family:&#39;微软雅黑&#39;; font-size:1em; text-indent:10px; line-height:1.25}
div{background:#a40000;margin:10px}
div p{background:#eee;margin:15px}
</style>
</head>
<body>
<div><p>空白边距叠加demo@Mr.Think</p></div>
</body>
</html>

32、网页设计中的默认字体

font: 12px/1.5 Tahoma, Helvetica, Arial, sans-serif;

说明:line-height采用1.5, 也就是18px. 这是淘宝视觉规范中定义的行高,对于12px字体,这个行高看起来很舒服。font-family默认采用Tahoma. Tahoma是英文Windows操作系统的默认字体,这个字体比较均衡,显示中英文混排很不错,是经久耐看的一款字体。

33、浏览器兼容——常用的css hack

/*第一种*/
.title{ height:200px;

    *height:200px;

    _height:200px; }

/*第二种*/
.title{ height:200px;

    *height:200px !important;

    *height:200px; }

/*第三种*/
.title{ height:200px; }

    *html.title{ height:200px;}

    *+html.title{ height:200px;}

虽然篇幅有点长,但是这里面的内容对我们真的很有用,大家赶紧收藏起来吧。

相关教程:

用html5和css3写出登录页面教程

CSS如何实现文字颜色渐变的实例

CSS3中关于“渐变”兼容性解决方案详解

The above is the detailed content of Common browser compatibility issues in html and css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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