简体   繁体   中英

Background-image width & height 100%

I have a div on my site and in this div i want embedd a background-image. The problem is now, i cant see the picture. How can i see the picture? I cant finde my mistake. If i embedd the picture in the HTML Code it works, but not in the css Code. Because i want to create something like that: Page (The image + scroll)

Here is my Page: Page

*{
    font-family: "Open Sans";
    margin: 0px;
    padding: 0px;
    font-size: 18px;
}

body{
    /*background: url("images/bg.png") repeat-x scroll left top #9EB5D6;
    background: url("images/bg2.png");                        */
}

nav{
   background: url("images/line-header.png") repeat-x scroll center bottom #4A525A;
   padding: 15px;
}

nav > ul{
    margin: 0px;
    padding: 0px;
    text-align: center;
}

nav ul > li{
    margin-left: 25px;
    display: inline-block;
    list-style-type: none;
}

nav ul li > a{
    display: block;
    text-decoration: none;
    color: black;
    color: #697683;
    transition: color 0.5s;
}

nav ul li > a:hover{
    color: #FFF;
}

.pic1 {
    background: url(images/banner.jpg);
    background-size: 100% 100%;
}
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" href="index.css" >
        <!-- Open Sans -->
        <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
    </head>
    <body>

            <nav>
                <ul>
                    <li><a href="#">Link 1</a></li>
                    <li><a href="#">Link 1</a></li>
                    <li><a href="#">Link 1</a></li>
                </ul>
            </nav>

            <div class="pic1">
            </div>

    </body>
</html>

you need to add:

html, body{
  height: 100%
}

then you can add a height to your image container:

.pic1{
  background: url("images/line-header.png") repeat-x scroll center bottom #4A525A;
  background-size: 100% 100%;
  height: 100%;
}

FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM