我是靠谱客的博主 醉熏小蚂蚁,这篇文章主要介绍怎么设置html的背景图片的位置,现在分享给大家,希望可以做个参考。

本文操作环境:windows10系统、html 5、thinkpad t480电脑。

如果我们想要在html代码中移动下背景图片的位置,其实可以借助于background-position属性。可能不少同学还不知道这个属性,下面我们来介绍下这个属性。

background-position属性是用来设置背景图像的起始位置的。

它的常用属性值有以下这些:

  • left top

  • left center

  • left bottom

  • right top

代码示例:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>靠谱客(uoften.com)</title> <style> body { background-image:url('smiley.gif'); background-repeat:no-repeat; background-attachment:fixed; background-position:center; } </style> </head> <body> <p><b>注意:</b>该属性工作在 Firefox 和 Opera, background-attachment 属性会被设置为 "fixed"。</p> </body> </html>
登录后复制

大家可以将上面的代码复制到本地,运行看下效果。

相关视频分享:html视频教程

以上就是怎么设置html的背景图片的位置的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是醉熏小蚂蚁最近收集整理的关于怎么设置html的背景图片的位置的全部内容,更多相关怎么设置html内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部