How to use responsive background image in css3 in bootstrap

后端 未结 7 1446
猫巷女王i
猫巷女王i 2020-12-25 09:47

I dont want to use html tag. This is my css. I am using bootstrap 3.0.

background:url(\'images/ip-box.png\')no-repeat;
background-size:100%;
height: 140px;
         


        
相关标签:
7条回答
  • 2020-12-25 10:27

    For full image background, check this:

    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;
    }
    
    0 讨论(0)
  • 2020-12-25 10:39

    Check this out,

    body {
        background-color: black;
        background: url(img/bg.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    
    0 讨论(0)
  • 2020-12-25 10:44

    I found this:

    Full

    An easy to use, full page image background template for Bootstrap 3 websites

    http://startbootstrap.com/template-overviews/full/

    or

    using in your main div container:

    html

    <div class="container-fluid full">
    
    
    </div>
    

    css:

    .full {
        background: url('http://placehold.it/1920x1080') no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        background-size: cover;
        -o-background-size: cover;
        height:100%;
    }
    
    0 讨论(0)
  • 2020-12-25 10:45

    Set Responsive and User friendly Background

    <style>
    body {
    background: url(image.jpg);
    background-size:100%;
    background-repeat: no-repeat;
    width: 100%;
    }
    </style>
    
    0 讨论(0)
  • 2020-12-25 10:45

    Try this:

    body {
      background-image:url(img/background.jpg);
      background-repeat: no-repeat;
      min-height: 679px;
      background-size: cover;
    }
    
    0 讨论(0)
  • 2020-12-25 10:47

    You need to use background-size: 100% 100%;

    Demo

    Demo 2 (Won't stretch, this is what you are doing)

    Explanation: You need to use 100% 100% as it sets for X AS WELL AS Y, you are setting 100% just for the X parameter, thus the background doesn't stretch vertically.


    Still, the image will stretch out, it won't be responsive, if you want to stretch the background proportionately, you can look for background-size: cover; but IE will create trouble for you here as it's CSS3 property, but yes, you can use CSS3 Pie as a polyfill. Also, using cover will crop your image.

    0 讨论(0)
提交回复
热议问题