Html always shows the elements in the center. The background image is full and drag randomly without going out of the border. The background image is full.

Source: Internet
Author: User

Html always shows the elements in the center. The background image is full and drag randomly without going out of the border. The background image is full.

First, write two class attributes.

Body {margin: 0; padding: 0; height: 100%; width: 100%; background-image: url (.. /Content/Images/background.jpg); background-repeat: no-repeat; background-size: cover ;}

. Login {height: 300px; width: 400px; border: 1px solid # f00; position: absolute; left: 50%; top: 50%; margin:-150px 0 0 0-200px ;}

The background image is set in the above body. The percentage of length and width is 100%. The background image is not repeated and the size is to overwrite the entire browser.

The login style is the logon box, and the height and width are fixed. Then, the border is used to locate and display the logs conveniently. You can cancel the login style after positioning the logs.

The position is an absolute attribute, and the width is 50% to the left and 50% to the top.

If the magin attribute is used,-150px is used to move the logon box up to 150px, so the logon box has 150px in the browser center and 150px in the browser center.

The same is true for-200px.

No matter how you narrow down the browser window, there will be no blank area in the background image, and the window is still in the browser center.

Even if the display resolution is changed, the window is still in the center of the browser.

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.