0

当我包含 '.html_safe' 时,我发现样式 (lass = 'lead' style = 'font-size: 14px;') 没有被使用。当我删除 .html_safe 时,我得到了样式,但现在显示了所有 html。

关于如何解决这个问题的任何建议?

    <p class = 'lead' style = 'font-size: 14px;'>
        <div id = 'textcontainer'>
            <%= @chapter.chaptext.html_safe %>
        </div> <!-- end of textcontainer div -->
    </p>    

没有 html 的 @chapter.chaptext 的内容:

<p> Sanjaya said: <a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>Lord Krishna</a></a></a></a></a></a></a></a></a> spoke these wor<a href = '#' class = 'getannotation'>ds to Arjuna</a> whose eyes were
<a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>tearful and downcast</a></a>, and who was ov<a href = '#' class = 'getannotation'>erwh</a>elmed <a href = '#' class = 'getannotation'><a href = '#' class = 'getannotation'>with compassion and despair</a></a>.
(2.01) <p>

<p> The Supreme Lord said: How has the dejection come to you at this
juncture? This is n<a href = '#' class = 'getannotation'>ot fit for an Arya</a>n (or the people of noble mind and
deeds). It is disgraceful, and it does not lead one to heaven, O Arjuna.
(2.02)<br>

<p> Do not become a coward, O Arjuna, because it does not befit you. Shake
off this weakness of your heart and get up (for the battle), O Arjuna.
(2.03) <p>
4

1 回答 1

1

它可以在没有的情况下工作,.html_safe因为@chapter.chaptext它被呈现为内部的字符串textcontainer。我认为问题在于class = 'getannotation'覆盖了您的风格(领导班),或者可能id = 'textcontainer'使用了类似的风格规则#textcontainer p { font-size: 20px;}

使用网络检查器工具来查看应用到chaptext内容的样式以及它的来源(CSS 类)。

于 2013-05-06T21:19:18.340 回答