22个必须知道的css技巧_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:56:35
原创
1312人浏览过

1、改变选中文字的背景和颜色

::selection{ /* Safari and Opera */    background:#c3effd;    color:#000;}::-moz-selection{ /* Firefox */    background:#c3effd;    color:#000;}
登录后复制

2、防止火狐滚动条跳动

html{ overflow-y:scroll; }
登录后复制

3、分页打印

.page-break{ page-break-before:always; }
登录后复制

4、使用!important

.page { background-color:blue !important;   background-color:red;}
登录后复制

5、图像替换文字

.header{    text-indent:-9999px;    background:url('someimage.jpg') no-repeat;    height: 100px; /*dimensions equal to image size*/    width:500px;}
登录后复制

标注:text-indent:-9999px; 是将首行左缩进到人看不到的地方

6、兼容浏览器的最小高度

#container{    height:auto !important;/*all browsers except ie6 will respect the !important flag*/    min-height:500px;    height:500px;/*Should have the same value as the min height above*/}
登录后复制

7、对新窗口打开得链接高亮显示

a[target="_blank"]:before,a[target="new"]:before {    margin:0 5px 0 0;    padding:1px;    outline:1px solid #333;    color:#333;    background:#ff9;    font:12px "Zapf Dingbats";    content: "\279C";}
登录后复制

8、美化li序列号

如图:

ol {    font: italic 1em Georgia, Times, serif;    color: #999999;}ol p {    font: normal .8em Arial, Helvetica, sans-serif;    color: #000000;}
登录后复制

9、首字下沉

如图:

p:first-letter{display:block;margin:5px 0 0 5px;float:left;color:#FF3366;font-size:3.0em;font-family:Georgia;}
登录后复制

10、兼容浏览器的opacity

.transparent_class {          filter:alpha(opacity=50);          -moz-opacity:0.5;          -khtml-opacity: 0.5;          opacity: 0.5;      }
登录后复制

11、使用line-height实现垂直居中

line-height:30px;
登录后复制

12、居中布局

body{    width:1000px;    margin:0 auto;}
登录后复制

13、移除ie文本域的垂直滚动条

textarea{    overflow:auto;}
登录后复制

14、移动超链接的虚线框

a:active, a:focus{ outline:none; }
登录后复制

15、ie下元素消失,给该元素添加

position:relative;
登录后复制

16、根据链接不一样,添加不一样的icons

a[href$='.doc'] {    padding:0 20px 0 0;    background:transparent url(/graphics/icons/doc.gif) no-repeat center right;}
登录后复制

17、css手型点击样式

input[type=submit],label,select,.pointer { cursor:pointer; }
登录后复制

18、字母大写

text-transform: capitalize;
登录后复制

19、所有英文大写,且首字母比其他的大

font-variant:small-caps;
登录后复制

20、高亮文本框,不支持ie

input[type=text]:focus, input[type=password]:focus{    border:2px solid #000;}
登录后复制

21、移除img边框

a img{ border:none; }
登录后复制

22、用label实现无表格表单

HTML Code

<form method="post" action="#" ><p><label for="username" >Username</label><input type="text" id="username" name="username" /></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p><p><label for="password" >Username</label><input type="password" id="password" name="pass" /></p>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/1370">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175680247718312.png" alt="C知道">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/1370">C知道</a>
                            <p>CSDN推出的一款AI技术问答工具</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="C知道">
                                <span>45</span>
                            </div>
                        </div>
                        <a href="/ai/1370" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="C知道">
                        </a>
                    </div>
                <p><input type="submit" value="Submit" /></p></form>
登录后复制

CSS Code

p label{    width:100px;    float:left;    margin-right:10px;    text-align:right;}
登录后复制

 参考:http://www.cnblogs.com/guoguo-15/archive/2011/08/24/2151859.html

 

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号