7.一般媒体查询
- /* Smartphones (portrait and landscape) ----------- */
- @media only screen
- and (min-device-width : 320px) and (max-device-width : 480px) {
- /* Styles */
- }
- /* Smartphones (landscape) ----------- */
- @media only screen and (min-width : 321px) {
- /* Styles */
- }
- /* Smartphones (portrait) ----------- */
- @media only screen and (max-width : 320px) {
- /* Styles */
- }
- /* iPads (portrait and landscape) ----------- */
- @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
- /* Styles */
- }
- /* iPads (landscape) ----------- */
- @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
- /* Styles */
- }
- /* iPads (portrait) ----------- */
- @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
- /* Styles */
- }
- /* Desktops and laptops ----------- */
- @media only screen and (min-width : 1224px) {
- /* Styles */
- }
- /* Large screens ----------- */
- @media only screen and (min-width : 1824px) {
- /* Styles */
- }
- /* iPhone 4 ----------- */
- @media only screen and (-webkit-min-device-pixel-ratio:1.5), only screen and (min-device-pixel-ratio:1.5) {
- /* Styles */
- }
这是一个很棒的模版,你能在CSS-Tricks找到其它零碎的媒体查询。不管怎样我已经把他们的例子全拷下来了,那里面包括了成吨的实际的移动设备。这些代码甚至能针对视网膜屏设备,使用最小设备像素比例。
8. 现代字体栈
- /* Times New Roman-based serif */
- font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
- /* A modern Georgia-based serif */
- font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif;
- /*A more traditional Garamond-based serif */
- font-family: "Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif;
- /*The Helvetica/Arial-based sans serif */
- font-family: Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;
- /*The Verdana-based sans serif */
- font-family: Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif;
- /*The Trebuchet-based sans serif */
- font-family: "Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif;
- /*The heavier "Impact" sans serif */
- font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif;
- /*The monospace */
- font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
你很难为设计一个新的页面头脑风暴式的想出自己的CSS字体栈。我希望这一小片代码能减轻一些折磨,并给你一些可以着手开始的模版。如果你想找更多的例子,查看一下CSS 字体栈 ,这是我最喜欢的资源之一。
9. 自定义文本选择
- ::selection { background: #e2eae2; }
- ::-moz-selection { background: #e2eae2; }
- ::-webkit-selection { background: #e2eae2; }
一些新式的浏览器会允许你定义页面中的高亮颜色。默认这是设为淡蓝色的,但你可以设置任何投你所好的颜色值,这小片代码包括了典型的::selection目标以及专为Webkit和Mozilla的特定前缀。
10.隐藏H1文本为Logo标志
- h1 {
- text-indent: -9999px;
- margin: 0 auto;
- width: 320px;
- height: 85px;
- background: transparent url("images/logo.png") no-repeat scroll;
- }
我第一次注意到这个技术实现是在古老的Digg 布局 。为了SEO的目的,你也可以设置一个包含有你的站点名称的H1标签。但使用CSS我们能移走这个文本使它不可见,并用一个客制化的logo图片替换它。
11. polaroid图像边界
- img.polaroid {
- background:#000; /*Change this to a background image or remove*/
- border:solid #fff;
- border-width:6px 6px 20px 6px;
- box-shadow:1px 1px 5px #333; /* Standard blur at 5px. Increase for more depth */
- -webkit-box-shadow:1px 1px 5px #333;
- -moz-box-shadow:1px 1px 5px #333;
- height:200px; /*Set to height of your image or desired div*/
- width:200px; /*Set to width of your image or desired div*/
- }
应用这个基础的片段将使你能在你的图像上实现.polaroid 类。这将会创建老照片风格效果,带一个很宽的白边和一些淡淡的阴影。你要更新宽/高数值,以便和你的图片尺寸和网站布局相匹配。
12. 锚链接伪类
- a:link { color: blue; }
- a:visited { color: purple; }
- a:hover { color: red; }
- a:active { color: yellow; }
大多数CSS开发者知道锚链接类和:hover效果。但是我想引入这小段代码给新手做个参考。这些是一个锚链接和一些其他HTML元素的四个默认状态。把它们留在手边,直到你可以记住一些更复杂的情况。