如何根据内容类型为 css 元素添加样式或添加类。我的例子:当它包含这样的 iframe 时,我希望添加类或样式 ap 元素。
<p><iframe frameborder="0" height="400" marginheight="0" marginwidth="0" scrolling="no" src="https://www.hashdoc.com/documents/185392/embed" style="border:1px solid #EAE9EA; border-width:1px; margin-bottom:5px; max-width: 100%;" title="Les résultats aux examens" width="550"></iframe></p>
所以它可能是这样的:
if p contain iframe add class 'myclass' to p
我可以用 sass 还是我需要 js 来做到这一点?
编辑:我最终的 jquery 代码
$(".page-lycee p:has(iframe)").addClass('external-content');
据我所知,目前无法使用 CSS。不过,您可以使用 jQuery 解决此问题。
示例代码:
$('p:has(iframe)').addClass('myclass');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句