简体   繁体   English

如何设置Javascript代码段的样式

[英]How to style a Javascript snippet

I want to embed this Javascript snippet (webform from AWeber) into my website: <script type="text/javascript" src="http://forms.aweber.com/form/49/522310949.js"></script> 我想将这个Javascript代码段(来自AWeber的webform)嵌入到我的网站中: <script type="text/javascript" src="http://forms.aweber.com/form/49/522310949.js"></script>

My site uses the style p { line-height: 1.5em; } 我的网站使用的是样式p { line-height: 1.5em; } p { line-height: 1.5em; } . p { line-height: 1.5em; } Unfortunately this is also applied to the Javascript snippet and makes it look stupid. 不幸的是,这也适用于Javascript片段并使其看起来很愚蠢。

How can I tell the Javascript snippet to use a line-height of 1em instead of 1.5em? 如何告诉Javascript代码段使用1em而不是1.5em的行高?

I tried this but it doesn't work: 我试过这个,但它不起作用:

<p style="line-height: 1em;">
<script type="text/javascript" src="http://forms.aweber.com/form/49/522310949.js"   
</script>
</p>

I also considered using Javascript ( document.getElementById('p').style.lineHeight = '1 em'; ) to change the CSS, but as I understand Javascript modifies the whole website and not only one element... 我还考虑过使用Javascript( document.getElementById('p').style.lineHeight = '1 em'; )来改变CSS,但据我所知,Javascript修改了整个网站而不仅仅是一个元素......

Can you please help? 你能帮忙吗? Thanks in advance! 提前致谢!

Putting the form inside a <p> does not make sense, as <p> cannot contain block-level elements. 将表单放在<p>是没有意义的,因为<p>不能包含块级元素。 Use a <div> instead: 改为使用<div>

<div style='line-height: 1em;'>
  <script src = " ... "></script>
</div>

As @Max implicitly noted, it'd be "nicer" to add CSS to style the content. 正如@Max隐含地指出的那样,添加CSS来设置内容样式会更“好”。

You can use Firebug or the Chrome/Safari developer tools to examine the styles of "live" page elements. 您可以使用Firebug或Chrome / Safari开发人员工具来检查“实时”页面元素的样式。 That can help you figure out the reasons that particular elements look a particular way, and it also lets you play around with alterations to the styles. 这可以帮助您找出特定元素看起来特定方式的原因,并且它还可以让您玩弄样式的更改。

edit maybe something like: 编辑可能是这样的:

div.af-form p { line-height: 1em; }
div.af-form {
    line-height: 1em;
}

In case you need more styling, I see that your generated block also uses these styles: af-header , af-body , af-footer , af-element and af-textWrap . 如果您需要更多样式,我会看到您生成的块也使用以下样式: af-headeraf-bodyaf-footeraf-elementaf-textWrap

However, if you need a more universal solution, refer to @Pointy's answer. 但是,如果您需要更通用的解决方案,请参阅@ Pointy的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM