CSS 背景图像
CSS 背景图像
background-image 属性指定用作元素背景的图像。
默认情况下,图像会重复,以覆盖整个元素。
页面的背景图像可以像这样设置:
<!DOCTYPE html><html><head><style>body {background-image: url("/images/demo.png");}</style></head><body><h1>Hello World!</h1><p>此页面以图像为背景!</p></body></html>
实例
本例展示了文本和背景图像的错误组合。文字难以阅读:
<!DOCTYPE html><html><head><style>body {background-image: url("/images/demo.png");}</style></head><body><h1>Hello World!</h1><p>在此背景图片上阅读这段文本并不容易。</p></body></html>
注意: 使用背景图像时,请使用不会干扰文本的图像。
还可以为特定元素设置背景图像,例如 <p> 元素:
实例
<!DOCTYPE html><html><head><style>p {background-image: url("/images/demo.png");}</style></head><body><h1>Hello World!</h1><p>本段以一幅图像作为背景!</p></body></html>