问题
I want my background image to cover my whole web page but it keeps on repeating. Is there a way to set it to non-repetition via HTML?
回答1:
You can't.
First of all, background is an obsolete attribute. Browsers still support it.
Second, it is not part of HTML5, as you can see in the list of attributes of the body element (see also global attributes). Which also you are not using HTML5, stop pretending you are.
And finally, there never was an attribute to control how the background repeats. At least not documented.
Why do you want this? Even - not so good - old IE6 supports CSS background-repeat
and background-size
. Well, except it has problems with PNGs. There are hacks. See Background repeat doesn't seem to work in IE6 and IE6 PNG Transparency CSS background-repeat Fix.
I tried to look how people did this past millelium. You know, around Windows 95. Could not find anything. Perhaps somebody older than me knows, I began learning HTML when we had Windows 98 and IE6. However, I bet the answer is you could not do it.
Why don't you use CSS (and HTML5 by the way) for a change?
回答2:
You need to use inline css (style).
<body style="background: url('images/bg.gif');background-repeat: no-repeat;background-size: cover">
回答3:
<body style="background:url(images/bg.gif) center cover / fixed no-repeat">
来源:https://stackoverflow.com/questions/57853093/non-repetition-background-image-using-html5-not-css