无法获得留下来的背景

时间:2014-11-05 10:14:48

标签: css background-image background-size

所以我想要的是背景图像保持原样(而不是根据内容量改变大小),左列用于滚动和(如果可能!)右列保持不变。

@import url(http://fonts.googleapis.com/css?family=Special+Elite);

/*font-family: 'Special Elite', cursive;*/

@import url(http://fonts.googleapis.com/css?family=Pacifico);

/*font-family:'Pacifico', cursive;*/

body {
  height: 100%;
}
#background {
  background-image: url('http://hd4desktop.com/images/b/1920x1080_pathway_in_forest-1211697.jpg');
  width: 100%;
  height: 100%;
  background-position: center fixed;
  background-size: cover;
}
.navbar {
  position: fixed;
  width: 100%;
  z-index: 1;
}
ul {
  text-align: center;
  background-color: #7A4909;
  margin-top: 10px;
}
li {
  list-style: none;
  margin-right: 1em;
  font-family: 'Special Elite', cursive;
  font-size: 35px;
  padding: 12px;
  display: inline-block;
}
li a {
  color: #D0903C;
  background-color: #7A4909;
  text-decoration: none;
  display: inline-block;
}
.left a:hover {
  color: #7A4909;
  background-color: #D0903C;
  -webkit-transform: rotate(-10deg) scale(1.2);
  -moz-transform: rotate(-10deg) scale(1.2);
  -o-transform: rotate(-10deg) scale(1.2);
  text-transform: uppercase;
}
.right a:hover {
  color: #7A4909;
  background-color: #D0903C;
  -webkit-transform: rotate(10deg) scale(1.2);
  -moz-transform: rotate(10deg) scale(1.2);
  -o-transform: rotate(10deg) scale(1.2);
  text-transform: uppercase;
}
#wrap {
  width: 900px;
  margin-top: 10px;
  margin-right: auto;
  margin-left: auto;
  overflow-y: auto;
  padding-top: 90px;
}
#content {
  width: 700px;
  background-color: #D09B54;
  float: left;
  opacity: 0.6;
}
#sidebar {
  width: 200px;
  float: left;
  background-color: #D0903C;
}
#sidebar ul li {
  font-size: 20px;
}
h1 {
  text-align: center;
  font-family: 'Pacifico', cursive;
}
p {
  font-family: 'Dawning of a New Day', cursive;
}
<body id="background">
  <ul class="navbar">
    <li class="left"><a href="home.html">Home</a>
    </li>
    <li class="right"><a href="contact.html">Contact Me</a>
    </li>
    <li class="left"><a href="blog.html">Blog</a>
    </li>
    <li class="right"><a href="funny.html">Funny</a>
    </li>
  </ul>
  <div id="wrap">
    <div id="content">
      <h1>Lorem Ipsum!</h1>
      <p>
        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
        sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
        ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
        eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
        euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
        velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
        eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim
        ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.
        At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
        et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
        At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem
        ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
        diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
        ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
      </p>
    </div>
    <!--end content div-->
    <div id="sidebar">
      <ul>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
      </ul>
    </div>
    <!--end sidebar div-->

1 个答案:

答案 0 :(得分:0)

所以我最终想出了自己...... 我删除了背景的高度和宽度,并添加了背景附件:固定。 为了让我的右列保持不变,我使用#sidebar ul {position:fixed;}但它不再是正确的宽度,所以我不得不再次为它分配200px的宽度。

@import url(http://fonts.googleapis.com/css?family=Special+Elite);

/*font-family: 'Special Elite', cursive;*/

@import url(http://fonts.googleapis.com/css?family=Pacifico);

/*font-family:'Pacifico', cursive;*/

body {
  height: 100%;
}
#background {
  background-image: url('http://hd4desktop.com/images/b/1920x1080_pathway_in_forest-1211697.jpg');
  background-position: center fixed;
  background-size: cover;
  **background-attachment:fixed;**
}
.navbar {
  position: fixed;
  width: 100%;
  z-index: 1;
}
ul {
  text-align: center;
  background-color: #7A4909;
  margin-top: 10px;
}
li {
  list-style: none;
  margin-right: 1em;
  font-family: 'Special Elite', cursive;
  font-size: 35px;
  padding: 12px;
  display: inline-block;
}
li a {
  color: #D0903C;
  background-color: #7A4909;
  text-decoration: none;
  display: inline-block;
}
.left a:hover {
  color: #7A4909;
  background-color: #D0903C;
  -webkit-transform: rotate(-10deg) scale(1.2);
  -moz-transform: rotate(-10deg) scale(1.2);
  -o-transform: rotate(-10deg) scale(1.2);
  text-transform: uppercase;
}
.right a:hover {
  color: #7A4909;
  background-color: #D0903C;
  -webkit-transform: rotate(10deg) scale(1.2);
  -moz-transform: rotate(10deg) scale(1.2);
  -o-transform: rotate(10deg) scale(1.2);
  text-transform: uppercase;
}
#wrap {
  width: 900px;
  margin-top: 10px;
  margin-right: auto;
  margin-left: auto;
  overflow-y: auto;
  padding-top: 90px;
}
#content {
  width: 700px;
  background-color: #D09B54;
  float: left;
  opacity: 0.6;
}
#sidebar {
  width: 200px;
  float: left;
  background-color: #D0903C;
}
**#sidebar ul {
  position:fixed;
  width:200px;
}**
#sidebar ul li {
  font-size: 20px;
}
h1 {
  text-align: center;
  font-family: 'Pacifico', cursive;
}
p {
  font-family: 'Dawning of a New Day', cursive;
}
<body id="background">
  <ul class="navbar">
    <li class="left"><a href="home.html">Home</a>
    </li>
    <li class="right"><a href="contact.html">Contact Me</a>
    </li>
    <li class="left"><a href="blog.html">Blog</a>
    </li>
    <li class="right"><a href="funny.html">Funny</a>
    </li>
  </ul>
  <div id="wrap">
    <div id="content">
      <h1>Lorem Ipsum!</h1>
      <p>
        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
        sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
        ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore
        eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
        euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
        velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
        eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim
        ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.
        At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
        et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
        At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem
        ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
        diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
        ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
      </p>
    </div>
    <!--end content div-->
    <div id="sidebar">
      <ul>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
        <li><a href="blog1.html">Blog1</a>
        </li>
      </ul>
    </div>
    <!--end sidebar div-->