内容样式表?

发布于 2024-09-07 03:09:58 字数 205 浏览 5 评论 0原文

请原谅我的无知,因为这似乎是我现在应该知道的事情。

我知道我可以制作一个样式表,它允许我在使用 CSS 的多个页面中对 CSS 进行更改。我还知道您可以创建一个外部 javascript 文件,其中可能包含您想要重用的函数。但是假设我有纯 HTML 内容(让我们假装一堆按钮或链接),我想将其复制到多个页面上。在这方面有什么类似于样式表的东西吗?这将允许您一次更新所有按钮/链接。

Forgive my ignorance since this seems like its something I should know by now.

I know I could make a stylesheet that will allow me to make changes in my CSS throughout several pages that use the CSS. I also know that you can make an external javascript file that could contain functions you want to reuse. But lets say I had pure HTML content (lets pretend a bunch of buttons or links) that I wanted replicated on several pages. Is there anything similar to a stylesheet in that regard? This would allow you to update the buttons/links all at once.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

风筝有风,海豚有海 2024-09-14 03:09:58

尝试服务器端包含。

SSI 最常见的用途是将一个或多个文件的内容包含到 Web 服务器上的网页中。例如,包含每日报价的网页可以通过将以下代码放入网页的文件中来包含报价:

如果您的主机允许,您也可以使用 PHP。只需将页面名称从 .html 更改为 .php 并引用标头即可:

<?php include "header.php" ?>

这两个操作都要求您更改文件的扩展名,因此您可能还需要 < a href="http://corz.org/serv/tricks/htaccess2.php" rel="nofollow noreferrer">使用 mod_rewrite 让用户仍然通过 .html 访问它姓名。再说一次,如果你的主机支持的话。

Try server-side includes.

The most frequent use of SSI is to include the contents of one or more files into a web page on a web server. For example, a web page containing a daily quote could include the quote by placing the following code into the file of the web page:

You could also use PHP, if your host allows it. Just change the name of the page from .html to .php and reference the header:

<?php include "header.php" ?>

Both of these require you to change the file's extension, so you might also want to use mod_rewrite to let users still access it via the .html name. Again, if your host supports it.

南渊 2024-09-14 03:09:58

这个问题并不是那么愚蠢,因为事实上 HTML 中没有任何原生的东西可以做到这一点。

如果您的服务器支持,服务器端包含是您的最佳选择。如果您有 PHP,您还可以执行

所有其他服务器端语言都有类似的构造。

The question isn't that stupid, as there in fact is nothing native in HTML to do this.

If supported by your server, Server Side Includes are your best option. If you have PHP, you can also do a <?php include "footer.html"; ?>

All other server side languages have a similar construct.

久隐师 2024-09-14 03:09:58

取决于...我知道 Dreamweaver 对模板有一些相当高级的支持。您可以深入研究所见即所得 HTML 编辑器的手册,了解它如何帮助您处理可重复的内容项。否则,正如 Simon 暗示的那样,您应该考虑学习一些服务器端技术(PHP 等脚本语言是一个简单的选择),编写可重复的 HTML,并让脚本随时随地输出您需要的内容。祝你好运!

Depends... I know Dreamweaver has some rather advanced support for templates. You can delve into the manual of your WYSIWYG HTML editor and get acquainted to how it can help you with repeatable content items. Otherwise, as Simon hinted, you should consider learning some server side technology (scripting language such as PHP is an easy choice), write your repeatable HTML and let the scripts output that whenever and wherever you need. Good luck!

屋檐 2024-09-14 03:09:58

看来您没有使用某些服务器端技术,例如 ASP.NET,它具有可以放置这些用户控件的用户控件。

另一种方法是使用服务器端包含

<!--#include virtual="header.html"-->

Grz、Kris。

It seems you're not using some server side technology like ASP.NET which has user controls on which you could place those.

An alternative would be to use Server Side Includes like:

<!--#include virtual="header.html"-->

Grz, Kris.

无所的.畏惧 2024-09-14 03:09:58

您可以尝试使用 CSS content 属性,但内容会插入到目标之后/之前。 http://www.w3schools.com/Css/pr_gen_content.asp

编辑

您还可以尝试将内容存储在 XML 文档中并使用 JavaScript 加载 XML 工作表。每个工作表都可以存储您的按钮内容、输入内容等。您所要做的就是解析 XML 并将内容呈现为 HTML 元素。

You can try using the CSS content property, but the content is inserted after/before the target. http://www.w3schools.com/Css/pr_gen_content.asp

EDIT

You can also try storing your content in XML documents and using JavaScript to load the XML sheets. Each sheet can store your button content, input content, etc. All you have to do is parse the XML and render the content as HTML elements.

dawn曙光 2024-09-14 03:09:58

虽然 SSI 似乎是我认为最好的主意,但如果我没记错的话,如果您使用 IIS,则必须调整服务器上的一些设置才能使 SSI 与 html 文件扩展一起工作。

虽然 SimpleCoder 的想法看起来并不是最好的想法,但它是一个有趣的想法。基于这个想法,也许 json 数据而不是 xml 是最好的。我只是为了好玩而玩这个。

While SSI seems like the best idea I believe, if memory serves me well, that if you're using IIS you're going to have to adjust some settings on the server to work get SSI with the html file extention.

While SimpleCoder's idea doesn't seem like the best idea it is an interesting one. Building on that idea maybe json data instead of xml would be best. I'd play around with this just for the fun of it.

别理我 2024-09-14 03:09:58

如果 SSI 或 PHP 都不可用,您可以仅使用 javascript 来完成:
将页面加载到隐藏的 IFRAME 中,然后抓取它(使用innerHTML)
- 并将其移动到您需要的地方..

If neither SSI or PHP is available, you could do it with javascript only:
Load the page into a hidden IFRAME, then grab it (with innerHTML)
- and move it to where you need it..

阪姬 2024-09-14 03:09:58

除非你不关心 SEO,否则我建议不要使用 javascript 来实现此目的。

这是可能的,但这种技术可能会阻止搜索引擎正确索引您的网站。

Unless you don't care about SEO, I would advise against using javascript for this purpose.

It's possible, but such a technique could prevent search engines from properly indexing your site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文