使用CSS3将你的网站设计推向未来

2016-02-20 00:03 7 1 收藏

下面图老师小编跟大家分享使用CSS3将你的网站设计推向未来,一起来学习下过程究竟如何进行吧!喜欢就赶紧收藏起来哦~

【 tulaoshi.com - Web开发 】

There are exciting new features in the pipeline for Cascading Style Sheets that will allow for an explosion of creativity in Web design. These features include CSS styling rules that are being released with the upcoming CSS3 specification. Realistically, you won’t be able to use these on your everyday client projects for another few years, but for design blogs and websites aimed at the Web design community, these features can help you push the boundaries of modern Web design today, adding that extra spice to your design and helping the industry move forward.

Here are five techniques snatched from the future that you can put into practice in your website designs today.

1. Border Radius

CSS border-radius

Probably the most common CSS3 feature currently being used is border-radius. Standard HTML block elements are square-shaped with 90-degree corners. The CSS3 styling rule allows rounded corners to be set.

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)view plaincopy to clipboardprint?-moz-border-radius: 20px;   -webkit-border-radius: 20px;   border-radius: 20px;  

Border-radius can also be used to target individual corners, although the syntax for -moz- and -webkit- is slightly different:

view plaincopy to clipboardprint?-moz-border-radius-topleft: 20px;   -moz-border-radius-topright: 20px;   -moz-border-radius-bottomleft: 10px;   -moz-border-radius-bottomright: 10px;   -webkit-border-top-right-radius: 20px;   -webkit-border-top-left-radius: 20px;   -webkit-border-bottom-left-radius: 10px;   -webkit-border-bottom-right-radius: 10px;  

Supported in Firefox, Safari and Chrome.

As used by: Twitter.

See also:

W3C Working Draft Border-radius on CSS3.info The Art of Web 2. Border Image

CSS border-image

Border-image, as the name suggests, allows an image file to be used as the border of an object. The image is first created in relation to each side of an object, where each side of the image corresponds to a side of the HTML object. This is then implemented with the following syntax:

view plaincopy to clipboardprint? border: 5px solid #cccccc;   -webkit-border-image: url(/images/border-image.png) 5 repeat;   -moz-border-image: url(/images/border-image.png) 5 repeat;   border-image: url(/images/border-image.png) 5 repeat;  

The {border: 5px} attribute specifies the overall width of the border, and then each border-image rule targets the image file and tells the browser how much of the image to use to fill up that 5px border area.

Border images can also be specified on a per-side basis, allowing for separate images to be used on each of the four sides as well as the four corners:

view plaincopy to clipboardprint?border-bottom-right-image   border-bottom-image   border-bottom-left-image   border-left-image      border-top-left-image      border-top-image      border-top-right-image      border-right-image  

Supported in Firefox 3.1, Safari and Chrome.

As used by: Blog.SpoonGraphics.

See also:

W3C Working Draft Border-image on CSS3.info Border-image in Firefox 3. Box Shadow and Text Shadow

CSS Shadow

Drop shadows: don’t you just love them?! They can so easily make or break a design. Now, with CSS3, you don’t even need Photoshop! The usage we’ve seen so far has really added to the design, a good example being this year’s 24 Ways website.

view plaincopy to clipboardprint?-webkit-box-shadow: 10px 10px 25px #ccc;   -moz-box-shadow: 10px 10px 25px #ccc;   box-shadow: 10px 10px 25px #ccc;  

The first two attributes determine the offset of the shadow in relation to the element, in this case, 10 pixels on the x and y axis. The third attribute sets the level of blurriness of the shadow. And finally, the shadow color is set.

Also, the text-shadow attribute is available for use on textual content:

view plaincopy to clipboardprint?text-shadow: 2px 2px 5px #ccc;  

Supported in Firefox 3.1, Safari, Chrome (box-shadow only) and Opera (text-shadow only).

As used by: 24 Ways.

See also:

W3C Working Draft Box-shadow on CSS3.info W3C Working Draft Text-shadow on CSS3.info 4. Easy Transparency with RGBA and Opacity

CSS Opacity

The use of PNG files in Web design has made transparency a key design feature. Now, an alpha value or opacity rule can be specified directly in the CSS.

view plaincopy to clipboardprint?rgba(200, 54, 54, 0.5);   /* example: */  background: rgba(200, 54, 54, 0.5);   /* or */  color: rgba(200, 54, 54, 0.5);  

The first three numbers refer to the red, green and blue color channels, and the final value refers to the alpha channel that produces the transparency effect.

Alternatively, with the opacity rule, the color can be specified as usual, with the opacity value set as a separate rule:

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)view plaincopy to clipboardprint?color: #000;   opacity: 0.5;  

Supported in Firefox, Safari, Chrome, Opera (opacity) and IE7 (opacity, with fixes).

As used by: 24 Ways (RGBA).

See also:

W3C Working Draft RGBA on CSS3.info Pure CSS Opacity 5. Custom Web Fonts with @Font-Face

CSS font-face

There has always been a set of safe fonts that can be used on the Web, as you know: Arial, Helvetica, Verdana, Georgia, Comic Sans (ahem), etc. Now the @font-face CSS3 rule allows fonts to be called from an online directory and used to display text in a whole new light. This does bring up issues of copyright, so there are only a handful of specific fonts that can be used for @font-face embedding.

The styling is put into practice like so:

view plaincopy to clipboardprint?@font-face {   font-family:'Anivers';   src: url('/images/Anivers.otf') format('opentype');   }  

The rest of the font family, containing secondary options, is then called as usual:

view plaincopy to clipboardprint?h1 { font-family: ‘Anivers’, Helvetica, Sans-Serif;  

Supported in Firefox 3.1, Safari, Opera 10 and IE7 (with lots of fixes: if you are brave enough, you can make font-face work in IE (thanks for heads up, Jon Tan))

As used by: TapTapTap.

See also:

Fonts available for font-face embedding Font-face in IE, making Web fonts work Web fonts, the next big thing - A List Apart

Although CSS3 is still under development, the rules listed here are supported by some browsers right now. Safari in particular has extensive support for these new features. Unfortunately, despite being a top-quality browser, Safari has a relatively low number of users, so it is probably not worthwhile adding extra features solely for this group of users. But with Apple’s Mac computers making their way into everyday life, Safari’s usage is likely to continually increase.

Firefox, on the other hand, now has a considerably large user base. What’s more, the soon-to-be-released Firefox 3.1 has added support for a range of CSS3 features. Assuming that most users of Firefox will update their browsers, there will soon be a large group of users with support for these new styling rules.

Google Chrome was released this year. Based on the WebKit engine, this browser has much of the same support as Safari. While Safari makes up a good proportion of Mac users, Chrome has burst onto the scene, making up a decent proportion of Windows users.

Percentage-wise, the W3’s browser statistics indicate that, as of November 2008, 44.2% of W3School’s users across the Web were browsing with Firefox, 3.1% with Chrome and 2.7% with Safari. That means almost 50% of all Internet users should be able to view these features. Within the Web design community in particular, which is much more conscious of browser choice, the range of users with CSS3 support is much higher, at 73.6% (according to the stats at Blog.SpoonGraphics).

6. The downside

Your website may now have a range of fancy new design features, but there are a few negatives to take into consideration:

Internet Explorer: 46% of Internet users won’t see these features, so don’t use them as a crucial part of the design of your website. Make sure that secondary options are in place, such as a standard border in place of border-image and a normal font in place of @font-face. Please notice that Internet Explorer supports with EOT (more details) since v4 (thanks for heads up, Jon Tan). Invalid style sheets: These CSS3 features have not been released as a final specification. They are currently implemented with tags that target different browsers. This can invalidate your style sheet. Extra CSS markup: Following the last point, having to add a different tag for each browser to specify the same rule, as well as include the standard rule for the final CSS specification, adds a lot of extra code to your CSS markup. Potentially horrific usage: Just as is done with traditional Photoshop filters, the use of these new styling features could result in some eye-wrenching designs. Drop shadows in particular ring warning bells for us; we’re not looking forward to seeing the Marketing Department’s choices with that one!

来源:http://www.tulaoshi.com/n/20160220/1631159.html

延伸阅读
标签: Web开发
CSS 3 + HTML 5 是未来的 Web,它们都还没有正式到来,虽然不少浏览器已经开始对它们提供部分支持。本文介绍了 5 个 CSS3 技巧,可以帮你实现未来的Web。目前这些技术不应该用在正式的客户项目,它们更适合你的个人博客站点,Web 设计社区,或者不会有客户向你投诉的场合。 1. 圆角效果 CSS3 新功能中最常用的一项是圆...
标签: Web开发
本文中的这些标志与图标都是用CSS3制作而成,看上去似乎很不可思议,其中包括了IE图标,网站图标,奥运会标志等等,都是一些十分常见的标志,而它们之所有如此特别是因为这些标志与图标只是用CSS3来显示在网页中,而并非图片显示。 尽管被批评为走火入魔,CSS3 痴迷者们仍然在尝试实现各种基于纯 CSS 的图形与图标设计,如果你看到本文介绍的...
标签: Web开发
1. 圆角效果     CSS3 新功能中最常用的一项是圆角效果,标准 HTML 方块对象是90度方角的,CSS3 可以帮你实现圆角。 1.moz-border-radius: 20px; 2.webkit-border-radius: 20px; 3.border-radius: 20px; 甚至单个角也可以实现圆角,不过 Mozilla 和 Webkit 的语法稍有不同。 1.moz-border-radius-topleft: 20px; 2.moz-...
标签: Web开发
CSS3透明不透明渐变随便你怎么叫它吧!这里是一些使用CSS3透明度的指南以及一些例子。 其实这个firefox很久以前就支持了,而IE一直不支持! 上一篇文章:CSS3教程(7):CSS3嵌入字体 opacity声明用来设置一个元素的透明度:层、文字、图片等一个opacity的值为1的元素是完全不透明的,反之,值为0是完全透明的,看不见的。1到0之间的任何值...
标签: Web开发
使用CSS3 HSL声明同样是用来设置颜色的。下一个呢? HSLA? 是的,这个和RGBA的效果是一样的。 上一篇文章:CSS3教程(9):设置RGB颜色 HSL声明使用色调Hue(H)、饱和度Saturation(s)和亮度Lightness(L)来设置颜色。 Hue 衍生于色盘:0和360是红色,接近120的是绿色,240是蓝色。 Saturation 值是一个百分比:0%是灰度,100%饱和度最高 ...

经验教程

829

收藏

78
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部