css小贴士备忘录

前言:在CSS的学习实践过程中,我经常遗忘一些貌似常用的代码,为了能够强化记忆特在此作归纳整理并将陆续增删,以备即时查阅。但愿今后能遇到问题及时解决,牢牢记住这些奇怪的字符们。

一、关于段落文本强制对齐

text-align:justify;  text-justify:inter-ideograph;

若要文本两端对齐,必须先定义P的宽度,然后 { text-align:justify; text-justify :distribute-all-lines; }

二、给按钮的不同状态加CSS

Html代码  

  1. <style type="text/css">
  2. <!--
  3. .over { ... }
  4. .down { ... }
  5. -->
  6. </style>
  7. <input type="button"
  8. onMouseOver="this.className=‘over‘;"
  9. onMouseOut="this.className=‘ ‘;"
  10. onMouseDown="this.className=‘down‘;"
  11. onMouseUp="this.className=‘over‘;"
  12. value="未被点击的按钮"
  13. onClick="this.value=‘被点击的按钮‘" name="Button">

三、在一个CSS文件中导入另一个CSS

@import url(***.css);

四、渐变背景色(使用这个一定得加width或height)

FILTER:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#EEF5F8,endColorStr=#ffffff);

使用这个时必须注意要对该DIV定义width或height值。

Css代码  

  1. .gradient {
  2. /* Firefox 3.6 */
  3. background-image: -moz-linear-gradient(top, #81a8cb, #4477a1);
  4. /* Safari & Chrome */
  5. background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #4477a1),color-stop(1, #81a8cb));
  6. /* IE6 & IE7 */
  7. filter:  progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=‘#81a8cb‘, endColorstr=‘#4477a1‘);
  8. /* IE8 */
  9. -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=‘#81a8cb‘, endColorstr=‘#4477a1‘)";
  10. }

background:#f4faff\9;
 background:linear-gradient(#fff 0%,#f1f9ff 100%) no-repeat;
 background:-moz-linear-gradient(#fff 0%,#f1f9ff 100%) no-repeat;
 background:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#f1f9ff)) no-repeat;
 background:-o-linear-gradient(#fff 0%,#f1f9ff 100%) no-repeat

五、用PNG图片在IE6中做出透明效果

*html #id{ filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=images/*.png); background:none; }

六、单行省略文本

{ overflow:hidden; text-overflow:ellipsis;  white-space:nowrap; }

使用这个时必须注意要对需要省略文本的单行(如div或li)定义width值。

七、设为首页和加入收藏的代码

Html代码  

  1. <a style="BEHAVIOR: url(#default#homepage)" onclick="this.style.behavior=‘url(#default#homepage)‘;this.setHomePage(‘http://www.hengdong8.cn‘);" href="javascript:" target="_self">设为首页</a>|<a href="contact.htm">联系我们</a>|<a href="javascript:window.external.AddFavorite(‘http://www.hengdong8.cn‘,‘衡东吧‘)" target="_self">加入收藏</a>

 

八、中文描边效果

Java代码  

  1. <style type="text/css">
  2. <!--
  3. body {
  4. font:12px "Verdana";
  5. filter:alpha(style=1,startY=0,finishY=100,startX=100,finishX=100);
  6. }
  7. .sizscolor {
  8. font-size:14px; font-weight:bold;
  9. position:absolute;
  10. padding:4px;
  11. filter:
  12. Dropshadow(offx=1,offy=0,color=white)
  13. Dropshadow(offx=0,offy=1,color=white)
  14. Dropshadow(offx=0,offy=-1,color=white)
  15. Dropshadow(offx=-1,offy=0,color=white);
  16. }
  17. -->
  18. </style>
  19. </head>
  20. <body><div class="sizscolor">中文描边效果</div>
  21. </body>

九、调整字间距

{ text-transform: uppercase; letter-spacing: 2px }

十、margin加倍的问题

设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这个div里面加上 display:inline; 例如: <#div id=”imfloat”> 相应的css为 #IamFloat{ float:left; margin:5px; /*IE下理解为10px*/ display:inline;/*IE下再理解为5px*/}

十一、把鼠标放在图片上会出现图片变亮的效果

可以用图片替换的技巧,也可以用如下的滤镜,代码如下: 
.pictures img { filter: alpha(opacity=45); } 
.pictures a:hover img { filter: alpha(opacity=90); }

十二、区分不同浏览器

区别FF ,IE7 ,IE6 :

background:orange ;* background:green !important ;*background:blue ;

注:IE都能识别*;标准浏览器(如FF)不能识别*;

IE6能识别*,但不能识别 !important,

IE7能识别*,也能识别!important;

FF不能识别*,但能识别!important;

IE6 IE7 FF
* ×
!important ×


另外再补充一个,下划线”_ “,
IE6支持下划线,IE7和firefox均不支持下划线。

于是大家还可以这样来区分IE6 ,IE7 ,firefox 
: background:orange ;* background:green ;_ background:blue ;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。

十三、单行图片文字垂直居中对齐

style *{vertical-align:middle;.....}

 

十四、input加样式(1)

input[type~=radio]   
  {   
  ...   
  }   
    
  含义:请将所有的input应用下面的style,但是其type属性是radio的input则例外。

十五、input加样式(2)

<input type="submit" class="btn" onmouseover="this.className=‘btnOver‘" onmouseout="this.className=‘btn‘" onmousedown="this.className=‘btnDown‘" value="确认" />

<input id="" name="" type="text" class="input1" onblur="this.className=‘input1‘" onfocus="this.className=‘input1-bor‘" />

十六、给文字加阴影

h1 { float: left; text-indent:0em; text-shadow:black 2px 2px 2px;  filter: dropshadow(OffX=2, OffY=2, Color=‘black‘, Positive=‘true‘);

十七、用Javascript和CSS去掉链接中的虚线框和下划线

在链接标签中添加onFocus="if(this.blur)this.blur()"这句代码即可屏蔽点击时四周出现的虚线框,如:
<A href="http://www.cce.com.cn" onFocus="if(this.blur)this.blur()"& gt;中国电脑教育报</a>

十八、 input type="image"

十九、删除链接上的虚线框 

a:active, a:focus { outline:none; } 

 

二十、改变上传按钮的样式

Html代码  

  1. <META NAME="Generator" CONTENT="EditPlus">
  2. <META NAME="Author" CONTENT="">
  3. <META NAME="Keywords" CONTENT="">
  4. <META NAME="Description" CONTENT="">
  5. </HEAD>
  6. <BODY>
  7. <input type="text" size="20" name="upfile" id="upfile" style="border:1px dotted #ccc">
  8. <input type="button" value="浏览" onclick="path.click()" style="border:1px solid #ccc;background:#fff">
  9. <input type="file" id="path" style="display:none" onchange="upfile.value=this.value">
  10. </BODY>
  11. </HTML>

Html代码  

  1. <span id="uploadImg">
  2. <input type="file" id="file" size="1"  style="width:100" class="upload">
  3. <a href="#">上传</a></span>

Css代码  

  1. #uploadImg{ font-size:12px; overflow:hidden; position:absolute;  left:190px; top:6px; }
  2. #uploadImg a { color:#000; line-height:24px; text-align:center; display:block; width:70px; margin:0; height:24px; border:1px solid #aecbd3; background:url(../images/btnbj.gif) repeat-x 0 0; }
  3. #file{ position:absolute; z-index:100; margin-left:-180px; font-size:60px;opacity:0;filter:alpha(opacity=0); margin-top:-5px;}

Html代码  

  1. <style>
  2. input{border:1px solid green;}
  3. div {width:300px;position:relative;}
  4. p {float:left}
  5. .file {position:absolute;top:20px;right:300px;+top:0;+right:73px;width:0px;height:30px;
  6. filter:alpha(opacity=0);-moz-opacity:0;opacity:0;}
  7. #txt {height:29px;margin:1px}
  8. #ii {width:70px;height:27px;margin-top:2px;}
  9. </style>
  10. <div>
  11. <form method="post" action="" enctype="multipart/form-data">
  12. <p>
  13. <input type="text" id="txt" name="txt" />
  14. </p>
  15. <p>
  16. <input id="ii" type="image" src="http://bbs.blueidea.com/images/blue/logo.gif" value="请选择文件" />
  17. </p>
  18. <p>
  19. <input type="file" onchange="txt.value=this.value" class="file" />
  20. </p>
  21. </form>
  22. </div>

二十一、css bug

  IE6 IE7 IE8 Firefox Chrome Safari
!important   Y   Y    
_ Y          
* Y Y        
*+   Y        
\9 Y Y Y      
\0     Y      
nth-of-type(1)         Y Y
时间: 2024-08-08 13:58:06

css小贴士备忘录的相关文章

[html]CSS 小贴士

CSS 中用四个伪类来定义链接的样式,分别是:a:link.a:visited.a:hover 和 a : active,例如: a:link{font-weight : bold ;text-decoration : none ;color : #c00 ;} a:visited {font-weight : bold ;text-decoration : none ;color : #c30 ;} a:hover {font-weight : bold ;text-decoration :

Git 中级用户的25个小贴士

原文链接:25 Tips for Intermediate Git Users 作者:Andy Jeffries 时间:2009年11月1日 更新:这篇文章最初是在 2009年11月 发布到我的博客,它一直没有更新--不过有许多人发现这篇文章很有用,所以我想保持下去.请不要评论说"这些已经不再是中级小贴士了". 我使用 git 大约 18 个月了,以为自己已经比较了解 git 了.但当我们请 GitHub 的 Scott Chacon 来 LVS 公司(博彩/游戏软件开发商)做一些培训

备起来!Linux安全运维常见命令小贴士

备起来!Linux安全运维常见命令小贴士 常用命令 1. 查找关键词并统计行数 cat 2015_7_25_test_access.log | grep "sqlmap" | wc -l 2. 删除含有匹配字符的行 sed -i '/Indy Library/d' 2015_7_25_test_access.log 3. 查找所有日志中的关键词 find ./ -name "*.log" |xargs grep "sqlmap" |wc -l 4

CSS小技巧

CSS 小技巧 总结的网络上的资源,以备自己后续参考... 使用:not()去除导航上不需要的边框 为body添加行高 垂直居中任何元素 逗号分离的列表 使用负nth-child选择元素 使用SVG图标 文本显示优化 在纯CSS幻灯片上使用max-height 继承box-sizing 表格单元格等宽 使用Flexbox摆脱边界Hack 使用属性选择器选择空链接 使用:not()添加/去除导航上不需要的边框 添加边框… /* 添加边框 */ .nav li { border-right: 1px

性能小贴士

性能小贴士 本文主要介绍一些代码优化方面的小贴士,结合起来使用能整体性的提升应用性能.但是,这些技巧不可能带来戏剧性的性能改变.合适的算法和数据结构是解决性能的首选考虑(还有程序的执行流程优化),但这已经脱离了本文的范畴. 本文介绍的小贴士是每个有追求的程序员应有的编码习惯. 关于如何写出高效的代码,这里有两个基本的原则: Don't do work that you don't need to do Don't allocate memory if you can avoid it 面临的现状

LINUX 小技巧备忘录

最近发现MDT推出去的系统的有不同问题,其问题就不说了,主要是策略权限被域继承了.比如我们手动安装的很多东东都是未配置壮态,推的就默认为安全壮态了,今天细找了一下,原来把这个关了就可以了. LINUX 小技巧备忘录,布布扣,bubuko.com

css小案例:导航栏特效

css小案例:导航栏特效,实现如下图所示效果: 首先可以将html代码写出: 1 <nav class="cl-effect-1"> 2 <a href="#">Umbrella</a> 3 <a href="#">Ineffable</a> 4 <a href="#">Lilt</a> 5 <a href="#"&g

每个程序员需掌握的20个代码命名小贴士

代码中到处都需要命名.作为程序员,我们得给类命名,给变量命名,给函数命名,给参数命名,给命名空间命名,等等等等.下面有20条小贴士能帮助你提高你的命名能力. 1.使用能够表达意图的名字 名字得能告诉我们它要做什么,为什么存在,以及是如何工作的.选择能够表达意图的名字,将更有利于我们理解代码. <span style="font-size:14px;">int d; // elapsed time in days int elapsedTimeInDays; int days

iframe的使用小贴士

1.之前又说到“根据内容计算iframe的高度” 链接 2.现在想说的是,一般iframe页面都是嵌套在父页面当中,所以在一般在iframe里面做相关动作时默认都是iframe页面的,不会影响到父页面.因此若是需要在iframe的子页面里面操作父页面的元素,我们会如何做? iframe 子页面操作父页面元素需要知道的两点是: (1)iframe 子页面和父页面必须属于同一个域下.(这个问题,一般在本地页面来做到,是不太可能的,经常会有这个错误出现 “Uncaught SecurityError: