简体   繁体   English

JavaScript 中段落的 CSS 样式

[英]CSS styling for paragraph in JavaScript

I am trying to set a style for paragraph which is fetched via JS.我正在尝试为通过 JS 获取的段落设置样式。

Here is what I have:这是我所拥有的:

  var info = "<p>" + meeting.summary + "</p>;

I want to apply some styling and I am trying the code below:我想应用一些样式,我正在尝试下面的代码:

var info= "<p style="font-family: Arial, sans-serif; font-size: small;">" + meeting.summary + "</p>;

But that doesn't work and the JS code does not work correctly.但这不起作用,并且 JS 代码无法正常工作。 How I can use CSS for JavaScript variables such as the one I am trying?我如何将 CSS 用于 JavaScript 变量,例如我正在尝试的变量?

To work with what you've got right now use this (notice the use of ' ):要使用您现在拥有的东西,请使用它(注意'的使用):

var info= '<p style="font-family: Arial, sans-serif; font-size: small;">' + meeting.summary + '</p>';

But I would simply suggest to add a class to the p and style that in CSS:但我只是建议在 CSS 中的p和样式中添加一个类:

// JS
var info = '<p class="info">' + meeting.summary + '</p>';

// CSS
.info {font-family: Arial, sans-serif; font-size: small;}

理想情况下,您将从 DOM 中获取段落并使用 Javascript 操作其属性,如下所示

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

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