将不同的层叠样式表应用于相同的html页面 [英] Applying different Cascade Style Sheets to the same html page

查看:123
本文介绍了将不同的层叠样式表应用于相同的html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了将CSS应用到现有的html页面,我需要添加一个链接到css文件的链接,我被要求在我正在构建的网页中包含一个链接,该链接将链接到相同的html页面,但是与不同的css文件,我想我需要创建一个不同的css文件,然后通过从第一页复制确切的内容并仅更改css文件的链接来创建另一个.html页面,但它看起来效率并不高。我假设应该有一个标准方法来做到这一点。



谢谢

解决方案

如果您可以使用像PHP这样的服务器端语言,我会这样做:

 < ?php 

$ allowed_stylesheets = array(red,white,blue,green,mobile);
$ default_stylesheet =red;

$ stylesheet =
(in_array($ _ GET [stylesheet])?$ _GET [stylesheet]:$ default_stylesheet);

?>

< link rel =stylesheettype =text / csshref =<?php echo $ stylesheet;?>>

然后你可以调用你的页面,并像下面这样切换样式表:

  www.example.com/page.php?stylesheet=mobile 
.html 页面,可能需要某些服务器设置,默认情况下只有


code> .php 页面在PHP中解析。根据你的情况,这可能比它的价值太麻烦。但是,我不知道任何纯HTML样式表可靠切换。



另外,这样,您每次打电话时都必须重复样式表命令这一页。

To apply a CSS to an existing html page I need to add a link that links to the css file, I am asked to include a link in the webpage that I am building that would link to the same html page but with a different css file, I am thinking I need to create a different css file, then create another .html page by copy the exact content from the first page and only change the link of the css file, but it doesn't seem so efficient and I am assuming there should be a standard method to do this.

thanks

解决方案

If you can use a server-side language like PHP, I would do it something like this:

<?php

   $allowed_stylesheets = array("red", "white", "blue", "green", "mobile");
   $default_stylesheet = "red";

   $stylesheet = 
   (in_array($_GET["stylesheet"]) ? $_GET["stylesheet"] : $default_stylesheet);

?>

<link rel="stylesheet" type="text/css" href="<?php echo $stylesheet; ?>">

you would then be able to call your page, and switch the style sheet like so:

www.example.com/page.php?stylesheet=mobile

note that to make a .html page run in PHP, there is probably some server setup necessary, by default only .php pages are parsed in PHP. Depending on your situation, that may be too much hassle than it's worth. However, I don't know any pure HTML way of switching style sheets reliably.

Also, this way, you will have to repeat the style sheet command every time you call the page.

这篇关于将不同的层叠样式表应用于相同的html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆