如何使用css让图片显示圆角

如何使用css让图片显示圆角,第1张

CSS3圆角只需设置一个属性:border-radius(含义是"边框半径")。你为这个属性提供一个值,就能同时设置四个圆角的半径。所有合法的CSS度量值都可以使用:em、ex、pt、px、百分比等等。

代码实例:border-radius: 15px;

1、把下列代码添加进入你的<style>标签内

2、清空缓存,看看效果吧(部分IE版本可能不支持)

预览

总结

这是个很实用的方法,可以让看起来更「精巧」一些

1、首先我们需要插入一张,并且只出现一次,并设计出现的位置在左上角,可以按照如下代码来完成:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:top left;

}

</style>

</head>

<body>

</body>

</html>

可以看到背景出现的位置在浏览器的左上角,这个和默认的设置是一样的。

2、我们需要让出现在上方的正中间,这里我就用代码来说明问题,具体详细代码如下:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:top center;

}

</style>

</head>

<body>

</body>

</html>

从下图的执行结果可以看到,我们的背景出现在了上方的正中间这个位置上了。

3、在上方的中间和左边都出现了,接下来设置出现在上方的右边,具体代码如下所示:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:top right;

}

</style>

</head>

<body>

</body>

</html>

可以看到如下图所示的执行效果图,出现的位置在上方的右边了。

4、如果需要出现的位置在正中间,我们知道设计网页的时候背景等等元素一般都是需要放在正中间这个位置上的,这里我就来分析下如何将背景放置在正中间这个位置上,具体代码如下:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:center center;

}

</style>

</head>

<body>

</body>

</html>

可以看到如下的执行结果,背景出现在了下方的正中间这个位置上了。

5、设置出现在背景的下方左边这个位置,下边用到了bottom这个属性值来设置的,具体代码如下:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:bottom left;

}

</style>

</head>

<body>

</body>

</html>

可以看到如下图所示的结果,

6、还可以设置背景出现的位置在最下方,可以看到如下代码:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:bottom;

}

</style>

</head>

<body>

</body>

</html>

通过如下图可以看到具体的执行效果,只用一个bottom就能设置出现在最下方这个位置上了。

7、用background-position设置的位置除了使用相对位置还能使用绝对位置来设置,可以设置像素值来确定背景左上角的坐标点来确定,具体代码如下:

<html>

<head>

<title>位置设置</title>

<style type="text/css">

body{

background-image:url("2jpg");

background-attachment:scorll;

background-repeat:no-repeat;

background-position:150px 150px;

}

</style>

</head>

<body>

</body>

</html>

从下图可以看到我们的执行结果,背景出现的位置是150px,150px这个点作为左上角的起始点。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13344372.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-18
下一篇 2023-07-18

发表评论

登录后才能评论

评论列表(0条)

保存