Home >Web Front-end >CSS Tutorial >What to do if css background exceeds width

What to do if css background exceeds width

藏色散人
藏色散人Original
2021-01-25 09:26:354589browse

The css background exceeds the width because the background image is too large. The solution: first open the corresponding css file; then add the "background-size:100% 100%" or "background-size:contain" style. Just make the width and height of the background image completely fit into the content area.

What to do if css background exceeds width

The operating environment of this tutorial: Windows 7 system, HTML5&&CSS3 version, DELL G3 computer.

Recommended: css video tutorial

The css background image exceeds the width of the set container because the background image is too large.

The background of an element is the total 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.

Solution:

Add background-size: 100% 100%; or background-size:contain; style so that the width and height of the background image fully adapt to the content area.

div{
        background-image: url(images/1.jpg);
       background-size: 100% 100%;
       
}

The above is the detailed content of What to do if css background exceeds width. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn