HTML & CSS » 有用的HTML+CSS片段

有用的HTML+CSS片段

发表于: HTML & CSS, 前端开发. 评论 (5)
Sponsor

今天向大家分享有关前端的一些小知识,包括HTML和CSS的技术,比如CSS3的渐变(Gradients)、@font-face的使用以及圆角阴影等等,对于新手们还是有必要学习的。如果你已经是高手哪么也可以看看,并希望你能给我们一些建议。

HTML5页面模板

现在国外很多制作新网站直接使用了HTML5代码,当然我们也得跟上,下面是一个常用的HTML5默认模板,就像你用Dreamweaver新建一个HTML文件时的代码,只不过现在这个是HTML5的。这个代码为了兼容IE浏览器,所以加入Google托管的HTML5shiv文件。其次是我们经常用到的最新的jQuery 1.8.2库。

<!doctype html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Default Page Title</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="styles.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>

</body>
</html>

CSS RESET

CSS Reset我想很多人都使用,他是CSS浏览器复位样式代码,下面这个已经是支持HTML5的Reset了,所以不要再使用旧的CSS RESET文件了哦。

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
   margin: 0;
   padding: 0;
   border: 0;
   font-size: 100%;
   font: inherit;
   vertical-align: baseline;
   outline: none;
 }
 html { height: 101%; } /* always display scrollbars */
 body { font-size: 62.5%; line-height: 1; font-family: Arial, Tahoma, Verdana, sans-serif; }
 
 article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
 ol, ul { list-style: none; }
 
 blockquote, q { quotes: none; }
 blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
 strong { font-weight: bold; } 
 
 input { outline: none; }
 
 table { border-collapse: collapse; border-spacing: 0; }
 img { border: 0; max-width: 100%; }
 
 a { text-decoration: none; }
 a:hover { text-decoration: underline; }

Clearfix清除浮动

清除浮动是前端人员必须知道的哦,延伸学习:http://www.qianduan.net/new-clearfix.html

.clearfix:before, .container:after { content: ""; display: table; }
.clearfix:after { clear: both; }

/* IE 6/7 */
.clearfix { zoom: 1; }

CSS3 渐变(CSS3 Gradients)

CSS3渐变真的很好用,但是它容易记住,下面是比较全面的浏览器兼容的CSS3渐变代码,下次使用直接Copy就可以了。

background-color: #000;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bbb', endColorstr='#000');
background-image: -webkit-gradient(linear, left top, left bottom, from(#bbb), to(#000));
background-image: -webkit-linear-gradient(top, #bbb, #000);
background-image: -moz-linear-gradient(top, #bbb, #000);
background-image: -ms-linear-gradient(top, #bbb, #000);
background-image: -o-linear-gradient(top, #bbb, #000);
background-image: linear-gradient(top, #bbb, #000);

CSS3渐变生成工具:CSS3 Gradient Generatorcolorzilla

延伸学习教程:http://css-tricks.com/examples/CSS3Gradient/http://www.w3cplus.com/content/css3-gradient(中文)

CSS3 Transforms

这个CSS3 Transforms(转换变形)代码很少用到,因为浏览支持不多,但它出来的效果却很强大。

-webkit-transform: perspective(250) rotateX(45deg);
-moz-transform: perspective(250) rotateX(45deg);
-ms-transform: perspective(250) rotateX(45deg);
-o-transform: perspective(250) rotateX(45deg);
transform: perspective(250) rotateX(45deg);

CSS3 Transforms在线工具:http://westciv.com/tools/transforms/index.html

延伸学习教程:http://sev7n.net/index.php/473.html(中文)

@font-face

这个主要是用于嵌入字体的模块,一般适用于嵌入文件较小的字体,中文字体很大,所以很少被嵌入。

@font-face{ 
  font-family: 'MyFont';
  src: url('myfont.eot');
  src: url('myfont.eot?#iefix') format('embedded-opentype'),
    url('myfont.woff') format('woff'),
    url('myfont.ttf') format('truetype'),
    url('myfont.svg#webfont') format('svg');
}

h1 { font-family: 'MyFont', sans-serif; }

延伸学习教程:http://www.w3cplus.com/content/css3-font-face(中文)

HTML Meta标签(用于响应性布局)

如果你已经制作了响应性布局,哪么加入下面代码到head部分,就可以在不同设备上浏览。

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">

HTML5嵌入媒体 (HTML5 Embedded Media)

新的<video>,<audio>标签给开发人员提供方便的嵌入媒体方式,这个日后必定很实用。

<video poster="images/preview.png" width="1280" height="720" controls="controls" preload="none"> 
	<source src="media/video.mp4" type="video/mp4"></source> 
	<source src="media/video.webm" type="video/webm"></source> 
	<source src="media/video.ogg" type="video/ogg"></source>
</video>

<audio controls="controls" preload="none">
	<source src="music.ogg" type="audio/ogg">
	<source src="music.mp3" type="audio/mpeg">
</audio>

总结

这篇文章介绍的都是基本入门的代码,在你构建HTML5/CSS3网站时通常都会用到它们,所以建议你收藏这些代码,也希望你能分享给更多人。

推荐:查看最受欢迎的 301 个设计网站 → http://hao.shejidaren.com
交流:为设计新人提供的设计交流群,请加入UI设计交流群,分享经验、接单、求职、聊设计。
赞助商链接
赞助商链接
设计达人微信交流社区:shejidaren888
喜欢这篇文章吗?欢迎分享到你的微博、QQ群,并关注我们的微博,谢谢支持。
版权:除非注明,本站文章均为原创文章,转载请联系我们授权,否则禁止转载。

+ 添加评论5 Responses to “有用的HTML+CSS片段”

  1. allgar - 回复

    很好的好网站

  2. 放珜的橙 - 回复

    支持

  3. Neo - 回复

    感觉html5在中国不好走…因为太多的IE…..

  4. Monad - 回复

    第一张图片的那个编辑器叫什么有人告诉我吗、用的NP看到这个忘记叫什么了!

    • monad -

      哦、我还以为是微软那个什么编辑器、这种底色看到舒服!


Leave a Reply to Neo