CSS教程(4):通过实例学习CSS背景



本教程介绍:1.如何仅显示一次背景图像,2.如何放置背景图像,3.如何使用%来定位背景图像。 本教程介绍:1.如何仅显示一次背景图像,2.如何放置背景图像,3.如何使用%来定位背景图像。
参考phpStudy关于CSS背景的理论知识:CSS教程(1):学习CSS背景相关知识。 1、如何仅显示一次背景图像
本例演示如何仅显示一次背景图像。
<html>
<head>
<style type="text/css">
body
{
background-image: url('/i/eg_bg_03.gif');
background-repeat: no-repeat
}
</style>
</head>
<body>
</body>
</html> 2、如何放置背景图像
本例演示如何在页面上放置背景图像。看到本信息说明该文是通过网页教学(phpstudy.net)整理发布的,请不要删掉!
<html>
<head>
<style type="text/css">
body
{
background-image:url('/i/eg_bg_03.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
</style>
</head>
<body>
<body>
<p><b>注释:</b>为了在 Mozilla 中实现此效果,background-attachment 属性必须设置为 "fixed"。</p>
</body>
</body>
</html> 3、如何使用%来定位背景图像
本例演示如何使用百分比来在页面上定位背景图像。
<html>
<head>
<style type="text/css">
body
{
background-image: url('/i/eg_bg_03.gif');
background-repeat: no-repeat;
background-attachment:fixed;
background-position: 30% 20%;
}
</style>
</head>
<body>
<p><b>注释:</b>为了在 Mozilla 中实现此效果,background-attachment 属性必须设置为 "fixed"。</p>
</body>
</html>

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3