Tips for setting background colors and images in css

Source: Internet
Author: User
In css, we can use background to set the background image and background color of HTML elements. It is very simple to set the background color, but it requires some skills to set the background image, this article describes how to use background and how to use it. For more information about coders, see. Set the background color:

To set the background color, use "background: color value. For example:

body{background:#000} 

Set the background color of the body to black.

Set the background image:

1. Regular background image.

It is better to set a gradient background image. For this background, you only need to cut out an image with a 1 pixel width and a suitable height as the background.

body{background: url("../images/body_bg.jpg") repeat-x rgb(222, 235, 243);} 

Instance:

   Tips for setting background colors and images in css    

Online operation

2. Irregular Images

We often see some special topics or image webpages. The background is a very large image as the background. In general, both wide screen and narrow screen displays full-screen background images, it is the same as the adaptive width of an image. In fact, this implementation is just as simple. The width of this image is designed to be large enough. For example, the resolution width of the widest display on the market is 2560 pixels, to enable such a wide-screen display to browse this page, you must make the background image of a width greater than or equal to the width of 2560px, in this way, the web page can be filled with full screen with wide screen and narrow screen display. To minimize, maximize, and change the size of the browser window, the background image is centered in full screen and looks like the adaptive size of the background image.

Key: the key to full-screen Adaptive Background images is that the images are sufficiently wide and can be filled with the widest-resolution display. Small resolutions are naturally full. At the same time, you need to set the background image as the body background and then center it.

body{background: url(bg.jpg) no-repeat center 0}

Code Description: set this image as the webpage background, which is usually not tiled (no-repeat). The image is horizontally centered and displayed on the top.

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.