html - 如何将自定义字体添加到 ConvertTo-HTML 的 <head> 部分?

标签 html css powershell fonts

我制作此脚本是为了在计算机上保存服务的 HTML 文件,并添加了内容。

$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "strong{color: green;}"
$a = $a + "</style>"


$b = "<H2>Service Information</H2>"
$b = $b + "<p> This is the list of services that are on this system. It dispays <strong>both</strong> running and stopped services </p>"

Get-Service | Select-Object Status, Name, DisplayName | 
ConvertTo-HTML -head $a -body $b | 
Out-File C:\Scripts\Test.htm
start "C:\Users\neela\Desktop\Services In HTML.ps1"
Invoke-Expression C:\Scripts\Test.htm

不过,我不喜欢这个字体。我想使用 Google 的 Ubuntu 字体。我尝试添加一些代码来完成这项工作:

$a = $a + "@import url('https://fonts.googleapis.com/css?family=Ubuntu');"
$a = $a + "font-family: 'Ubuntu', sans-serif;"

但是,它不起作用。现在我应该如何改变它?

来自 Google 的路线

要将您选择的字体嵌入到网页中,请将此代码复制到您的 HTML 文档中。

<style>
@import url('https://fonts.googleapis.com/css?family=Ubuntu');
</style>

使用以下 CSS 规则指定这些系列:

font-family: 'Ubuntu', sans-serif;

最佳答案

在现有样式之上添加样式导入,然后将 css 规则应用于您想要的任何元素。在这种情况下,我将它应用于 body 。我还建议在此处使用字符串而不是 +=,因为它们更具可读性。

$a = @"
  <style>
    @import url('https://fonts.googleapis.com/css?family=Ubuntu')
  </style>
  <style>
    BODY{background-color:peachpuff; font-family: 'Ubuntu', sans-serif;}
    TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
    TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}
    TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}
    strong{color: green;}
  </style>
"@
$b = @"
  <H2>Service Information</H2>
  <p> This is the list of services that are on this system. It dispays <strong>both</strong> running and stopped services </p>
"@

Get-Service | Select-Object Status, Name, DisplayName |
 ConvertTo-HTML -Head $a -Body $b |
 Out-File C:\Scripts\Test.htm
Invoke-Item C:\Scripts\Test.htm

关于html - 如何将自定义字体添加到 ConvertTo-HTML 的 <head> 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40644871/

相关文章:

python - 从 Python 运行 powershell 脚本而无需在每次运行时重新导入模块

Powershell New-NfsShare 无效的命名空间

html - 我可以使用哪种示例 url 会立即导致请求失败?

javascript - jQuery TreeView 中的展开和折叠图标未显示在树中

javascript - 相对于光标的 CSS 背景位置

html 复选框显示在 h2 标签下方

命令行、引号和新行上的 Powershell 内联命令

html - 拉伸(stretch)图像以适应特定的 div

php - 带有 PHP 确认邮件的预订系统

javascript - 飞出垂直菜单中的重叠菜单项(Z-Index 无济于事!)