gpt4 book ai didi

css - 如何在html中有选择地加载css?

转载 作者:太空宇宙 更新时间:2023-11-03 21:41:03 25 4
gpt4 key购买 nike

从同一个 layout.rhtml 生成了多个页面。每个页面除了全局的css文件外,还有自己的css文件,比如page1.css、page2.css对应page1.rhtml、page2.rhtml。有什么方法可以选择性地加载 rhtml 中的 css 文件吗?

提前致谢。

最佳答案

在 Controller 中定义一个实例变量,为其加载 css。假设我们将像这样在 Controller 中使用 stylefile 变量:

@stylefile = "page1.css"

现在在加载 css 文件的地方编写以下代码。

<%= stylesheet_link_tag @stylefile %>

类似地在 Controller 中更改 page2 的文件名。

关于css - 如何在html中有选择地加载css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23604186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com