HTML background no repeat

后端 未结 2 1054
孤街浪徒
孤街浪徒 2021-01-28 14:53

How to fit a background image in html without it repeating to cover the whole page? Is there a HTML code for it or do I have to use a CSS code?

2条回答
  •  鱼传尺愫
    2021-01-28 15:06

    There are two CSS properties you can use to control the size and repetition of a background image:

    • background-repeat
    • background-size

    In order to set as a background image that covers the target element, you would use the values no-repeat and cover, like such:

    targetelement {
      background-image:url('example.jpg');
      background-repeat:no-repeat;
      background-size:contain;
    }
    

    If you'd like to learn more about these CSS properties and their possible values, have a look at these two pages:

    • https://www.w3schools.com/cssref/pr_background-repeat.asp
    • https://www.w3schools.com/cssref/css3_pr_background-size.asp

提交回复
热议问题