我制作此脚本是为了在计算机上保存服务的 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/