<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>高级的背景</title> <style> body { margin-left:200px; background:#5d9ab2 url('https://static.runoob.com/images/mix/img_tree.png') no-repeat top left; } .container { text-align:center; } .center_div { border:1px solid gray; margin-left:auto; margin-right:auto; width:90%; background-color:#d0f0f6; text-align:left; padding:8px; } </style> </head> <body> <div class="container"> <div class="center_div"> <h1>Hello World!</h1> <p>这个实例包含了一些高级的 CSS 方法,后面章节会介绍到。</p> </div> </div> </body> </html>
声明背景属性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>声明背景属性</title> <style> body { background:#ffffff url('https://static.runoob.com/images/mix/img_tree.png') no-repeat right top; margin-right:200px; } </style> </head> <body> <h1>Hello World!</h1> <p>背景图片只显示一次,但它位置离文本比较远。</p> <p>在这个例子中我们添加了一个右边距,所以背景图像不会打扰到文本。</p> </body> </html>
明天深入学习如何css背景属性