CSS3圆角,阴影,透明_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:51:52
Original
1651 people have browsed it

CSS实现圆角,阴影,透明的方法很多,传统的方法都比较复杂,用CSS3就方便很多了,虽然现在各浏览器对CSS3的支持还不是很好,但不久的将来CSS3就会普及.

 

1.圆角

CSS3实现圆角有两种方法.

第一种是背景图像,传统的CSS每个元素只能有一个背景图像,但是CSS3可以允许一个元素有多个背景图像.这样给一个元素添加4个1/4圆的背景图像,分别位于4个角上就可以实现圆角了.

Html代码  

  1. .box {  
  2.     /* 首先定义要使用的4幅图像为背景图 */  
  3.     background-image: url(/img/top-left.gif),  
  4.                                    url(/img/top-right.gif),  
  5.                                    url(/img/bottom-left.gif),  
  6.                                    url(/img/bottom-right.gif);  
  7.     /* 然后定义不重复显示 */  
  8.     background-repeat: no-repeat,  
  9.                                      no-repeat,  
  10.                                      no-repeat,  
  11.                                      no-repeat;  
  12.     /* 最后定义4幅图分别显示在4个角上 */  
  13.     background-position: top left,  
  14.                                        top right,  
  15.                                        bottom left,  
  16.                                        bottom right;  
  17. }  

 第二种方法就简洁了,直接用CSS实现,不需要用图片.

Html代码  

  1. .box {  
  2.     /* 直接定义圆角的半径就可以了 */  
  3.     border-radius: 1em;  
  4. }  

 但是第二种方法还没有得到很好的支持,当前Firefox和Safari(同一个核心的Chrome也可以),需要使用前缀

Html代码  

  1. .box {  
  2.     -moz-border-radius: 1em;  
  3.     -webkit-border-radius: 1em;  
  4.     border-radius: 1em;  
  5. }  

 

2.阴影

CSS3的box-shadow属性可以直接实现阴影

Html代码  

  1. img {  
  2.     -webkit-box-shadow: 3px 3px 6px #666;  
  3.     -moz-box-shadow: 3px 3px 6px #666;  
  4.     box-shadow: 3px 3px 6px #666;  
  5. }  

 这个属性的4个参数是:垂直偏移,水平偏移,投影的宽度(模糊程度),颜色

 

3.透明

CSS本来就是支持透明的,IE以外的浏览器是opacity属性,IE是filter:alpha.但是,这个透明度有个缺点,就是它会使应用元素的内容也会继承它,比如有一个DIV,

Html代码  

  1. >  
  2.     内容  
  

 如果像上面这样DIV的背景是透明了,但是内容两个字也透明了,这时可以用RGBa.

Html代码  

  1. .alert {  
  2.     rgba(0,0,0,0.8);  
  3. }  

 这个属性前3个属性表示颜色红,绿,蓝,第四个是透明度.红绿蓝都是0代表黑色,所以rgba(0,0,0,0.8)就是将黑色的透明度设置为0.8.

 

 

CSS3使得原来很难实现的效果变得很简单,希望各浏览器对CSS3尽快实现完美支持.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!