HTML background no repeat

后端 未结 2 1050
孤街浪徒
孤街浪徒 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:09

    The best solution for your question is adding background-repeat:no-repeat or background-size: cover to your CSS or your element's style tag.

    For example:

    html { 
       background: url(images/bg.jpg) no-repeat center center fixed; 
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: cover;
    }
    

    If you insist on using HTML only, you would have to resize the element according to your image, or the other way around. Your question refers to a page's background image, so for my openion CSS or style is the only way to achieve this.

提交回复
热议问题