In CSS, you can use the background-repeat attribute to prevent the background image from repeating. This attribute can set whether and how the background image is repeated; just set "background-repeat:no-repeat;" to the background image. ” style to prevent the background image from repeating.

The operating environment of this tutorial: Windows 7 system, HTML5&&CSS3 version, Dell G3 computer.
Recommended: css video tutorial
CSS setting background image
In CSS, we You can use the background attribute to set the background image, such as the following code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>演示背景图片</title>
<style>
body{
background: url('2019062123225How to make the background image not repeat in css');
}
</style>
</head>
<!--飞鸟慕鱼博客-->
<body>
</body>
</html>When we run the code, we find that the background image is repeated whether horizontally or vertically until it covers the entire display area.

CSS background-repeat attribute
There is a background-repeat attribute in CSS that can set images Whether and how the background image is repeated. Its default value is to repeat both horizontally and vertically. If the value of this property is not set, then the background image will be repeated horizontally and vertically like the sample code above, and cover the entire object. displayed area.
It has three values that can be set, as follows, among which the repeat value is the default.
repeat: Default. The background image will repeat vertically and horizontally.
repeat-x : The background image will repeat horizontally.
repeat-y : The background image will repeat vertically.
no-repeat : The background image will be displayed only once.
inherit: Specifies that the setting of the background-repeat attribute should be inherited from the parent element.
css background image only repeats horizontally (horizontally)
CSS code:
body{
background: url('2019062123225How to make the background image not repeat in css');
background-repeat:repeat-x;
}The running result is as shown below, background The images are repeated horizontally

css background image is repeated vertically
CSS code
body{
background: url('2019062123225How to make the background image not repeat in css');
background-repeat:repeat-y;
}Run results As shown below, the background images are repeated vertically
css background images are not repeated
CSS code
body{
background: url('2019062123225How to make the background image not repeat in css');
background-repeat:no-repeat;
}The running result is as shown below. The background image will not be repeated horizontally or vertically. Only one
will be displayed. For more programming-related knowledge, please visit: programming teaching! !
The above is the detailed content of How to make the background image not repeat in css. For more information, please follow other related articles on the PHP Chinese website!
Preloading Pages Just Before They are NeededApr 16, 2025 am 09:53 AMThe typical journey for a person browsing a website: view a page, click a link, browser loads new page. That's assuming no funny business like a Single Page
Adaptive Photo Layout with FlexboxApr 16, 2025 am 09:51 AMLet’s take a look at a super lightweight way to create a horizontal masonry effect for a set of arbitrarily-sized photos. Throw any set of photos at it, and
The Many Ways to Link Up Shapes and Images with HTML and CSSApr 16, 2025 am 09:45 AMDifferent website designs often call for a shape other than a square or rectangle to respond to a click event. Perhaps your site has some kind of tilted or
Web Developer Search HistoryApr 16, 2025 am 09:41 AMSophie Koonin blogged "Everything I googled in a week as a professional software engineer," which was a fascinating look into the mind of a web developer and
What happens when you open a new install of browsers for the 1st time?Apr 16, 2025 am 09:29 AMInteresting research from Jonathan Sampson, where he watches the network requests a browser makes the very first time you launch it on a fresh install, and
Web Development Merit BadgesApr 16, 2025 am 09:26 AMA collection of front-end development achievements. How many can you collect?
Clipping, Clipping, and More Clipping!Apr 16, 2025 am 09:22 AMThere are so many things you can do with clipping paths. I've been exploring them for quite some time and have come up with different techniques and use cases


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),







