CSS Background Background instances

Source: Internet
Author: User
Tags set background

The CSS background background is used to set the background color of the HTML tag element, and the background image has other background properties. This article introduces the use of CSS background background and basic usage examples to code farmers. Need to the code farmers can refer to.

First, CSS background background syntax

CSS Background Basics

CSS background This refers to setting the background properties of the object through CSS, such as setting the background of various styles through CSS.

Background syntax:

Background:background-color | | Background-image | | Background-repeat | | background-attachment | | Background-position

CSS in the background word:

Background CSS Manual Query-background
Background-color set color As Object background color
Background-image setting a picture as a background image
Background-repeat Setting the background tile repeat direction
Background-attachment Sets or retrieves whether the background image is scrolled or fixed with the content of the object.
Background-position Sets or retrieves the background image position of the object.

The value of the background background style is a combination of composite attribute values, that is, the value of the background word can be linked to multiple attribute values, with a space interval between values and values.
Such as:

Background: #000 URL (picture address) No-repeat left top

Css Background Background effect:

1. Set solid color background. Background background can set the background color of the object's solid color,
2, set the picture as the background. You can set the object background as a picture, if the background is a picture, you can let the picture repeat the tiling, or the picture as the object background fixed to the object anywhere.

Set Page background style

HTML original background and CSS background control
HTML refers to the table background setting of the corresponding effect

HTML background Word:

Bgcolor Setting the background color corresponds to the CSS background color background-color
Background Set the picture as background with CSS background picture corresponding background-image

Second, background color
Background-color: #FFF

Set object background to pure white

If you set the background color for table, you can use the bgcolor= color value to set the object background color.
If it is a CSS background color, you can use Background-color: color value, or background: color value to set the object background color.

Third, CSS picture background

CSS can use background or background-image to directly reference the picture address to set the picture as the object background.

Background:url (http://www.manongjc.com/logo.gif);

Set logo image as background


Background-image:url (http://www.manongjc.com/logo.gif);

Have the same effect. There is a flaw in setting up the picture as the background is that the picture will be repeated up or down.

Background-attachment Use resolution:

background-attachment:fixed; fixed background

background-attachment:scroll; CSS background picture is scrolling with object content

Picture background background syntax:

Background-image:url (URL)

Background-image:url (Http://www.manongjc.com/logo.gif)

Set object background to picture Http://www.manongjc.com/logo.gif

If the picture is asked to repeat the tile as the background, the tiling direction and so on we all need background-position and background-repeat use together

The object div is defined here, the background image is http://www.manongjc.com/logo.gif, and the background image is not duplicated, positioning the Div object on the left distance of 5px, up to the distance of 6px

Four, the background is centered

CSS background is divided into left and right centers and up and down.

The background image is centered, can be used to calculate the upper and lower height and then split the settings, such as the height of the upper and lower distance of 500px, then set the top of the image of how many px can let the picture to the center.

V. Compound background style shorthand

We need to take into account the code of simplicity, where we can optimize the shorthand code

1, if only set background for a single color

Background-color: #FFF

We shorthand for

Background: #FFF

2, the picture is set as the background shorthand

We shorthand for:

Vi. CSS Background (background) summary

Use the picture as a background in a page layout is often encountered, I hope you can master its knowledge in practice. General Set object picture as Background property instance background: #666 URL (picture address) No-repeat Center top; (explanation first set the background color immediately after setting the picture as the background immediately after the picture is repeated and then with the picture in the object position.) The background color of the front can not be set at the same time is not necessary, general use of the picture as the object background if you want to set the picture to repeat the distance location will set the picture position)

1, set the picture as the background if the picture is set to repeat in the x-coordinate direction, if the picture is set to the left or right position of the object, it will not work, and can be set to start at or below the object.

2, set the picture as the background if the picture is set to repeat in the y-coordinate direction, the picture will not work if it is set to the top or bottom position of the object, and the picture can be set to start at the left or right position of the object.

3, if the setting background is completely repeated display, then set the picture in the upper and lower position of the object to display the wireless.

Web page layout When we often set the background color, background settings picture, to achieve the aesthetic effect we need, we practice to write CSS background background as simple as possible, the introduction of the picture when the path is correct, if you want to locate the object background.

Classic Background Composite Property expressions:

Here both sets the background color, the background picture introduction, the background picture localization, the picture as the background whether repeats the style.

Original address: http://www.manongjc.com/article/842.html

Related reading:

    • CSS Tutorials
    • CSS3 Tutorials
    • CSS Reference Manuals
    • CSS background
    • CSS background-attachment
    • CSS Background-clip
    • CSS Background-color
    • CSS Background-image
    • CSS Background-origin
    • CSS background-position
    • CSS Background-repeat
    • CSS background-size

CSS Background Background instances

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.