Write Css Codes Distinct From Different Pages

In rails, there is normally a view corresponding to an action. So if you want to do some special styles based on different pages, you can render controller name and action name in your layout file like this:

<body class="#{controller_name} #{action_name}">
  <!-- Render something -->
</body>

Let’s assumpt that your current page controller is ProductsController, and your action is index, then you can write your style codes like:

.products.index {
  /* some styles */
}
    原文作者:Martin91
    原文地址: https://segmentfault.com/a/1190000000758478
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞