实现一个自适应网页用到的css知识

1 div导致父级高度没有变化是应该子元素设置了float:left等

2 div元素居中 text-align:center; margin-left: auto;margin-right:

3 大小随窗体变化一定要设置成百分比(width:98% )且用到 @media screen and (min- 280px) and (max- 380px){}

4 网页两变一定要留一定(固定)距离可以设置 左右各15像素( padding:0 15px; ) ,padding是向内占位,margin是向外占位,设置的宽度不包括margin

5 div脱离文档设置 position:relative/absolute

6 设置边框 border-style:solid; border-1px; border-color:#000;

7 背景透明度和背景颜色 background-color:#000;opacity:0.5;

8 背景图片background:url('/images4/bg.jpg');

9 opacity会被继承,会影响后面子元素的透明度,解决方案 建一个同级别的div,然后定位到上面,看似一样。

这个问题解决可以参考https://www.janecc.com/css3-opacity-inherit-resolve.html和https://my.oschina.net/xiangduole8/blog/291146

10 after真的很有用

这个来源:http://www.cnblogs.com/losesea/archive/2012/12/20/2825763.html

 CSS中存在一些比较特殊的属性,称之为伪类,它们之中最常用的就是定义链接的伪:link,:visited,:hover,:active等。

    除了它们,还有一些不被常使用的伪类,有:focus,:first-child,:lang等。

    而且CSS里不光有伪类,还有伪元素,比如::first-letter,:first-line,:before和:after。

    ?本文中其它伪元素暂且不表,单说:after伪元素。

    after顾名思义是在元素后面的意思,实质是在元素之后添加内容。

    这个伪元素允许制作人员在元素内容的最后面插入生成内容,需要和content属性一起使用,设置在对象后发生的内容。默认地,这个伪元素是inline行内元素,不过可以使用属性 display 改变这一点。  

    所有主流浏览器都支持 :after 伪元素,但对于IE来说,只有IE8以上版本支持。  

    下面举个例子,在CSS代码中插入:

<style type="text/css"> 
  h1:after {content:url(logo.gif)}  
</style>


    Html:

<h1>标题内容</h1>


    在显示时,标题内容后会插入一张图片。这就是伪元素:after的作用。

    伪元素:after另外一个常用的作用在原来的文章中曾经提到过,有些同学可能还记得,那就是清除浮动。

    在CSS中加入带有CSS伪类:after的内容:    

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


    然后在外面的Div容器box中引用这个class,比如:  

<div id="box" class="clear">
  ……
  ……
  </div>
 

   自我小结

/*这个效果很好,设置了元素高度,要借鉴*/
.check-main:after, .f-cbli li:after {
    display: block;
    clear: both;
    visibility: hidden;
    height: 0;
    overflow: hidden;
    content: ".";
}

11  zoom

 zoom这个特性是IE特有的属性。

  zoom:1;一般是拿来解决IE6的子元素浮动时候父元素不随着自动扩大的问题,功能相当于overflow:auto,同样也可以用height:1%来代替zoom:1。所以一般要在浮动元素的父元素加上overflow:auto;zoom:1;。这样,子元素浮动,父元素再也不会不自动跟子元素扩大了。
 
详细解说:http://www.cnblogs.com/top5/archive/2011/07/11/2103343.html
 
 
12 容易忽视的
.b-input input[type="text"],input[type="text"],input[type="password"]{ height:30px;line-height: 30px; padding:0 3px;border:1px solid #d7d7d7; }
css 实现小三角形

.triangledown
{
height:0px; 0px;
border:10px solid #000; border-color:#f00 transparent transparent transparent;
border:10px solid #000; border-color:#f00 transparent transparent; border-style:solid solid dashed dashed;
line-height:0px;

}
.triangleup
{padding-bottom: 5px;
height:0px; 0px;
border:10px solid #000; border-color:transparent transparent #f00 transparent ;
border:10px solid #000; border-color: transparent transparent #f00; border-style:solid solid dashed dashed;
line-height:0px;
}

/*间隔*/四周空隙
.searchmargin
{
padding:10px 10px 10px 20px;
}

 padding与margin有区别的
margin不计算在里面,padding计算在里面
原文地址:https://www.cnblogs.com/xiaohuasan/p/6004345.html