当我包含'.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>
答案 0 :(得分:0)
它没有.html_safe
,因为@chapter.chaptext
在textcontainer
内呈现为字符串。我认为问题在于class = 'getannotation'
会覆盖您的风格(潜在客户类),或者id = 'textcontainer'
可能会使用#textcontainer p { font-size: 20px;}
使用网络检查工具查看正在应用于chaptext
内容的样式及其来源(CSS类)。