css常见的快捷开发代码汇总(长期更新),包括CSS3代码,有一些css效果很顽固,经常会一时找不出解决方案,网络上也有很多的工具和高手提供了具体的浏览器兼容代码,这个页面我今后会经常整理,希望能够帮到重构和正在找这些效果的代码,如果你有更好的实现方案,不妨告诉我,或者你有解决不了的,也不妨告诉我。你想找浏览器兼容写法吗?点CSS浏览器兼容与hack代码(经验汇总,保持最新)

Css背景颜色透明(#ddd)

请参考在线版制作

.liter{
filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#4CDDDDDD', endColorstr='#4CDDDDDD');
}
:root .liter {
filter:none;     /*处理IE9浏览器中的滤镜效果*/
background-color:rgba(221,221,221,0.3);
}

图片垂直居中对齐

第一种:table-cell法

<div class="test_box">
<img src="book.jpg" alt="css常用代码大全" alt="" />
</div>
.test_box {display:table-cell;width:200px;height:200px;vertical-align:middle;text-align:center;
*float:left;*font-family:simsun;*font-size:200px;*line-height:1;
border:1px solid #000000;
}
.test_box img {vertical-align:middle;}

第二种:span法

<div class="test_box">
<span class="hook"></span>
<a href="http://blog.linxz.de/css_book/" target="_blank"><img src="book.jpg" alt="css常用代码大全" alt="" /></a>
</div>
.test_box {width:200px;height:200px;overflow:hidden;text-align:center;font-size:0;border:1px solid #000000;}
.test_box .hook {display:inline-block;width:0;height:100%;overflow:hidden;margin-left:-1px;font-size:0;line-height:0;vertical-align:middle;}
.test_box img {vertical-align:middle;border:0 none;}

css border制作小三角(兼容IE6)

工具请参考小志的在线版

.triangle {display:inline-block;width:0;height:0;overflow:hidden;line-height:0;font-size:0;
vertical-align:middle;
border-right:7px solid #000fff;
border-left:0 none;
border-top:7px solid transparent;
border-bottom:7px solid transparent;
_color:#FF3FFF;
_filter:chroma(color=#FF3FFF);
}

CSS固定在底部

CSS代码

 /*
Sticky Footer Solution
by Steve Hatcher http://stever.ca http://www.cssstickyfooter.com */
* {margin:0;padding:0;} /* must declare 0 margins on everything, also for main layout components use padding, not
vertical margins (top and bottom) to add spacing, else those margins get added to total height
and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {
    overflow:auto;
    padding-bottom: 150px;  /* must be same height as the footer */
}
#footer {
    position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;
}
/*Opera Fix*/
body:before {/* thanks to Maleika (Kohoutec)*/
    content:"";
    height:100%;
    float:left;
    width:0;
    margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}
/* IMPORTANT
You also need to include this conditional style in the  of your HTML file to feed this style to IE 6 and lower and 8 and higher.
<!--[if !IE 7]>
<style type="text/css">
    #wrap {display:table;height:100%}
</style>
< ![endif]-->
*/

html代码

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

纯粹的css固定在底部

#footer {
position:fixed;
left:0px;
bottom:0px;
height:32px;
width:100%;
background:#333;
}
/* IE 6 */
* html #footer {
position:absolute;
top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');
}

CSS包裹内容很长的URL和文本

这个代码片段通过保证文本的包裹元素宽度适应内容的宽度,能够避免很长的文本超出内容区域。

pre {
white-space: pre; /* CSS 2.0 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP Printers */
word-wrap: break-word; /* IE 5+ */
}

css3创造3D文字

text-shadow属性能帮助你只用CSS创造3D文字。

p.threeD{
text-shadow:
-1px 1px 0 #ddd,
-2px 2px 0 #c8c8c8,
-3px 3px 0 #ccc,
-4px 4px 0 #b8b8b8,
-4px 4px 0 #bbb,
0px 1px 1px rgba(0,0,0,.4),
0px 2px 2px rgba(0,0,0,.3),
-1px 3px 3px rgba(0,0,0,.2),
-1px 5px 5px rgba(0,0,0,.1),
-2px 8px 8px rgba(0,0,0,.1),
-2px 13px 13px rgba(0,0,0,.1)
;
}

CSS透明度

div{
opacity: .75; /* Standard: FF gt 1.5, Opera, Safari */
filter: alpha(opacity=75); /* IE lt 8 */
-ms-filter: "alpha(opacity=75)"; /* IE 8 */
-khtml-opacity: .75; /* Safari 1.x */
-moz-opacity: .75; /* FF lt 1.5, Netscape */
}

改变博客中默认选中文本的颜色

::selection {
background: #ffb7b7; /* Safari */
color: #ffffff;
}
::-moz-selection {
background: #ffb7b7; /* Firefox */
color: #ffffff;
}

多重背景图片

#multiple-images {
background: url(image_1.png) top left no-repeat,
url(image_2.png) bottom left no-repeat,
url(image_3.png) bottom right no-repeat;
}

多栏CSS3

使用css3来创建多栏,它可以自适应网页,不兼容IE

#columns-3 {
text-align: justify;
-moz-column-count: 3;
-moz-column-gap: 12px;
-moz-column-rule: 1px solid #c4c8cc;
-webkit-column-count: 3;
-webkit-column-gap: 12px;
-webkit-column-rule: 1px solid #c4c8cc;
}

文本溢出省略

.textoverflow a {
display:block;
width:120px;
margin: 0px 0px 0px 3px;
white-space: nowrap;
overflow: hidden;
float: left;
-o-text-overflow: ellipsis; /* for Opera */
text-overflow: ellipsis; /* for IE */
}
.textoverflow:after{ content: "..."; }/* for Firefox */
@media all and (min-width: 0px){ .textoverflow:after{ content:""; }/* for Opera */ }

让IE9以下的版本支持HTML5

在项目中加入以下JS代码

// html5 shiv

if (!+[1,]) {
(function() {
var tags = [
'article', 'aside', 'details', 'figcaption',
'figure', 'footer', 'header', 'hgroup',
'menu', 'nav', 'section', 'summary',
'time', 'mark', 'audio', 'video'],
i = 0, len = tags.length;
for (; i < len; i++) document.createElement(tags[i]);
})();
}
or
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

PNG32透明(IE6)

主要用来兼容IE6,不建议使用,由于这个css代码比较耗内存。

.some_element {
background: url(image.png);
_background: none;
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.png', sizingMethod='crop');
}

参考文章

http://miyuki.42code.com/2012/02/useful-css-snippets/

http://www.djavupixel.com/development/css-development/master-css3-ultimate-css-code-snippets/

原文链接:css常用代码大全 版权所有,转载时请注明出处,违者必究。
注明出处格式:前端开发博客 (http://caibaojian.com/popular-css-snippets.html)
 
 

CSS Hack代码与浏览兼容总结

关于CSS Hack的东西能少尽量少吧。发现这篇文章我写得太复杂了,所以重新精简了一下,把代码粘贴到jsfiddle上,方面修改代码和维护。

1, IE条件注释法,微软官方推荐的hack方式。

只在IE下生效
<!--[if IE]>
这段文字只在IE浏览器上显示
<![endif]--> 只在IE6下生效
<!--[if IE 6]>
这段文字只在IE6浏览器上显示
<![endif]--> 只在IE6以上版本生效
<!--[if gt IE 6]>
这段文字只在IE6以上版本IE浏览器上显示
<![endif]--> 只在IE7上不生效
<!--[if ! IE 7]>
这段文字在非IE7浏览器上显示
<![endif]--> 非IE浏览器生效
<!--[if !IE]><!-->
这段文字只在非IE浏览器上显示
<!--<![endif]-->

2.综合一下常用的CSS Hack代码

3.IE CSS Media,来自这里 3.IE CSS Media,来自这里

4.button重置css样式兼容ie6,ie7

button在IE6、IE7下的兼容性,需要充值css为overflow:visible

5.让IE6支持max-width,min-width

.sector{max-width:500px; _width:expression((documentElement.clientWidth>500)?"500px":"auto");

min-width:300px; _width:expression((documentElement.clientWidth<300)?"300px":"auto");}

6.IE6下某些情况line-height无效

当在一个容器里文字和img、input、textarea、select、object等元素相连的时候,对这个容器设置的line-height数值会失效; 同时以上元素的行高可能×2。
受影响的浏览器: Microsoft Internet Explorer 5.01 / Windows Microsoft Internet Explorer 5.5 / Windows Microsoft Internet Explorer 6

解决办法:
对和文字相连接的img、input、textarea、select、object等元素加以属性:
{margin: (所属line-height-自身img,input,select,object高度)/2px 0;vertical-align:middle;}

原文链接:CSS Hack代码与浏览兼容总结 版权所有,转载时请注明出处,违者必究。
注明出处格式:前端开发博客 (http://caibaojian.com/css-hacks.html)
 
 

css常用代码大全以及css兼容(转载)的更多相关文章

  1. css常用代码大全

    css常用代码大全,html+css代码 html+css可以很方便的进行网页的排版布局,还能减少很多不必要的代码. 一.文本设置1.font-size: 字号参数 2.font-style: 字体格 ...

  2. CSS颜色代码大全

    CSS颜色代码大全 转载:http://blog.163.com/wujinhongisme@126/blog/static/3613698020095115919389/ RGB ( Red,Gre ...

  3. XSS(跨站脚本攻击) - 常用代码大全

    XSS(跨站脚本攻击) - 常用代码大全-版本一 1'"()&%<acx><ScRiPt >prompt(915149)</ScRiPt> < ...

  4. javascript常用代码大全

    http://caibaojian.com/288.html    原文链接 jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...

  5. PHP常用代码大全(新手入门必备)

    PHP常用代码大全(新手入门必备),都是一些开发中常用的基础.需要的朋友可以参考下.   1.连接MYSQL数据库代码 <?php $connec=mysql_connect("loc ...

  6. HTML+CSS常用代码(笔记)

    注释标签:对代码进行说明 <!-- 单行注释,也可以对多行文字进行注释 --> 常用格式标签 <b>加粗</b> <i>斜体</i> < ...

  7. html常用代码大全

    1.结构性定义 文件类型 <HTML></HTML> (放在档案的开头与结尾) 文件主题 <TITLE></TITLE> (必须放在「文头」区块内) 文 ...

  8. 23----2013.07.01---Div和Span区别,Css常用属性,选择器,使用css的方式,脱离文档流,div+css布局,盒子模型,框架,js基本介绍

    01 复习内容 复习之前的知识点 02演示VS创建元素 03div和span区别 通过display属性进行DIV与Span之间的转换.div->span 设置display:inline   ...

  9. jQuery+CSS 简单代码实现遮罩层( 兼容主流浏览器 )

    /* ** jQuery版本:jQuery-1.8.3.min.js ** 浏览器:Chrome( v31.0.1650.63 m ),IE11,Firefox( v32.0.1 ),IETester ...

随机推荐

  1. "AssertionError: View function mapping is overwriting an existing endpoint function"如何解决

    使用Flask定义URL的时候,如果出现"AssertionError: View function mapping is overwriting an existing endpoint ...

  2. Atcoder AGC031B Reversi (DP计数)

    简单的计数题.(总算做出一道AGC的B题了,然而这场比赛我忘记打了233333) 题目链接: https://atcoder.jp/contests/agc031/tasks/agc031_b 题意: ...

  3. 学习EXTJS6(4)基本功能-信息提示框组件

    1.使用组件,主要配置表现形式有二种(是否可以说参数) 用逗号分隔的传统参数列表方式: <script type="text/javascript"> Ext.onRe ...

  4. [bzoj4864][BeiJing2017Wc]神秘物质_非旋转Treap

    神秘物质 bzoj-4864 BeiJing-2017-Wc 题目大意:给定一个长度为n的序列,支持插入,将相邻两个元素合并并在该位置生成一个指定权值的元素:查询:区间内的任意一段子区间的最大值减最小 ...

  5. Javascript中的原型继承具体解释

    js中的继承,是面向对象的知识,由于js没有类的概念.所以继承是通过对象实现的.谈到继承.就必须说到prototype,就不得不先说下new的过程. 一个小小的列子: <script type= ...

  6. Spark MLlib Deep Learning Deep Belief Network (深度学习-深度信念网络)2.2

    Spark MLlib Deep Learning Deep Belief Network (深度学习-深度信念网络)2.2 http://blog.csdn.net/sunbow0 第二章Deep ...

  7. leetCode 74.Search a 2D Matrix(搜索二维矩阵) 解题思路和方法

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  8. 利用LruCache载入网络图片实现图片瀑布流效果(改进版)

    PS: 2015年1月20日21:37:27 关于LoadImageAsyncTask和checkAllImageViewVisibility可能有点小bug 改动后的代码请參见升级版本号的代码 ht ...

  9. Vue常用插件总结

    Vue-router ----- 路由插件 Vue-loader-----webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件   Vue-resource-----提供了使用 ...

  10. c.vim的安装和使用

    之前写了一些废话,今天写的稍微具体点. 在mac上给vim装个插件,,倒腾了半天 先要去找到c.vim.zip,自己百度下,官网就有的,我mac下下来,是直接解压的格式,而不是*.zip,也就是说不需 ...