图像没有填充背景容器

时间:2015-04-03 17:36:47

标签: html css image background

我试图为应用创建一个开放页面,但我的响应式图像不适合全屏。我已经尝试使用属性值为background-size:但问题仍然存在。使用容器,它削减了图像的宽度,有些丢失了,我不想要那样。非常感谢任何帮助。

以下是使用 - http://www.shbarcelona.cat/blog/cat/wp-content/uploads/2014/05/formula-2.jpg

的图片

谢谢。

 <html>

 <head>

<meta name="viewport" content="width=device-width, initial-scale=1">


<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="http://demos.jquerymobile.com/1.4.5/theme-classic/theme-classic.css"><script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>

   <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


 </head><body>
 <div data-role="page" >
    <div id="background_image">

        <div data-role="header" data-theme="a">
            <h1>Formula 1 Team List</h1>
        </div>


        <div data-role="main" class="ui-content" id="index_button">
            <a href="#" data-role="button" data-ajax="false"> List of Teams </a>
        </div>

        <div data-role="footer" data-theme="a" data-position="fixed">
            <h1> Kevin Murphy - 11139323</h1>
        </div>
    </div>
</div>

#background_image
{
background: transparent url(formula1.jpg);
background-repeat:no-repeat ;
background-position: center;
background-size: contain;
}

1 个答案:

答案 0 :(得分:0)

只需使用background-size: cover制作全角图像。它们的关键是确保将div和body / html的高度和宽度设置为100%。

html, body {
    height: 100%;
}

#something {
    color: white;
    height: 100%;
    width: 100%;

    background: url(https://download.unsplash.com/photo-1426200830301-372615e4ac54) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

https://jsfiddle.net/shaansingh/soxjt0aj/2/

相关问题