简体   繁体   English

如何使用一张 css 表引用多个 html 页面?

[英]How do you reference multiple html pages with one css sheet?

Here's my code.这是我的代码。 In the screenshot provided I included two situations in which me trying to reference the css style sheet does not work.在提供的屏幕截图中,我包含了两种情况,其中我试图引用 css 样式表不起作用。

In the html, I used < body class="1" >.在 html 中,我使用了 <body class="1" >。 And then in the stylesheet I referenced it by saying body.1{}.然后在样式表中我通过说 body.1{} 来引用它。 This does not work.这不起作用。 I tried making the background black and that won't show.我尝试将背景设置为黑色,但不会显示。 Previously, I tried name it "home" instead of "1", that didn't work either.以前,我尝试将其命名为“home”而不是“1”,但这也不起作用。 It also wouldn't let me set a background image in the css file so I had to add an image in the html instead.它也不允许我在 css 文件中设置背景图像,因此我不得不在 html 中添加图像。

The same things go for < body class="2" > and body.2{}. <body class="2" > 和 body.2{} 的 go 相同。

在此处输入图像描述

You can't use numbers as class names.您不能将数字用作 class 名称。

"A valid name should start with an underscore (_), a hyphen (-) or a letter (az) which is followed by any numbers, hyphens, underscores, letters. A name should be at least two characters long. Cannot start with a digit, two hyphens or a hyphen followed by a number." “一个有效的名称应以下划线 (_)、连字符 (-) 或字母 (az) 开头,后跟任何数字、连字符、下划线、字母。名称应至少有两个字符。不能以一个数字、两个连字符或一个连字符后跟一个数字。”

https://pineco.de/css-quick-tip-the-valid-characters-in-a-custom-css-selector/ https://pineco.de/css-quick-tip-the-valid-characters-in-a-custom-css-selector/

Try something like:尝试类似:

a1 

Code pen for demonstration: https://codepen.io/jamiecalder/pen/rNNVgMj演示用代码笔: https://codepen.io/jamiecalder/pen/rNNVgMj

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

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