仅在主页上的 CSS 背景图像,在 Rails 应用程序中 [英] CSS Background image on Home Page only, in a Rails App

查看:45
本文介绍了仅在主页上的 CSS 背景图像,在 Rails 应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个 Rails 应用程序,并且能够获取一个图像作为主页的背景.但是,我将代码放在主页 css 文件中,但它也被应用于应用程序 css 文件.这导致图像成为应用中所有页面的背景.

I am currently working on a Rails App, and am able to get an image as the background of the home page. However, I placed the code in the homepage css file, but it is being applied to the application css file also. This is resulting in the image being the background for all pages in the app.

在 Rails 3.1+ 应用中,如何让背景图片只出现在主页上?

In a Rails 3.1+ app, how do I get the background image to only appear on the homepage?

我尝试将背景图片 css 块移动到不同的 css 文件,但它仍然适用于所有页面.

I have tried to move the background image css block to a different css file, but it still applied across all pages.

推荐答案

为您想要的页面声明内联样式,如果您在 CSS 文件中声明并将这些文件链接到多个文档中,那么显然它将采用背景图像作为各个元素

Declare styles inline for the page you want, if you declare in CSS file and you link those files in several documents than obviously it will take the background image for the respective element

假设它像 index.html

<style>
body {
   background-image: url('#');
}
</style>

或者简单地声明一个类并在该特定页面上应用

Or simply declare a class and apply on that particular page

.unique { /* In Your CSS File */
   background-image: url('#');
}

<body class="unique"></body>

这篇关于仅在主页上的 CSS 背景图像,在 Rails 应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆