search
HomeWeb Front-endCSS TutorialHow to make the background image not repeat in css

How to make the background image not repeat in css

Dec 23, 2020 am 11:28 AM
cssBackground picture

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.

How to make the background image not repeat in css

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(&#39;2019062123225How to make the background image not repeat in css&#39;);
    }
    </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.

How to make the background image not repeat in css

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(&#39;2019062123225How to make the background image not repeat in css&#39;);
    background-repeat:repeat-x;
}

The running result is as shown below, background The images are repeated horizontally

How to make the background image not repeat in css

css background image is repeated vertically

CSS code

body{
    background: url(&#39;2019062123225How to make the background image not repeat in css&#39;);
    background-repeat:repeat-y;
}

Run results As shown below, the background images are repeated vertically

How to make the background image not repeat in css

css background images are not repeated

CSS code

body{
    background: url(&#39;2019062123225How to make the background image not repeat in css&#39;);
    background-repeat:no-repeat;
}

The running result is as shown below. The background image will not be repeated horizontally or vertically. Only one

How to make the background image not repeat in css

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!

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
Preloading Pages Just Before They are NeededPreloading Pages Just Before They are NeededApr 16, 2025 am 09:53 AM

The 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 FlexboxAdaptive Photo Layout with FlexboxApr 16, 2025 am 09:51 AM

Let’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 CSSThe Many Ways to Link Up Shapes and Images with HTML and CSSApr 16, 2025 am 09:45 AM

Different 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 HistoryWeb Developer Search HistoryApr 16, 2025 am 09:41 AM

Sophie 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

A Snippet to See all SVGs in a SpriteA Snippet to See all SVGs in a SpriteApr 16, 2025 am 09:31 AM

I think of an SVG sprite as this:

What happens when you open a new install of browsers for the 1st time?What happens when you open a new install of browsers for the 1st time?Apr 16, 2025 am 09:29 AM

Interesting 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 BadgesWeb Development Merit BadgesApr 16, 2025 am 09:26 AM

A collection of front-end development achievements. How many can you collect?

Clipping, Clipping, and More Clipping!Clipping, Clipping, and More Clipping!Apr 16, 2025 am 09:22 AM

There 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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

DVWA

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

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),