Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将css类应用于没有js的div_Css_Ruby On Rails - Fatal编程技术网

将css类应用于没有js的div

将css类应用于没有js的div,css,ruby-on-rails,Css,Ruby On Rails,我在我的应用程序中递归地显示一些嵌套注释,但在没有嵌套注释时遇到了应用特定类的挑战。仅当嵌套的\u命令大于0时,如何将类sole干净地应用于我的div条目 def horizontal_tree_for(comments) comments.map do |comment, nested_comments| entry(comment) + (nested_comments.size > 0 ?

我在我的应用程序中递归地显示一些嵌套注释,但在没有嵌套注释时遇到了应用特定类的挑战。仅当嵌套的\u命令大于0时,如何将类
sole
干净地应用于我的div
条目

    def horizontal_tree_for(comments)
        comments.map do |comment, nested_comments|
       entry(comment) + 
          (nested_comments.size > 0 ?          
              content_tag(:div, horizontal_tree_for(nested_comments), class: "branch") +
            "</div>"

          : "</div>")
    end.join.html_safe
  end

def entry(comment)
  "<div class='entry'  **conditional sole class**><span class='label'> #{comment.name} </span>"
end
def水平树(注释)
comments.map do | comment,嵌套的| comments|
条目(备注)+
(嵌套的注释大小>0?
内容标签(:div,水平树(嵌套注释),类:“分支”)+
""
: "")
end.join.html_safe
结束
def条目(注释)
“#{comment.name}”
结束

此样式仅适用于具有子元素的元素:

.empty{
背景色:黑色;
高度:100px;
}
div:not(:空){
背景色:红色!重要;
}

此样式仅适用于具有子元素的元素:

.empty{
背景色:黑色;
高度:100px;
}
div:not(:空){
背景色:红色!重要;
}

按照注释中的建议,只需编写类即可

伪代码:

"<div class='entry (nested_comments.size > 0 ? "sole" : "")'>
 <span class='label'> #{comment.name} </span>"
”
#{comment.name}”

按照注释中的建议,只需编写类即可

伪代码:

"<div class='entry (nested_comments.size > 0 ? "sole" : "")'>
 <span class='label'> #{comment.name} </span>"
”
#{comment.name}”

仅仅编写类就足够了吗?Pseudo:
“#{comment.name}”
@rabelloo有效!你可以把它作为一个答案,我会接受的,仅仅写这个类难道还不够吗?Pseudo:
“#{comment.name}”
@rabelloo有效!你可以这样回答,我会接受的