SASS上的参考图像

时间:2014-01-16 13:01:41

标签: css ruby-on-rails sass

我一直在尝试使用SASS将背景图像设置到我的Rails应用程序但是当我尝试时:

.header {
  display: table;
  height: 100%;
  width: 100%;
  position: relative;
  background-image: image-url("sky.png") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

图像未加载,但是当我尝试时:

background-image: image-url("sky.png");

图像部分加载。任何人都知道为什么会这样吗?我该如何解决这个问题?

修改

CSS文件:

html,
body {
  height: 100%;
  width: 100%;
}

.vert-text {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

.vert-text h1 {
  padding: 0;
  margin: 0;
  font-size: 4.5em;
  font-weight: 700;
}

/* Side Menu */

#sidebar-wrapper {
  margin-right: -250px;
  right: 0;
  width: 250px;
  background: #000;
  position: fixed;
  height: 100%;
  overflow-y: auto;
  z-index: 1000;
  -webkit-transition: all 0.4s ease 0s;
  -moz-transition: all 0.4s ease 0s;
  -ms-transition: all 0.4s ease 0s;
  -o-transition: all 0.4s ease 0s;
  transition: all 0.4s ease 0s;
}

.sidebar-nav {
  position: absolute;
  top: 0;
  width: 250px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav li {
  line-height: 40px;
  text-indent: 20px;
}

.sidebar-nav li a {
  color: #999999;
  display: block;
  text-decoration: none;
}

.sidebar-nav li a:hover {
  color: #fff;
  background: rgba(255,255,255,0.2);
  text-decoration: none;
}

.sidebar-nav li a:active,
.sidebar-nav li a:focus {
  text-decoration: none;
}

.sidebar-nav > .sidebar-brand {
  height: 55px;
  line-height: 55px;
  font-size: 18px;
}

.sidebar-nav > .sidebar-brand a {
  color: #999999;
}

.sidebar-nav > .sidebar-brand a:hover {
  color: #fff;
  background: none;
}

#menu-toggle {
  top: 0;
  right: 0;
  position: fixed;
  z-index: 1;
}

#sidebar-wrapper.active {
  right: 250px;
  width: 250px;
  -webkit-transition: all 0.4s ease 0s;
  -moz-transition: all 0.4s ease 0s;
  -ms-transition: all 0.4s ease 0s;
  -o-transition: all 0.4s ease 0s;
  transition: all 0.4s ease 0s;
}

.toggle {
  margin: 5px 5px 0 0;
}

/* Full Page Image Header Area */

.header {
  display: table;
  height: 100%;
  width: 100%;
  position: relative;
  background: image-url("sky.png") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

/* Intro */

.intro {
  padding: 50px 0;
}

/* Services */

.services {
  background: #7fbbda;
  padding: 50px 0;
  color: #ffffff;
}

.service-item {
  margin-bottom: 15px;
}

i.service-icon {
  border: 3px solid #ffffff;
  border-radius: 50%;
  display: inline-block;
  font-size: 56px;
  width: 140px;
  height: 140px;
  line-height: 136px;
  vertical-align: middle;
  text-align: center;
}

/* Callout */

.callout {
  color: #ffffff;
  display: table;
  height: 400px;
  width: 100%;
  background: image-url("footimage.png") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

/* Portfolio */

.portfolio {
  padding: 50px 0;
}

.portfolio-item {
  margin-bottom: 25px;
}

.img-portfolio {
  margin: 0 auto;
}


/* Call to Action */

.call-to-action {
  color: #ffffff;
  background: #0a5175;
  padding: 50px 0;
}

.call-to-action .btn {
  margin: 10px;
}

/* Map */

.map {
  height: 500px;
}

/* Footer */

footer {
  padding: 100px 0;
}

.top-scroll {
  margin-top: 50px;
}

.top-scroll a {
  text-decoration: none;
  color: inherit;
}

i.scroll {
  color: #333333;
}

i.scroll:hover {
  color: #0a5175;
}
/* Responsive */

@media (max-width: 768px) {

  .header {
        background: image-url("sky.png") no-repeat center center fixed;
  }

  .callout {
        background: image-url("footimage.png") no-repeat center center fixed;
  }

  .map {
        height: 75%;
  }

}

3 个答案:

答案 0 :(得分:1)

所以我发现你和我有同样的问题,经过数小时和数小时的挖掘,我终于找到了解决1/3图像问题的方法。我不是开发人员,这可能是完全错误的但是在时尚组合中包含的css中有一个部分调用.text-vertical-center我在最初的帖子中没有在你的.css中看到它。为了正确显示图像,我发现你需要添加

height: 963px;

这解决了我的问题。我看到你发布这个已经好几个月了,但我真的希望它可以帮助你或其他人。如果没有正确的方式在.css中显示图像,请随时留下评论。

答案 1 :(得分:0)

您可以像这样管理它;

<强> demo

<强> CSS

html {
  height:100%;
  width:100%;
}

.header {
  width: 100%;
  height: 100%;
  background-image:url("https://www.google.co.in/logos/doodles/2014/dian-fosseys-82nd-birthday-5702250374627328-hp.jpg");
  background-repeat:no-repeat;
  background-position:center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  position:fixed;
}

答案 2 :(得分:0)

以下css可以帮助您

html,body{
width:100%;
height:100%;
}


.header {
  width: 100%;
  height:100%;
  position: relative;
  background: url("desert.jpg") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}