


Detailed explanation of the setting of background-image attribute in HTML_HTML/Xhtml_Web page production
For pictures, the first thing we think of is the background picture. Because many of our decorations are implemented using background pictures. In this case, let’s start with controlling the background image with CSS.
Definition and usage
The background-image attribute sets the background image for the element.
Theelement's background takes up the entire size of the element, including padding and borders, but not margins.
By default, the background image is placed in the upper left corner of the element and repeats horizontally and vertically.
1. CSS control background image:
For a web page, when we start designing, we may not think too much about what the background image is, because most of them just design the background color. I think the reason is very simple, because it is related to the foreground. Just like music, it will have a certain impact on the speed of opening a web page. However, for a general personal website or personal blog, it is of course indispensable for showing one's own personality. Of course, nothing is too perfect. There are good and bad. That is, when the image is not available but When CSS is enabled, replacement content will not be displayed, so it is not recommended to use CSS background images for navigation button text or similar situations.
There are many CSS properties for controlling background images. As long as they are related to images, most of them will be used.
(1). Import of background images:
Of course the most familiar ones are background and background-image.
The code for designing background images for web pages is:
body {background:url("d:images
orbody {background-image:url("d:images
(2) How to display the background image:
Of course, you cannot express the effect you want by just using the above code. Because if the picture is small, it will be tiled. If it is large, scroll bars will appear in order to display it, which is not good. Therefore, we have to perform more display control, that is, we need to use background-repeat,
It is the value:
no-repeat: The background image is not tiled
repeat-x: The background image is only tiled horizontallyrepeat-y: The background image is only tiled vertically
As for the code, I think anyone who knows a little CSS will know it, as follows
:
(3), background image size control:
I think many people will naturally use the following code:
Copy code
Haha, the idea is good, but does the browser you are using support it? I think IE or FF will definitely treat it as if they didn’t see it. Maybe you will ask, when I designed the forum style, was it achievable? I think if it is just the above code, it cannot control the picture, because it only controls the size of the BODY. Of course, there is no control here. If it is other ID tags, I think the range size of the tag can be controlled, haha, of course it is not the size of the image.
To be honest, this problem not only bothers you, but also bothers me. Because it is just the value of a property, not a real object. If you think of using CSS control, remember to tell me.
Supplement: W3C published an article called "CSS Backgrounds and Borders Module Level 3" on September 10, which adds several attributes to the CSS background that we have never seen before:
background-clip :
background-origin :
background-size :Background size.
background-break :
Although these attributes are available, there are currently no browsers that support them. It’s so distressing.
(4), background image position control:
My department imported the background image, but its location is really unacceptable. Because it is aligned to the upper left by default. But we don’t want to place it like this, so what should we do? Don't worry, the exciting moment is coming soon. Now, let's get to know background-position, background-position-x and background-position-y.
a. Basic grammar:
background-position : length || length
background-position : position || position
background-position-x : length | left | center | right
background-position-y : length | top | center | bottom
b. Grammar value:
length: Percentage | A length value consisting of a floating point number and a unit identifier.
position : top | center | bottom | left | center | right
c. Example:
body { background-image: url("d:images
I will only write the following three examples for the values of length | top | center | bottom.
Having said so many examples, I think you have a certain understanding of positioning.
(5), Transparency setting of background image:
Sometimes, we always want to set the picture to be transparent.
(6). Setting of multiple background images:
Regarding the setting of multiple background images, I saw it in "Beyond CSS: The Essence of WEB Design Art". However, it makes me very sad because the current browsers that support multiple background images in one label are too small, and the only one I know of is Apple Safari. You may ask, how is this possible. After you read this example, I think you will be surprised, "Oh my god, before CSS3, you could only use one image for each element." If you want to study it, install a Safari browser quickly. To me, I believe this is the trend. In a word, whoever has the stronger ability to interpret CSS will become the trend of development. Whoever has perfect WEB standards will be the browser star of tomorrow.
The code is as follows:
Copy the code

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Native lazy loading is a built-in browser function that enables lazy loading of pictures by adding loading="lazy" attribute to the tag. 1. It does not require JavaScript or third-party libraries, and is used directly in HTML; 2. It is suitable for pictures that are not displayed on the first screen below the page, picture gallery scrolling add-ons and large picture resources; 3. It is not suitable for pictures with first screen or display:none; 4. When using it, a suitable placeholder should be set to avoid layout jitter; 5. It should optimize responsive image loading in combination with srcset and sizes attributes; 6. Compatibility issues need to be considered. Some old browsers do not support it. They can be used through feature detection and combined with JavaScript solutions.

srcset and sizes are key properties for HTML implementation of responsive images. srcset provides multiple image sources and their width or pixel density, such as 400w and 800w, and the browser selects the appropriate image accordingly; sizes defines the display width of the image under different screen widths, such as (max-width: 600px)100vw, 50vw, so that the browser can more accurately match the image size. In actual use, you need to prepare multi-size pictures, clearly named, design layout in accordance with media query, and test the performance of the equipment to avoid ignoring sizes or unit errors, thereby saving bandwidth and improving performance.

Using HTML tags, you can use the href attribute to realize page jump, open new windows, positioning within pages and email and phone link functions. 1. Basic usage: Specify the target address through href, such as accessing a web page; 2. Open a new window: add target="_blank" and rel="noopener" attributes; 3. Jump within the page: combine id and # symbol to achieve anchor point positioning; 4. Email phone link: use mailto: or tel: protocol to trigger system applications.

The main difference is that textarea supports multiple lines of text input, while inputtext is only available in a single line. 1. Use inputtype="text" to be suitable for short and single-line user input, such as username, email address, etc., and can set maxlength to limit the number of characters. The browser provides automatic filling function, making it easier to uniformly style across browsers; 2. Use textarea for scenarios that require multiple lines of input, such as comment boxes, feedback forms, support line breaks and paragraphs, and can control the size through CSS or disable the adjustment function. Both support form features such as placeholders and required fills, but textarea defines the size through rows and cols, and input uses the size attribute.

The key steps to implement the draggable function include: 1. Use the draggable attribute of HTML5 to make the elements draggable; 2. Set drag data through the dragstart event; 3. Listen to the dragover and drop event processing placement logic in the target area; 4. Use the FileList object to implement drag and drop upload. The HTML5 native drag and drop API uses a series of event control processes, such as dragstart, dragover, drop, etc., where draggable custom elements need to be set to set draggable="true" and bind dragstart event, and call setData() to save data. The dr must be blocked when handling drag and drop

Is a placeholder for content distribution in WebComponents, allowing content within custom component tags to be inserted into the specified location of the component template. 1. The default slot receives content from unspecified locations; 2. The named slot distinguishes multiple slot areas through the name attribute; 3. The slot can set back content to display default information when content is not passed in; 4. The slot content scope belongs to the parent component, and attention should be paid to browser compatibility and structural nesting issues. Mastered use can improve component flexibility and reusability, but common mistakes include missing slot attributes or inappropriate access to slot content.

It is a block-level element, used to divide large block content areas; it is an inline element, suitable for wrapping small segments of text or content fragments. The specific differences are as follows: 1. Exclusively occupy a row, width and height, inner and outer margins can be set, which are often used in layout structures such as headers, sidebars, etc.; 2. Do not wrap lines, only occupy the content width, and are used for local style control such as discoloration, bolding, etc.; 3. In terms of usage scenarios, it is suitable for the layout and structure organization of the overall area, and is used for small-scale style adjustments that do not affect the overall layout; 4. When nesting, it can contain any elements, and block-level elements should not be nested inside.

When writing web content, you need to pay attention to the title and paragraph structure to improve the reading experience and SEO effect. 1. The title level should be clear. A page should only use one h1 as the main title, h2 as the title of the big section, and h3 subdivides the subsections to avoid multiple h1, skip grades or keyword piles up; 2. The paragraph should be controlled in three to four lines, and the key points should be directly mentioned at the beginning, and if necessary, use the ul list to enhance readability; 3. Appropriately use the subtitles of h2 and h3 to guide readers' attention, facilitate information search and optimize search engine recognition.
