Twitter Bootstrap Responsive Background-Image inside Div

后端 未结 9 1256
醉梦人生
醉梦人生 2020-12-13 03:15

How i can modify #bg image so it would be responsive, resizable and proportional in all browser?

HTML:

 
相关标签:
9条回答
  • 2020-12-13 03:57

    I believe this should also do the job too:

    background-size: contain;

    It specifies that the image should be resized to fit within the element without losing it's aspect ratio.

    0 讨论(0)
  • 2020-12-13 03:58

    I had the similar issue and i solved it using:

    background:url(images/banner1.png) no-repeat center top scroll;
    background-size: 100% auto;
    padding-bottom: 50%;
    

    ... here i had to add the padding: 50% because it wasn't working for me otherwise. It allowed me to set the height of container, as per the size ratio of my banner image. and it is also responsive in my case.

    0 讨论(0)
  • 2020-12-13 03:58

    Mby bootstrap img-responsive class is you looking for.

    0 讨论(0)
  • 2020-12-13 03:59

    I found a solution.

    background-size:100% auto;
    
    0 讨论(0)
  • 2020-12-13 04:00

    Don't use fixed:

    .myimage {
       background:url(admin-user-bg.png) no-repeat top center;
       background: transparent url("yourimage.png") no-repeat top center fixed;
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: 100%;
       height: 500px;
    }
    
    0 讨论(0)
  • 2020-12-13 04:12

    Try this (apply to a class you image is in (not img itself), e.g.

    .myimage {
      background: transparent url("yourimage.png") no-repeat top center fixed;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: 100%;
      height: 500px;
    }
    
    0 讨论(0)
提交回复
热议问题