(原)前端知识杂烩(css系列)

更新于 20170316

 

1. css hack

1 .pad{
2     padding:17px 0 0 17px;  /* 普通写法 */ 
3     *padding:17px 0 0 17px; /* *为IE7   *+html css()为IE7 */
4     _padding:17px 0 0 17px;  /*  _为IE6  *html css()为IE6 */
5 }

 

2. css 设置圆角

1 .radius{
2     -moz-border-radius: 100px;
3     -webkit-border-radius: 100px;
4     border-radius:100px;
5 }

 

3. css  盒子阴影   (x,y,阴影模糊度,阴影颜色)

1 .shadow{
2     -moz-box-shadow: 3px 3px 4px #fff;
3     -webkit-box-shadow: 3px 3px 4px #fff;
4     box-shadow: 3px 3px 4px #fff; 
5     filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=3px, OffY=3px, Color='#ffffff');  /* 盒子阴影 IE6,IE7 */
6     -ms-filter: "progid:DXImageTransform.Microsoft.dropshadow(OffX=3px, OffY=3px, Color='#ffffff')"; /* 盒子阴影 IE8 */
7 }

 

4. css 透明度

1 .lucency{
2     filter:alpha(opacity=80);
3     opacity:0.8;    
4 }

 

5. css 文本超出范围省略号代替 ( 块级元素,强制单行,强制指定行数)

/* 超出一行 */
 .over{
     overflow:hidden;
     white-space:nowrap;
     text-overflow:ellipsis;
 }

/* 超出两行,省略号  */
.over2{
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

 

6. css 设置背景透明

1 .lucencyBg{
2     background-color:transparent;
3 }

 

7. css 文字中间划横线效果

1 .txtDec{
2     text-decoration:line-through;
3 }

 

8. css 背景图片定位  (通常为负数)

1 .posBg{
2     background-position:x y;
3 }

 

9.  css 下拉框去掉三角形

1 .selectStyle{
2     appearance:none;
3     -moz-appearance:none;
4     -webkit-appearance:none;
5 }

 

10. css 输入框没有选中效果

1 .inp{
2     outline:none;
3 }

 

11. css 禁止页面图片拖曳 ( body )

1 body{
2     oncontextmenu="return false" ondragstart="return false"  tstart="return false"
3 }

 

12. css 防止点击出现透明背景问题

1 .colorBg{
2     -webkit-tap-highlight-color:rgba(0,0,0,0);
3 }

 

13. css 未知宽度水平居中 相对浮动

1 .unknow_width_center1 {position:relative; left:50%; float:left;}
2 .unknow_width_center1 li {position:relative; right:50%; z-index:2; float:left;}

 

14. css 容器内完全居中(垂直 & 水平)

1 .parent{ position:relative; width:300px; height:300px; margin:0 auto;}
2 .child{ position:absolute; left:0; right:0; bottom:0; top:0; width:50px; height:50px; overflow:auto; margin:auto;}

 

15. css 容器内文字垂直居中

1 .outer { display:table; width:578px; overflow:hidden;}
2 .middle {display:table-cell; vertical-align:middle;}

1 /*下面的CSS是针对IE7,IE6*/
2 <!--[if lte IE 7]>
3 <style>
4 .outer{position:relative;}
5 .middle{position: absolute; top: 50%;}
6 .inner{position: relative; top:-50%}
7 </style> 
8 <![endif]-->

 

16. css  textarea 输入框/输入区域不可随意拖动大小

1 .textarea{ resize:none; }

 

17. css radio / checkbox 选中样式设置(推荐用在移动端,pc端未经测试)

 1 input[type=radio]{
 2     -webkit-appearance: none;
 3     appearance: none;
 4     width:15px;
 5     height:15px;
 6     margin-top:-2px;
 7     margin-left:3px;
 8     cursor: pointer;
 9     vertical-align:middle;
10     -webkit-border-radius:15px;
11     -moz-border-radius:15px;
12     border-radius:15px;
13     border:1px solid #e29452;
14     background-color:#fff;
15 }
16 input[type=radio]:checked::after { 17 content: url(../images/check.png); 18 margin-left:1px; 19 }

如图:

 

18. css 鼠标移上图片,图片放大 

.fouce{width:300px;height:300px;overflow:hidden;}
.fouce>img{
    width:100%;height:100%;
    -webkit-transition:all 1s; 
    -moz-transition:all 1s; 
    -o-transition:all 1s; 
    }
.fouce:hover img{
    -webkit-transition:all 1s; 
    -moz-transition:all 1s; 
    -o-transition:all 1s; 
    -moz-transform:scale(1.2,1.2);  
    -webkit-transform:scale(1.2,1.2);  
    -o-transform:scale(1.2,1.2);  
}

然后, 在需要放大的 div 中添加 fouce classname 即可

 

19. css 三角形(下拉框或者对话框总会用到三角形吧,不用css3就可以搞定小三角形)

.border{
    position: absolute;
    left: 31px;
    top: -8px;
    display: block;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid #FFFEC6;    
}

 

20. css 针对不同的移动设备的方案(哪个不同写哪个)

@media (device-height:480px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone4/4s */

    .prize_round{  width: 70%;top: 8%;margin-left: -33%;}

}

@media (device-height:568px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone5 */

    .prize_round{  width: 78%;top: 9%;margin-left: -39%;}

}


@media (device-height:667px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 */

    .prize_round{  width: 80%;top: 8%;margin-left: -40%;}

}

@media (device-height:736px) and (-webkit-min-device-pixel-ratio:2){/* 兼容iphone6 Plus */

   .prize_round{  width: 82%;top: 8%;margin-left: -41%;}

}

 

21. css  移动端横屏 & 竖屏 样式

//竖屏时使用的样式
@media all and (orientation:portrait) {
.css{}
}

//横屏时使用的样式
@media all and (orientation:landscape) {
.css{}
}

 

22. css  table 边框

.order_table{
    width: 100%;
    border-collapse:collapse;
    border:solid 1px #e6e6e6;
}

.order_table tr td{
    border: solid #e6e6e6;
    border-width:0px 1px 1px 0px;
}

如图 

 

23. 文字第一行缩进两个字符

.txt p{
    text-indent: 2em;
}

 

posted @ 2016-01-05 14:35  Microhuu  阅读(562)  评论(2编辑  收藏  举报