新手问题 image_tag 做背景图片

se7enxin · May 11, 2016 · Last by yunshang replied at May 12, 2016 · 1993 hits
我用 image_tag() 加载一张背景图片,出来的效果怎么也和正常 css 的 background-image 不一样,浏览器下方会多一个左右滑动条。用 background-image 没有问题,而 image_tag() 试了不同的参数以及 css 的改动,都会有左右滑动条的问题。

erb

<div class="page-one">
  <div class="page-one-bg"><%= image_tag "bg.jpg", alt: "background" %></div>
</div>

css

.page-one {
    height: 750px;
}

.page-one-bg {
    height: 800px;
    width: 100%;
    position: absolute;
    background-position: center center;
    background-size: cover;
}

image_tag() 编译后生成的是​img 标签,background-image 是 css 样式,两者是不同的。是块状元素,所以造成了两者的显示样式不同。

You need to Sign in before reply, if you don't have an account, please Sign up first.