如何实现背景图像

时间:2014-05-13 09:19:49

标签: html css image background repeat

我需要帮助在重复时使用图像制作背景但不太确定如何在html或css中编写它时如何实现它 如果是这样怎么样?例如,如果它是用css创建的,我会将background-image:放在body {}标签中吗? 这是我想使用的图像http://s889.photobucket.com/user/aussieking/media/background_image.png.html

<!DOCTYPE html>
    <html lang="en">
        <head>
            <title>Clowning Around</title>
            <link rel="stylesheet" href="style.css">
            <meta charset="utf-8">
        </head>
        <header class= 'main-header' >
                   <div class="logo">
                        !# insert logo picture
                   </div>
        <div id="nav">
                   <ul id="nav">
                            <li><a href="/home/">Home</a></li>
                            <li><a href="/about/">About Us</a></li>
                            <li><a href="/news/">News & Events</a></li>
                            <li><a href="/classes/">Classes & Camps</a></li>
                            <li><a href="/gallery/">Gallery</a></li>
                            <li><a href="/contact/">Contact us</a></li>
                            <li><a href="/enrol/">Enrol Now</a></li>
                    </ul>
              </div>
            </header>  
        <!-- <div id = "breadcrumb">
            <div class ="field clearfix" id = "breadcrumb">
                <ul class = "navigation">
                    <li><a href="/home/">Home</a></li>
                    <li><a href="/about/">About Us</a></li>
                    <li><a href="/news/">News & Events</a></li>
                    <li><a href="/classes/">Classes & Camps</a></li>
                    <li><a href="/gallery/">Gallery</a></li>
                    <li><a href="/contact/">Contact us</a></li>
                    <li><a href="/enrol/">Enrol Now</a></li>
                 make other tabs hidden when user is not on the page, fix list </!--> 

     <body class = 'content' >
        <body>

        </head>

我的CSS

html {
border: 4px solid black;
}
#content {
   width: 50em;
   margin: 0 auto;
   padding: 40px 0;
}

ul#nav {
    position: relative;
    list-style: none;
    margin: 0;
    padding: 0;
}

ul#nav li  {
    position: relative;
    float: left;
    display: inline-block;
    padding: 8px 5px 3px 5px;
    background-color: #FFF;
    text-decoration: none; 
    padding: .2em 1em;
}

#breadcrumb {
position: relative;
width: 980px;
margin: 20px auto 0px auto;
padding: 0;

}

h1 {
font-size: 48px;
font-weight: bold;
font-family: 'Open Sans', sans-serif;
text-align:center;
position: fixed;
border: 2px solid black;
border-width: 100%;
background-color: #fffafa;
width: 1000px;
text-align: center;
margin-left: auto;
margin-right: auto ;
position: fixed; top: 255px;
background-position: center;
}

Body{
font-size: 16px;
font-family: 'Open Sans', sans-serif;
}

p {
font-size: 16px;
font-family: 'Open Sans', sans-serif;
text-align: left;
}

br {
height: 300 px;
}


.boxed {
  border: 2px solid black;
  border-width: 100%;
  background-color: #fffafa;
  width: 1000px;
  text-align: center;
  margin-left: 170px;
  margin-right: auto ;
  position: fixed; top: 390px;
}

img.displayed {
    display: block;
    margin-left: 1000px;
    margin-right: 1000px;
    padding: 2px;
    border: 2px solid #fff;
    margin: 50px;
    position: fixed; top: 48px;
    background-position: center top;
}

hr {
border: 0.25px solid;
background-color: #000;
width: 1000px;
height: 3px;
}

.main-header {
overflow: hidden;
left: 0;
height:150px;
width: 100%;
background-color: black;
padding: 0px;
margin-left: 0px;
position: absolute;
top: -50px;

}

3 个答案:

答案 0 :(得分:5)

您的代码缺少body标记。用css,这就是我要做的事情

body {background:url(yourimageurl) center center;background-size:cover}

图片将始终填充页面的背景,并始终居中。

答案 1 :(得分:0)

body
{
    background-image:url('http://i889.photobucket.com/albums/ac93/aussieking/background_image.png');
    background-repeat:/* How you want it to repeat */;
}

然后选择您想要重复的方向

background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;

答案 2 :(得分:0)

我会使用html标签:

html {
    background: url('http://i889.photobucket.com/albums/ac93/aussieking/background_image.png') center center;
    background-size: cover;
}