包括 HTML + CSS 文件无冲突
我有一个带有自己的样式表的 HTML 标头模板。该 HTML 代码很复杂,它包含菜单、不同的块和其他浮动元素。 CSS 文件包含整个网站的样式。总共有 800 个选择器。
当我在现有网站中包含 HTML 和 CSS 时,它就会崩溃。这是因为很多 CSS 规则干扰了网站的规则。例如,标题模板中的 CSS 有一个名为“.nav”的选择器,网站也有这个选择器。由于两者的规则不同,网站就崩溃了。
我的问题是如何在不完全重新编码的情况下将此 HTML 文件“包含”到现有网站中。
我执行以下操作:处理模板中的样式并为每个样式指定一个唯一的名称。因此,每个“#body”都会变成“#body-1”,每个“.nav”都会变成“.nav-1”,等等。手动执行此操作将需要一段时间。
有没有一个工具可以做到这一点?
I have a HTML header template with its own style sheet. This HTML code is complex, it contains menu's, different blocks and other floating elements. The CSS file contains styles from whole website. It total 800 selectors.
When I just include the HTML and the CSS in my existing website, it breaks. This is due the fact that a lot of CSS rules are interfering with the rules of the website. For example CSS from the header template has a selector with name ".nav" and the website has that too. Because both of them have different rules, the website breaks.
My question is how do I 'include' this HTML file in an existing website without complete recoding.
I though the following: process the styles from the template and give each a unique name. So every '#body' becomes "#body-1", every ".nav" bocomes ".nav-1", etc. Doing this by hand will take a while.
Is there a tool which could do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用我所说的“CSS 命名空间”。
更改新页面的 CSS 规则,使它们与 ID 或类相关。
例如,采用这个:
并将其设置为:
并用 id="NewyThingy" 将新包含的页面包围在 div 中。
或者
将新包含页面的正文标记更改为 class="NewyThingy"。
Use what I call "CSS Namespacing".
Change the CSS rules for the new page such that they are contextual to an ID or class.
For example, take this:
and make it this:
And surround the newly included page in div with id="NewyThingy".
Or
and change the body tag of the newly include page to have class="NewyThingy".