如何用CSS将图片显示成圆角

html-css014

如何用CSS将图片显示成圆角,第1张

用CSS将图片显示成圆角的效果图。 看到了吧,这就是用纯CSS实现的圆角化图片,为了能看到透明化的效果,我特意应用了一个背景图片,你可以下载本模型到你的电脑中,随意伸缩窗口的大小,看看外圆角是否是透明的。 有了这种效果,你再也不愁给每一张图片作圆角的工作,这种效果在一些图片类的演示页面中经常见到,特别适用那些图片比较多的列表中。怎么样,效果还可以吧! 好了,我们来看看它的实现机制吧! 实现原理: 这种效果其实就是我在第二章中变体实现,下面讲一讲主要的关键代码。 主要变化的还是背景图片的定位,只是这一次与第二章中的有些不同,这次需要考虑到下面的两个圆角的变化。 先看看上面两个圆角的实现: /*图片偏移定位--上面部分*/ .sharp b.b2{background-position:-4px top} .sharp b.b3{background-position:-2px -1px} .sharp b.b4{background-position:-1px -2px} 再看看下面两个圆角的样式设置,下面部分和上面部分是相互对应的。 /*图片偏移定位--下面部分*/ .sharp b.b7{background-position:-4px bottom} .sharp b.b6{background-position:-2px bottom} .sharp b.b5{background-position:-1px bottom} 不同的图片调用样式: /*颜色方案一,绿色风格----------------------------------------*/ /*边框色*/ .color1 .b2,.color1 .b3,.color1 .b4,.color1 .b5,.color1 .b6, .color1 .b7,.color1 .content{border-color:#262626} .color1 .b1,.color1 .b8{background:#262626} /*图片路径*/ .color1 .b2,.color1 .b3,.color1 .b4,.color1 h3,.color1 .b5,.color1 .b6,.color1 .b7,.color1 .content{background:url(image/1.jpg) no-repeat} 前面两句共同构成边线框的颜色值,需要设置成同一个色值,后面的一句设置图片的调用路径。 三句话就搞定一种颜色方案了

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:img { border-radius: 20px}。

3、浏览器运行index.html页面,此时页面插入的图片会自动显示圆角20px的。

第一种

<html xmlns:v>

<head>

<style>

v\:*{behavior: url(#default#VML)}

</style>

</head>

<body>

<v:roundRect style="position:absoluteleft:20pxtop:50pxwidth:200pxheight:140px" FillColor="#e8e8e8" Filled="T" />

刷新本页才能看到效果

</body>

</html>

======================================

第二种

css圆角效果,IE6, firefox均显示正常

<html>

<head>

<title>css圆角效果--网站每日新</title>

<meta http-equiv="content-type" content="text/htmlcharset=gb2312">

<style type="text/css">

div.RoundedCorner{background: #9BD1FA}

b.rtop, b.rbottom{display:blockbackground: #FFF}

b.rtop b, b.rbottom b{display:blockheight: 1pxoverflow: hiddenbackground: #9BD1FA}

b.r1{margin: 0 5px}

b.r2{margin: 0 3px}

b.r3{margin: 0 2px}

b.rtop b.r4, b.rbottom b.r4{margin: 0 1pxheight: 2px}

</style>

</head>

<body>

<div class="RoundedCorner">

<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>

<br>无图片实现圆角框<br><br>

<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>

</div>

</body>

</html>