Centering a background image, using CSS

前端 未结 13 2081
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 03:59

I want to center a background image. There is no div used, this is the CSS style:

body{
    background-position:center;
    background-image:url(../images/im         


        
13条回答
  •  再見小時候
    2020-11-28 04:33

    Had the same problem. Used display and margin properties and it worked.

    .background-image {
      background: url('yourimage.jpg') no-repeat;
      display: block;
      margin-left: auto;
      margin-right: auto;
      height: whateveryouwantpx;
      width: whateveryouwantpx;
    }
    

提交回复
热议问题