CSS: background-color/background-image_html/css_WEB-ITnose
Using CSS, you can specify a background image or background color for the html tag, and you can set the position of the image.
Code compiled from w3school: http://www.w3school.com.cn
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="zh-cn" /><!--(1)设置背景颜色:background-color(2)设置背景图像:background-image(3)设置背景图像的重复:background-repeat(4)背景定位:background-position(5)背景关联:background-attachment--><head> <style> h1 {background-color:#afa} h2 {background-color:rgb(255,187,187)} div#bgImage { background-image:url(images/bg_image.jpg); padding:10px; } div#bgImageKeywords { background-color:#ddd; background-image:url(images/d_sikao.png); padding:30px; background-repeat:no-repeat; background-position:left bottom; } div#bgImagePercent { width:400px; background-color:#ddd; background-image:url(images/d_sikao.png); padding:40px; background-repeat:no-repeat; background-position:20% 80%; } div#bgImageOffset { width:400px; background-color:#ddd; background-image:url(images/d_sikao.png); padding:40px; background-repeat:no-repeat; background-position:200px 20px; } div#bgImageAttach { background-image:url(images/bg_image.jpg); padding:10px; background-attachment:fixed; } </style></head><title>CSS 背景</title><body> <h1>这是一个h1级别的标题:淡绿色</h1> <h2>这是一个h2级别的标题:淡红色</h2> <h3>这是一个h3级别的标题(没有设定样式)</h3> <div id="bgImage"> <p>这个段落有背景图像,有内边距,允许重复(默认)<p> </div> <br/> <!--使用 关键字 描述背景图像的位置。位置关键字可以按任何顺序出现,只要保证不超过两个关键字:一个对应水平方向,另一个对应垂直方向。如果只出现一个关键字,则认为另一个关键字是 center。--> <div id="bgImageKeywords"> <p>淡灰色背景色,同时有背景图像,不允许重复,背景图像居 左下方 显示<p> </div> <br/> <!--使用 百分比 描述背景图像的位置。百分比是图像相对于元素的位置(而不是整个浏览器窗口)。 如果只提供一个百分数值,所提供的这个值将用作水平值,垂直值将假设为 50%。这一点与关键字类似。--> <div id="bgImagePercent" > <p>背景图像相对元素居 水平20%,垂直80% 显示<p> </div> <br/> <!--使用 偏移量 描述背景图像的位置。即图像的左上角与 background-position 声明中的指定的点对齐。--> <div id="bgImageOffset"> <p>背景图像相对元素左上角的偏移量为水平200px,垂直20px<p> </div> <br/> <!--背景关联。如果文档比较长,那么当文档向下滚动时,背景图像也会随之滚动。当文档滚动到超过图像的位置时,图像就会消失。--> <div id="bgImageAttach"> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> <p>这个段落的背景图像不会随着文字滚动。<p> </div></body></html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
