近期,我刚开始升級网志了。
在改动模版的全过程中,必须重新写过CSS款式表。恰好看到instantshift.com有1篇CSS常见技能的总结文章内容,我就把它梳理出来,供自身参照,也期待对大伙儿有效。
将来,本文将不断升级。
1. 文本的水平垂直居中 将1段文本置于器皿的水平中点,要是设定text-align特性便可:
text-align:center;
2. 器皿的水平垂直居中 先为该器皿设定1个确立宽度,随后将margin的水平值设为auto便可。
div#container {
width:760px;
margin:0 auto;
}
3. 文本的竖直垂直居中 单写作字的竖直垂直居中,要是将行高与器皿高设为相同便可。
例如,器皿中有1行数据。
<div id="container">1234567890</div>
随后CSS这样写:
div#container {height: 35px; line-height: 35px;}
假如有n写作字,那末将行高设为器皿高宽比的n分之1便可。
4. 器皿的竖直垂直居中 例如,有1大1小两个器皿,请问怎样将小器皿竖直垂直居中?
<div id="big">
<div id="small">
</div>
</div>
最先,将大器皿的精准定位为relative。
div#big{
position:relative;
height:480px;
}
随后,将小器皿精准定位为absolute,再将它的左上角沿y轴下移50%,最终将它margin-top上移自身高宽比的50%便可。
div#small {
position: absolute;
top: 50%;
height: 240px;
margin-top: ⑴20px;
}
应用一样的思路,还可以做出水平垂直居中的实际效果。
5. 照片宽度的自融入 怎样使得较大的照片,可以全自动融入小器皿的宽度?CSS能够这样写:
img {max-width: 100%}
可是IE6不适用max-width,因此遇到IE6时,应用IE标准注解,将句子改变为:
img {width: 100%}
6. 三d按钮 要使按钮具备三d实际效果,要是将它的左上部边框设为浅色系,右下部边框设为深色便可。
div#button {
background: #888;
border: 1px solid;
border-color: #999 #777 #777 #999;
}
7. font特性的便捷写法 font便捷写法的文件格式为:
body {
font: font-style font-variant font-weight font-size line-height font-family;
}
因此,
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: normal;
font-variant: small-caps;
font-style: italic;
line-height: 150%;
}
能够被写成:
body {
font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif;
}
8. link情况的设定次序 link的4种情况,必须依照下面的前后左右次序开展设定:
a:link
a:visited
a:hover
a:active
9. IE标准注解 你能够运用标准注解,设定只对IE造成功效的句子:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie-stylesheet.css" />
< ![endif]-->
还能够区别各种各样不一样的IE版本号:
<!--[if IE 6]> - targets IE6 only -->
<!--[if gt IE 6]> - targets IE7 and above -->
<!--[if lt IE 6]> - targets IE5.5 and below -->
<!--[if gte IE 6]> - targets IE6 and above -->
<!--[if lte IE 6]> - targets IE6 and below -->
10. IE6专术语句:方式1 因为IE6不把html视作文本文档的根元素,因此运用这1点,能够写出仅有IE6才可以读到的句子:
/* the following rules apply only to IE6 */
* html{
}
* html body{
}
* html .foo{
}
IE7专术语句则要写成
/* the following rules apply only to IE7 */
*+html .foo{
}
11. IE专术语句:方式2 除IE6之外,全部访问器都不可以鉴别特性前的下划线。而除IE7以外,全部访问器都不可以鉴别特性前的*号,因而能够写出仅有这两个访问器才可以读到的句子:
.element {
background: red; /* modern browsers */
*background: green; /* IE 7 and below */
_background: blue; /* IE6 exclusively */
}
12. CSS的优先选择性 假如同1个器皿被好几条CSS句子界定,那末哪个界定优先选择呢?
基础标准是:
行内款式 > id款式 > class款式 > 标识名款式
例如,有1个元素:
<div id="ID" class="CLASS" style="color:black;"></div>
行内款式是最佳先的,随后别的设定的优先选择性,从低到高先后为:
div < .class < div.class < #id < div#id < #id.class < div#id.class
13. IE6的min-height
IE6不适用min-height,有两种方式能够处理这个难题:
方式1:
.element {
min-height: 500px;
height: auto !important;
height: 500px;
}
共有3条CSS句子,第1句是对于别的访问器设定最少高宽比,第3句是对于IE设定最少高宽比,第2句则是让别的访问器遮盖第3句的设定。
方式2:
.element {
min-height: 500px
_height: 500px
}
_height仅有IE6能载入。
14. font-size标准 访问器的缺省字体样式尺寸是16px,你能够先将标准字体样式尺寸设为10px:
body {font-size:62.5%;}
后边统1选用em做为字体样式企业,2.4em就表明24px。
h1 {font-size: 2.4 em}
15. Text-transform和Font Variant Text-transform用于将全部字母变为小写字母、大写字母或首字母大写:
p {text-transform: uppercase}
p {text-transform: lowercase}
p {text-transform: capitalize}
Font Variant用于将字体样式变为小型的大写字母(即与小写字母等高的大写字母)。
p {font-variant: small-caps}
16. CSS重设 CSS重设用于撤销访问器的内嵌款式,请参照YUI和Eric Meyer的款式表。
17. 用照片当做目录标示 默认设置状况下,访问器应用1个黑圆圈做为目录标示,能够用照片替代它:
ul {list-style: none}
ul li {
background-image: url("path-to-your-image");
background-repeat: none;
background-position: 0 0.5em;
}
18. 全透明 将1个器皿设为全透明,可使用下面的编码:
.element {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
在这4行CSS句子中,第1行是IE专用的,第2行用于Firefox,第3行用于webkit关键的访问器,第4行用于Opera。
19. CSS3角形 怎样应用CSS转化成1个3角形?
先撰写1个空元素
<div class="triangle"></div>
随后,将它4个边框中的3个边框设为全透明,剩余1个设为可见,便可以转化成3角形实际效果:
.triangle {
border-color: transparent transparent green transparent;
border-style: solid;
border-width: 0px 300px 300px 300px;
height: 0px;
width: 0px;
}
20. 严禁全自动换行 假如你期待文本在1行中显示信息进行,不必全自动换行,CSS指令以下:
h1 { white-space:nowrap; }
21. 用照片更换文本 有时大家必须在题目栏中应用照片,可是又务必确保检索模块可以读到题目,CSS句子能够这样写:
h1 {
text-indent:⑼999px;
background:url("h1-image.jpg") no-repeat;
width:200px;
height:50px;
}
22. 得到聚焦点的表模块素 当1个表模块素得到聚焦点时,能够将其突显显示信息:
input:focus { border: 2px solid green; }
23. !important标准 好几条CSS句子相互之间矛盾时,具备!important的句子将遮盖别的句子。因为IE不适用!important,因此还可以运用它区别不一样的访问器。
h1 {
color: red !important;
color: blue;
}
上面这段句子的結果是,别的访问器都显示信息鲜红色题目,仅有IE显示信息蓝色题目。
24. CSS提醒框 当电脑鼠标挪动到连接上方,会全自动出現1个提醒框。
<a class="tooltip" href="#">连接文本 <span>提醒文本</span></a>
CSS这样写:
a.tooltip {position: relative}
a.tooltip span {display:none; padding:5px; width:200px;}
a:hover {background:#fff;} /*background-color is a must for IE6*/
a.tooltip:hover span{display:inline; position:absolute;}
25. 固定不动部位的页首 当网页页面翻转时,有时必须页首在部位固定不动不会改变,CSS句子能够这样写
body{ margin:0;padding:100px 0 0 0;}
div#header{
position:absolute;
top:0;
left:0;
width:100%;
height:<length>;
}
@media screen{
body>div#header{position: fixed;}
}
* html body{overflow:hidden;}
* html div#content{height:100%;overflow:auto;}
IE6的另外一种写法(用于固定不动部位的页脚):
* 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');
}
26. 在IE6中设定PNG照片的全透明实际效果
.classname {
background: url(image.png);
_background: none;
_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader
(src='image.png', sizingMethod='crop');
}
27. 各类访问器的专术语句
/* IE6 and below */
* html #uno { color: red }
/* IE7 */
*:first-child+html #dos { color: red }
/* IE7, FF, Saf, Opera */
html>body #tres { color: red }
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }
/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }
/* Safari 2⑶ */
html[xmlns*=""] body:last-child #seis { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho { color: red }
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#diez { color: red }
}
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
#veintiseis { color: red }
}
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece { color: red }
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red }
/* Everything but IE6⑻ */
:root *> #quince { color: red }
/* IE7 */
*+html #dieciocho { color: red }
/* Firefox only. 1+ */
#veinticuatro, x:-moz-any-link { color: red }
/* Firefox 3.0+ */
#veinticinco, x:-moz-any-link, x:default { color: red }
/***** Attribute Hacks ******/
/* IE6 */
#once { _color: blue }
/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }
/* Everything but IE6 */
#diecisiete { color/**/: blue }
/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }
/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }
/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
28. 器皿的水平静竖直垂直居中 HTML编码以下:
<figure class='logo'>
<span></span>
<img class='photo'/>
</figure>
CSS编码以下:
.logo {
display: block;
text-align: center;
display: block;
text-align: center;
vertical-align: middle;
border: 4px solid #dddddd;
padding: 4px;
height: 74px;
width: 74px; }
.logo * {
display: inline-block;
height: 100%;
vertical-align: middle; }
.logo .photo {
height: auto;
width: auto;
max-width: 100%;
max-height: 100%; }
29. CSS黑影 外黑影:
.shadow {
-moz-box-shadow: 5px 5px 5px #ccc;
-webkit-box-shadow: 5px 5px 5px #ccc;
box-shadow: 5px 5px 5px #ccc;
}
内黑影:
.shadow {
-moz-box-shadow:inset 0 0 10px #000000;
-webkit-box-shadow:inset 0 0 10px #000000;
box-shadow:inset 0 0 10px #000000;
}
30. 撤销IE文字框的翻转条
textarea { overflow: auto; }
31. 照片预载入 请参照
https://www.jb51.net/article/32761.htm
https://www.jb51.net/css/68340.html
32. CSS重设
请参照https://www.jb51.net/css/68582.html